Skip to content

Commit 364b2f3

Browse files
ENGCOM-6023: Remove unnecessaries ternary conditions #24885
- Merge Pull Request #24885 from carusogabriel/magento2:refactoring/useless-conditions - Merged commits: 1. 38c9db4 2. 7da6807 3. e903ae7
2 parents db0dce6 + e903ae7 commit 364b2f3

File tree

11 files changed

+53
-38
lines changed

11 files changed

+53
-38
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/MediaGalleryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,6 @@ private function checkImageExists(string $url): bool
198198
curl_exec($connection);
199199
$responseStatus = curl_getinfo($connection, CURLINFO_HTTP_CODE);
200200
// phpcs:enable Magento2.Functions.DiscouragedFunction
201-
return $responseStatus === 200 ? true : false;
201+
return $responseStatus === 200;
202202
}
203203
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductImageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ private function checkImageExists(string $url): bool
144144
curl_exec($connection);
145145
$responseStatus = curl_getinfo($connection, CURLINFO_HTTP_CODE);
146146

147-
return $responseStatus === 200 ? true : false;
147+
return $responseStatus === 200;
148148
}
149149
}

dev/tests/functional/lib/Magento/Mtf/Client/Element/LiselectstoreElement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\Mtf\Client\Locator;
1010

1111
/**
12-
* Class LiselectstoreElement
1312
* Typified element class for lists selectors
1413
*/
1514
class LiselectstoreElement extends SimpleElement
@@ -76,6 +75,7 @@ public function setValue($value)
7675

7776
$option = $this->context->find($optionSelector, Locator::SELECTOR_XPATH);
7877
if (!$option->isVisible()) {
78+
// phpcs:ignore Magento2.Exceptions.DirectThrow
7979
throw new \Exception('[' . implode('/', $value) . '] option is not visible in store switcher.');
8080
}
8181
$option->click();
@@ -133,7 +133,7 @@ public function getValues()
133133
*/
134134
protected function isSubstring($haystack, $pattern)
135135
{
136-
return preg_match("/$pattern/", $haystack) != 0 ? true : false;
136+
return preg_match("/$pattern/", $haystack) != 0;
137137
}
138138

139139
/**
@@ -157,8 +157,8 @@ protected function findNearestElement($criteria, $key, array $elements)
157157
/**
158158
* Get selected store value
159159
*
160-
* @throws \Exception
161160
* @return string
161+
* @throws \Exception
162162
*/
163163
public function getValue()
164164
{

dev/tests/functional/tests/app/Magento/Bundle/Test/Block/Catalog/Product/View/Type/Bundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function fillBundleOptions($bundleOptions)
311311
{
312312
foreach ($bundleOptions as $option) {
313313
$selector = sprintf($this->bundleOptionBlock, $option['title']);
314-
$useDefault = isset($option['use_default']) && strtolower($option['use_default']) == 'true' ? true : false;
314+
$useDefault = isset($option['use_default']) && strtolower($option['use_default']) == 'true';
315315
if (!$useDefault) {
316316
/** @var Option $optionBlock */
317317
$optionBlock = $this->blockFactory->create(

dev/tests/functional/tests/app/Magento/Review/Test/TestCase/MassActionsProductReviewEntityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function test($gridActions, $gridStatus)
102102
$this->reviewIndex->getReviewGrid()->massaction(
103103
[['title' => $this->review->getTitle()]],
104104
[$gridActions => $gridStatus],
105-
($gridActions == 'Delete' ? true : false)
105+
($gridActions == 'Delete')
106106
);
107107
}
108108

lib/internal/Magento/Framework/Acl/AclResource/Config/Converter/Dom.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*/
66
namespace Magento\Framework\Acl\AclResource\Config\Converter;
77

8+
/**
9+
* @inheritDoc
10+
*/
811
class Dom implements \Magento\Framework\Config\ConverterInterface
912
{
1013
/**
11-
* {@inheritdoc}
14+
* @inheritdoc
1215
*
1316
* @param \DOMDocument $source
1417
* @return array
@@ -39,6 +42,7 @@ protected function _convertResourceNode(\DOMNode $resourceNode)
3942
$resourceAttributes = $resourceNode->attributes;
4043
$idNode = $resourceAttributes->getNamedItem('id');
4144
if ($idNode === null) {
45+
// phpcs:ignore Magento2.Exceptions.DirectThrow
4246
throw new \Exception('Attribute "id" is required for ACL resource.');
4347
}
4448
$resourceData['id'] = $idNode->nodeValue;
@@ -53,7 +57,7 @@ protected function _convertResourceNode(\DOMNode $resourceNode)
5357
$sortOrderNode = $resourceAttributes->getNamedItem('sortOrder');
5458
$resourceData['sortOrder'] = $sortOrderNode !== null ? (int)$sortOrderNode->nodeValue : 0;
5559
$disabledNode = $resourceAttributes->getNamedItem('disabled');
56-
$resourceData['disabled'] = $disabledNode !== null && $disabledNode->nodeValue == 'true' ? true : false;
60+
$resourceData['disabled'] = $disabledNode !== null && $disabledNode->nodeValue == 'true';
5761
// convert child resource nodes if needed
5862
$resourceData['children'] = [];
5963
/** @var $childNode \DOMNode */

lib/internal/Magento/Framework/App/MaintenanceMode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function setAddresses($addresses)
110110
throw new \InvalidArgumentException("One or more IP-addresses is expected (comma-separated)\n");
111111
}
112112
$result = $this->flagDir->writeFile(self::IP_FILENAME, $addresses);
113-
return false !== $result ? true : false;
113+
return false !== $result;
114114
}
115115

116116
/**

lib/internal/Magento/Framework/Code/Reader/NamespaceResolver.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function resolveNamespace($type, array $availableNamespaces)
5050
) {
5151
$name = explode(self::NS_SEPARATOR, $type);
5252
$unqualifiedName = $name[0];
53-
$isQualifiedName = count($name) > 1 ? true : false;
53+
$isQualifiedName = count($name) > 1;
5454
if (isset($availableNamespaces[$unqualifiedName])) {
5555
$namespace = $availableNamespaces[$unqualifiedName];
5656
if ($isQualifiedName) {
@@ -101,16 +101,22 @@ public function getImportedNamespaces(array $fileContent)
101101
$imports[$importsCount][] = $item;
102102
}
103103
foreach ($imports as $import) {
104-
$import = array_filter($import, function ($token) {
105-
$whitelist = [T_NS_SEPARATOR, T_STRING, T_AS];
106-
if (isset($token[0]) && in_array($token[0], $whitelist)) {
107-
return true;
104+
$import = array_filter(
105+
$import,
106+
function ($token) {
107+
$whitelist = [T_NS_SEPARATOR, T_STRING, T_AS];
108+
if (isset($token[0]) && in_array($token[0], $whitelist)) {
109+
return true;
110+
}
111+
return false;
108112
}
109-
return false;
110-
});
111-
$import = array_map(function ($element) {
112-
return $element[1];
113-
}, $import);
113+
);
114+
$import = array_map(
115+
function ($element) {
116+
return $element[1];
117+
},
118+
$import
119+
);
114120
$import = array_values($import);
115121
if ($import[0] === self::NS_SEPARATOR) {
116122
array_shift($import);

lib/internal/Magento/Framework/GraphQl/Schema/Type/ScalarTypes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ScalarTypes
2121
public function isScalarType(string $typeName) : bool
2222
{
2323
$standardTypes = \GraphQL\Type\Definition\Type::getStandardTypes();
24-
return isset($standardTypes[$typeName]) ? true : false;
24+
return isset($standardTypes[$typeName]);
2525
}
2626

2727
/**

lib/internal/Magento/Framework/HTTP/PhpEnvironment/Response.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<?php
22
/**
3-
* Base HTTP response object
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
86
namespace Magento\Framework\HTTP\PhpEnvironment;
97

8+
/**
9+
* Base HTTP response object
10+
*/
1011
class Response extends \Zend\Http\PhpEnvironment\Response implements \Magento\Framework\App\Response\HttpInterface
1112
{
1213
/**
1314
* Flag; is this response a redirect?
15+
*
1416
* @var boolean
1517
*/
1618
protected $isRedirect = false;
1719

1820
/**
19-
* {@inheritdoc}
21+
* @inheritdoc
2022
*/
2123
public function getHeader($name)
2224
{
@@ -29,8 +31,7 @@ public function getHeader($name)
2931
}
3032

3133
/**
32-
* Send the response, including all headers, rendering exceptions if so
33-
* requested.
34+
* Send the response, including all headers, rendering exceptions if so requested.
3435
*
3536
* @return void
3637
*/
@@ -40,7 +41,7 @@ public function sendResponse()
4041
}
4142

4243
/**
43-
* {@inheritdoc}
44+
* @inheritdoc
4445
*/
4546
public function appendBody($value)
4647
{
@@ -50,7 +51,7 @@ public function appendBody($value)
5051
}
5152

5253
/**
53-
* {@inheritdoc}
54+
* @inheritdoc
5455
*/
5556
public function setBody($value)
5657
{
@@ -60,6 +61,7 @@ public function setBody($value)
6061

6162
/**
6263
* Clear body
64+
*
6365
* @return $this
6466
*/
6567
public function clearBody()
@@ -69,7 +71,7 @@ public function clearBody()
6971
}
7072

7173
/**
72-
* {@inheritdoc}
74+
* @inheritdoc
7375
*/
7476
public function setHeader($name, $value, $replace = false)
7577
{
@@ -84,7 +86,7 @@ public function setHeader($name, $value, $replace = false)
8486
}
8587

8688
/**
87-
* {@inheritdoc}
89+
* @inheritdoc
8890
*/
8991
public function clearHeader($name)
9092
{
@@ -111,7 +113,7 @@ public function clearHeaders()
111113
}
112114

113115
/**
114-
* {@inheritdoc}
116+
* @inheritdoc
115117
*/
116118
public function setRedirect($url, $code = 302)
117119
{
@@ -122,22 +124,22 @@ public function setRedirect($url, $code = 302)
122124
}
123125

124126
/**
125-
* {@inheritdoc}
127+
* @inheritdoc
126128
*/
127129
public function setHttpResponseCode($code)
128130
{
129131
if (!is_numeric($code) || (100 > $code) || (599 < $code)) {
130132
throw new \InvalidArgumentException('Invalid HTTP response code');
131133
}
132134

133-
$this->isRedirect = (300 <= $code && 307 >= $code) ? true : false;
135+
$this->isRedirect = (300 <= $code && 307 >= $code);
134136

135137
$this->setStatusCode($code);
136138
return $this;
137139
}
138140

139141
/**
140-
* {@inheritdoc}
142+
* @inheritdoc
141143
*/
142144
public function setStatusHeader($httpCode, $version = null, $phrase = null)
143145
{
@@ -152,7 +154,7 @@ public function setStatusHeader($httpCode, $version = null, $phrase = null)
152154
}
153155

154156
/**
155-
* {@inheritdoc}
157+
* @inheritdoc
156158
*/
157159
public function getHttpResponseCode()
158160
{
@@ -170,7 +172,10 @@ public function isRedirect()
170172
}
171173

172174
/**
175+
* @inheritDoc
176+
*
173177
* @return string[]
178+
* @SuppressWarnings(PHPMD.SerializationAware)
174179
*/
175180
public function __sleep()
176181
{

0 commit comments

Comments
 (0)