From f4da06d0a3146c6002e1dc8fe3481e7313c40011 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 22 Nov 2017 15:58:56 +0200 Subject: [PATCH 1/5] MAGETWO-84354: Copy EQP sniffs to Magento 2 Core repo --- .../Sniffs/LanguageConstructs/GotoSniff.php | 45 +++++ .../LanguageConstructsSniff.php | 85 +++++++++ .../Sniffs/Security/ExecutableRegExSniff.php | 85 +++++++++ .../Sniffs/Strings/StringPositionSniff.php | 164 ++++++++++++++++++ .../static/framework/Magento/ruleset.xml | 9 + 5 files changed, 388 insertions(+) create mode 100644 dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php create mode 100644 dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php create mode 100644 dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php create mode 100644 dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php diff --git a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php new file mode 100644 index 0000000000000..85992bbcabbeb --- /dev/null +++ b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php @@ -0,0 +1,45 @@ +addError($this->errorMessage, $stackPtr, $this->errorCode); + } +} diff --git a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php new file mode 100644 index 0000000000000..9e153f4890d87 --- /dev/null +++ b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php @@ -0,0 +1,85 @@ +getTokens(); + if ($tokens[$stackPtr]['code'] === T_BACKTICK) { + if ($phpcsFile->findNext(T_BACKTICK, $stackPtr + 1)) { + return; + } + $phpcsFile->addError($this->errorMessageBacktick, $stackPtr, $this->backtickCode); + return; + } + if ($tokens[$stackPtr]['code'] === T_EXIT) { + $code = $this->exitUsage; + } else { + $code = $this->directOutput; + } + $phpcsFile->addError($this->errorMessage, $stackPtr, $code, [$tokens[$stackPtr]['content']]); + } +} diff --git a/dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php b/dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php new file mode 100644 index 0000000000000..569fd080aa51e --- /dev/null +++ b/dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php @@ -0,0 +1,85 @@ +getTokens(); + if ($tokens[$stackPtr]['content'] !== $this->function) { + return; + } + $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); + if (in_array($tokens[$prevToken]['code'], $this->ignoreTokens)) { + return; + } + $nextToken = $phpcsFile->findNext([T_WHITESPACE, T_OPEN_PARENTHESIS], $stackPtr + 1, null, true); + if (in_array($tokens[$nextToken]['code'], Tokens::$stringTokens) + && preg_match('/[#\/|~\}\)][imsxADSUXJu]*e[imsxADSUXJu]*.$/', $tokens[$nextToken]['content']) + ) { + $phpcsFile->addError( + $this->errorMessage, + $stackPtr, + $this->errorCode, + [$tokens[$stackPtr]['content']] + ); + } + } +} diff --git a/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php b/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php new file mode 100644 index 0000000000000..716599602f906 --- /dev/null +++ b/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php @@ -0,0 +1,164 @@ +tokens = $phpcsFile->getTokens(); + $this->file = $phpcsFile; + $this->leftLimit = $open = $this->tokens[$stackPtr]['parenthesis_opener']; + $this->rightLimit = $close = $this->tokens[$stackPtr]['parenthesis_closer']; + for ($i = ($open + 1); $i < $close; $i++) { + if (($this->tokens[$i]['code'] === T_STRING && in_array($this->tokens[$i]['content'], $this->functions)) + && (!$this->findIdentical($i - 1, $this->findFunctionParenthesisCloser($i) + 1)) + ) { + $foundFunctionName = $this->tokens[$i]['content']; + $phpcsFile->addError($this->errorMessage, $i, $this->errorCode, [$foundFunctionName]); + } + } + } + + /** + * Recursively finds identical operators in current scope. + * + * @param int $leftCurrentPosition + * @param int $rightCurrentPosition + * @return bool + */ + protected function findIdentical($leftCurrentPosition, $rightCurrentPosition) + { + $leftBound = $this->file->findPrevious($this->leftRangeTokens, $leftCurrentPosition, $this->leftLimit - 1); + $rightBound = $this->file->findNext($this->rightRangeTokens, $rightCurrentPosition, $this->rightLimit + 1); + $leftToken = $this->tokens[$leftBound]; + $rightToken = $this->tokens[$rightBound]; + if ($leftToken['code'] === T_OPEN_PARENTHESIS && $rightToken['code'] === T_CLOSE_PARENTHESIS) { + return $this->findIdentical($leftBound - 1, $rightBound + 1); + } else { + return ( + in_array($leftToken['code'], $this->identical) || in_array($rightToken['code'], $this->identical) + ) ?: false; + } + } + + /** + * Finds the position of close parenthesis of detected function. + * + * @param int $currentPosition + * @return mixed + */ + protected function findFunctionParenthesisCloser($currentPosition) + { + $nextOpenParenthesis = $this->file->findNext(T_OPEN_PARENTHESIS, $currentPosition, $this->rightLimit); + return $nextOpenParenthesis ? $this->tokens[$nextOpenParenthesis]['parenthesis_closer'] : false; + } +} diff --git a/dev/tests/static/framework/Magento/ruleset.xml b/dev/tests/static/framework/Magento/ruleset.xml index 56a5a9e55c30e..ff0b9e9d50dd5 100644 --- a/dev/tests/static/framework/Magento/ruleset.xml +++ b/dev/tests/static/framework/Magento/ruleset.xml @@ -16,14 +16,23 @@ + + */Framework/* + *.phtml + + + */Framework/* + */_files/* + + From ddd5c0340669bbe99bf366c9cf4db9eefe917358 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Thu, 23 Nov 2017 13:57:42 +0200 Subject: [PATCH 2/5] MAGETWO-84354: Copy EQP sniffs to Magento 2 Core repo --- .../Magento/Sniffs/LanguageConstructs/GotoSniff.php | 5 +++++ .../Sniffs/LanguageConstructs/LanguageConstructsSniff.php | 8 +++++++- .../Magento/Sniffs/Security/ExecutableRegExSniff.php | 2 ++ .../Magento/Sniffs/Strings/StringPositionSniff.php | 4 ++++ dev/tests/static/framework/Magento/ruleset.xml | 8 ++------ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php index 85992bbcabbeb..8ff5571abb494 100644 --- a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php +++ b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php @@ -10,6 +10,11 @@ /** * Detects GOTO usage. + * + * Example: + * goto end; + * end: + * 'The End'; */ class GotoSniff implements Sniff { diff --git a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php index 9e153f4890d87..9873c9be916ab 100644 --- a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php +++ b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php @@ -9,7 +9,13 @@ use PHP_CodeSniffer\Files\File; /** - * Detects possible usage of discouraged language constructs. + * Detects possible usage of discouraged language constructs. Is not applicable to *.phtml files. + * + * Examples: + * echo 'echo text'; + * print('print text'); + * $ = `back quotes`; + * exit(1); */ class LanguageConstructsSniff implements Sniff { diff --git a/dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php b/dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php index 569fd080aa51e..0482f574f28ce 100644 --- a/dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php +++ b/dev/tests/static/framework/Magento/Sniffs/Security/ExecutableRegExSniff.php @@ -11,6 +11,8 @@ /** * Detects executable regular expressions. + * + * Example: echo preg_replace('|^(.*)$|ei', '"\1"', 'get_input'); */ class ExecutableRegExSniff implements Sniff { diff --git a/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php b/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php index 716599602f906..bc3b790537e75 100644 --- a/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php +++ b/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php @@ -10,6 +10,10 @@ /** * Detects misusing of IS_IDENTICAL operators. + * + * Examples: + * if (!strpos($haystack, $needle)) {} + * if (strpos($haystack, $needle) == false) {} */ class StringPositionSniff implements Sniff { diff --git a/dev/tests/static/framework/Magento/ruleset.xml b/dev/tests/static/framework/Magento/ruleset.xml index ff0b9e9d50dd5..c886c87be10a4 100644 --- a/dev/tests/static/framework/Magento/ruleset.xml +++ b/dev/tests/static/framework/Magento/ruleset.xml @@ -16,12 +16,8 @@ - - */Framework/* - *.phtml - - - */Framework/* + + */app/code/*\.(?!phtml) */_files/* From 50c83feac4fcfba0ede5cc552618dc5852a7c5fb Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Thu, 30 Nov 2017 17:12:31 +0200 Subject: [PATCH 3/5] MAGETWO-84354: Copy EQP sniffs to Magento 2 Core repo --- .../Magento/Backend/Block/Widget/Tabs.php | 2 +- .../Model/Import/Product/Type/Bundle.php | 3 +- .../Model/Customer/Attribute/Source/Store.php | 2 +- app/code/Magento/Deploy/Service/Bundle.php | 4 +- .../Import/Product/Type/Downloadable.php | 6 ++- .../Model/Entity/Attribute/Source/Table.php | 2 +- .../Magento/Email/Model/AbstractTemplate.php | 2 +- app/code/Magento/Fedex/Setup/InstallData.php | 8 +-- .../Carrier/AbstractCarrierOnlineTest.php | 1 + app/code/Magento/Usps/Setup/UpgradeData.php | 6 ++- .../Webapi/Model/Rest/Swagger/Generator.php | 2 +- .../CurlTransport/BackendDecorator.php | 2 +- .../CurlTransport/FrontendDecorator.php | 2 +- ...AssertBundleProductOnConfigureCartPage.php | 2 +- .../Product/Edit/Section/Options.php | 3 +- .../Handler/CatalogProductAttribute/Curl.php | 2 +- .../Handler/CatalogProductSimple/Curl.php | 2 +- .../Catalog/Test/Handler/Category/Curl.php | 2 +- .../Test/Handler/CatalogRule/Curl.php | 2 +- .../Test/Handler/CheckoutAgreement/Curl.php | 2 +- .../Block/Adminhtml/Page/Edit/PageForm.php | 2 +- .../Cms/Test/Handler/CmsBlock/Curl.php | 2 +- .../Magento/Cms/Test/Handler/CmsPage/Curl.php | 2 +- .../Customer/Test/Handler/Customer/Curl.php | 4 +- .../Test/Handler/CustomerGroup/Curl.php | 2 +- .../Test/Handler/CurrencyRate/Curl.php | 2 +- .../Test/Handler/DownloadableProduct/Curl.php | 2 +- .../Test/Handler/Integration/Curl.php | 2 +- .../Newsletter/Test/Handler/Template/Curl.php | 2 +- .../Review/Test/Handler/Rating/Curl.php | 2 +- .../Review/Test/Handler/Review/Curl.php | 2 +- .../Test/Handler/OrderInjectable/Curl.php | 2 +- .../Sales/Test/Handler/OrderStatus/Curl.php | 4 +- .../SalesRule/Test/Handler/SalesRule/Curl.php | 2 +- .../Search/Test/Handler/SynonymGroup/Curl.php | 2 +- .../Sitemap/Test/Handler/Sitemap/Curl.php | 2 +- .../Magento/Store/Test/Handler/Store/Curl.php | 2 +- .../Store/Test/Handler/StoreGroup/Curl.php | 2 +- .../Store/Test/Handler/Website/Curl.php | 2 +- .../Magento/Tax/Test/Handler/TaxRule/Curl.php | 2 +- .../Test/Handler/UrlRewrite/Curl.php | 2 +- .../Magento/User/Test/Handler/Role/Curl.php | 2 +- .../Magento/User/Test/Handler/User/Curl.php | 2 +- .../Test/Handler/SystemVariable/Curl.php | 2 +- .../Widget/Test/Handler/Widget/Curl.php | 2 +- .../testsuite/Magento/Deploy/DeployTest.php | 2 +- .../Modular/BlockInstantiationTest.php | 4 +- .../Integrity/Modular/TemplateFilesTest.php | 4 +- .../Sniffs/LanguageConstructs/GotoSniff.php | 50 ------------------- .../LanguageConstructsSniff.php | 18 +------ .../Magento/Sniffs/Less/ClassNamingSniff.php | 4 +- .../static/framework/Magento/ruleset.xml | 1 - .../Magento/Test/Integrity/DependencyTest.php | 2 +- .../Framework/Code/Reader/ArgumentsReader.php | 2 +- lib/internal/Magento/Framework/DataObject.php | 2 +- .../Magento/Framework/DataObject/Cache.php | 2 +- .../Framework/EntityManager/TypeResolver.php | 2 +- lib/internal/Magento/Framework/Parse/Zip.php | 2 +- .../Framework/Session/SessionManager.php | 2 +- .../Framework/View/Asset/Bundle/Manager.php | 2 +- .../src/Magento/Setup/Model/PackagesData.php | 2 +- .../Code/Reader/Decorator/Interceptions.php | 2 +- 62 files changed, 78 insertions(+), 136 deletions(-) delete mode 100644 dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php diff --git a/app/code/Magento/Backend/Block/Widget/Tabs.php b/app/code/Magento/Backend/Block/Widget/Tabs.php index ec3628d2fcb43..7f146e19e8c6e 100644 --- a/app/code/Magento/Backend/Block/Widget/Tabs.php +++ b/app/code/Magento/Backend/Block/Widget/Tabs.php @@ -164,7 +164,7 @@ public function addTab($tabId, $tab) */ protected function _addTabByName($tab, $tabId) { - if (strpos($tab, '\Block\\')) { + if (strpos($tab, '\Block\\') !== false) { $this->_tabs[$tabId] = $this->getLayout()->createBlock($tab, $this->getNameInLayout() . '_tab_' . $tabId); } elseif ($this->getChildBlock($tab)) { $this->_tabs[$tabId] = $this->getChildBlock($tab); diff --git a/app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php b/app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php index b4435acca8d0d..f273ee0b1c0ef 100644 --- a/app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php +++ b/app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php @@ -217,7 +217,8 @@ protected function parseOption($values) $option = []; foreach ($values as $keyValue) { $keyValue = trim($keyValue); - if ($pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR)) { + $pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR); + if ($pos !== false) { $key = substr($keyValue, 0, $pos); $value = substr($keyValue, $pos + 1); if ($key == 'type') { diff --git a/app/code/Magento/Customer/Model/Customer/Attribute/Source/Store.php b/app/code/Magento/Customer/Model/Customer/Attribute/Source/Store.php index 1845ba36d46c1..f70d0a91f35fb 100644 --- a/app/code/Magento/Customer/Model/Customer/Attribute/Source/Store.php +++ b/app/code/Magento/Customer/Model/Customer/Attribute/Source/Store.php @@ -67,7 +67,7 @@ public function getOptionText($value) $value = '0'; } $isMultiple = false; - if (strpos($value, ',')) { + if (strpos($value, ',') !== false) { $isMultiple = true; $value = explode(',', $value); } diff --git a/app/code/Magento/Deploy/Service/Bundle.php b/app/code/Magento/Deploy/Service/Bundle.php index cf0d7a551f4c3..fe6b36619126b 100644 --- a/app/code/Magento/Deploy/Service/Bundle.php +++ b/app/code/Magento/Deploy/Service/Bundle.php @@ -167,7 +167,7 @@ private function hasMinVersion($filePath) } $info = pathinfo($filePath); - if (strpos($filePath, '.min.') === true) { + if (strpos($filePath, '.min.') !== false) { $this->excludedCache[] = str_replace(".min.{$info['extension']}", ".{$info['extension']}", $filePath); } else { $pathToMinVersion = $info['dirname'] . '/' . $info['filename'] . '.min.' . $info['extension']; @@ -216,7 +216,7 @@ private function isExcluded($filePath, $area, $theme) */ private function prepareExcludePath($path) { - if (strpos($path, Repository::FILE_ID_SEPARATOR) > 0) { + if (strpos($path, Repository::FILE_ID_SEPARATOR) !== false) { list($excludedModule, $excludedPath) = explode(Repository::FILE_ID_SEPARATOR, $path); if ($excludedModule == 'Lib') { return $excludedPath; diff --git a/app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php b/app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php index 06df8b12351be..b6ae91e79e0b1 100644 --- a/app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php +++ b/app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php @@ -777,7 +777,8 @@ protected function parseLinkOption(array $values) $option = []; foreach ($values as $keyValue) { $keyValue = trim($keyValue); - if ($pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR)) { + $pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR); + if ($pos !== false) { $key = substr($keyValue, 0, $pos); $value = substr($keyValue, $pos + 1); if ($key == 'sample') { @@ -810,7 +811,8 @@ protected function parseSampleOption($values) $option = []; foreach ($values as $keyValue) { $keyValue = trim($keyValue); - if ($pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR)) { + $pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR); + if ($pos !== false) { $key = substr($keyValue, 0, $pos); $value = substr($keyValue, $pos + 1); if ($key == self::URL_OPTION_VALUE || $key == self::FILE_OPTION_VALUE) { diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php index 03d64ff27e962..8f8c39bf26040 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php @@ -145,7 +145,7 @@ private function addEmptyOption(array $options) public function getOptionText($value) { $isMultiple = false; - if (strpos($value, ',')) { + if (strpos($value, ',') !== false) { $isMultiple = true; $value = explode(',', $value); } diff --git a/app/code/Magento/Email/Model/AbstractTemplate.php b/app/code/Magento/Email/Model/AbstractTemplate.php index fa9d28074bf85..e6a2f74a0d1a8 100644 --- a/app/code/Magento/Email/Model/AbstractTemplate.php +++ b/app/code/Magento/Email/Model/AbstractTemplate.php @@ -289,7 +289,7 @@ public function loadDefault($templateId) /** * trim copyright message */ - if (preg_match('/^/m', $templateText, $matches) && strpos($matches[0], 'Copyright') > 0) { + if (preg_match('/^/m', $templateText, $matches) && strpos($matches[0], 'Copyright') !== false) { $templateText = str_replace($matches[0], '', $templateText); } diff --git a/app/code/Magento/Fedex/Setup/InstallData.php b/app/code/Magento/Fedex/Setup/InstallData.php index 823cd2794290f..1591aaa3abf70 100644 --- a/app/code/Magento/Fedex/Setup/InstallData.php +++ b/app/code/Magento/Fedex/Setup/InstallData.php @@ -82,13 +82,13 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $mapsOld = $conn->fetchAll($select); foreach ($mapsOld as $mapOld) { $mapNew = ''; - if (stripos($mapOld['path'], 'packaging') && isset($codes['packaging'][$mapOld['value']])) { + if (stripos($mapOld['path'], 'packaging') !== false && isset($codes['packaging'][$mapOld['value']])) { $mapNew = $codes['packaging'][$mapOld['value']]; - } elseif (stripos($mapOld['path'], 'dropoff') && isset($codes['dropoff'][$mapOld['value']])) { + } elseif (stripos($mapOld['path'], 'dropoff') !== false && isset($codes['dropoff'][$mapOld['value']])) { $mapNew = $codes['dropoff'][$mapOld['value']]; - } elseif (stripos($mapOld['path'], 'free_method') && isset($codes['method'][$mapOld['value']])) { + } elseif (stripos($mapOld['path'], 'free_method') !== false && isset($codes['method'][$mapOld['value']])) { $mapNew = $codes['method'][$mapOld['value']]; - } elseif (stripos($mapOld['path'], 'allowed_methods')) { + } elseif (stripos($mapOld['path'], 'allowed_methods') !== false) { foreach (explode(',', $mapOld['value']) as $shippingMethod) { if (isset($codes['method'][$shippingMethod])) { $mapNew[] = $codes['method'][$shippingMethod]; diff --git a/app/code/Magento/Shipping/Test/Unit/Model/Carrier/AbstractCarrierOnlineTest.php b/app/code/Magento/Shipping/Test/Unit/Model/Carrier/AbstractCarrierOnlineTest.php index 37439082b9111..499f71a271981 100644 --- a/app/code/Magento/Shipping/Test/Unit/Model/Carrier/AbstractCarrierOnlineTest.php +++ b/app/code/Magento/Shipping/Test/Unit/Model/Carrier/AbstractCarrierOnlineTest.php @@ -128,6 +128,7 @@ public function testParseXmlXXEXml() $xmlElement = $this->carrier->parseXml($xmlString); + // @codingStandardsIgnoreLine echo $xmlElement->asXML(); } diff --git a/app/code/Magento/Usps/Setup/UpgradeData.php b/app/code/Magento/Usps/Setup/UpgradeData.php index f8a15d170b3f5..bc29d46836640 100644 --- a/app/code/Magento/Usps/Setup/UpgradeData.php +++ b/app/code/Magento/Usps/Setup/UpgradeData.php @@ -88,9 +88,11 @@ private function updateAllowedMethods(ModuleDataSetupInterface $setup) $oldConfigValues = $connection->fetchAll($select); foreach ($oldConfigValues as $oldValue) { - if (stripos($oldValue['path'], 'free_method') && isset($oldToNewMethodCodesMap[$oldValue['value']])) { + if (stripos($oldValue['path'], 'free_method') !== false + && isset($oldToNewMethodCodesMap[$oldValue['value']]) + ) { $newValue = $oldToNewMethodCodesMap[$oldValue['value']]; - } elseif (stripos($oldValue['path'], 'allowed_methods')) { + } elseif (stripos($oldValue['path'], 'allowed_methods') !== false) { $newValuesList = []; foreach (explode(',', $oldValue['value']) as $shippingMethod) { if (isset($oldToNewMethodCodesMap[$shippingMethod])) { diff --git a/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php b/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php index 3df6966fb01b3..d864f5d7a195c 100644 --- a/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php +++ b/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php @@ -407,7 +407,7 @@ protected function getObjectSchema($typeName, $description = '') if ($simpleType = $this->getSimpleType($trimedTypeName)) { $result['items'] = ['type' => $simpleType]; } else { - if (strpos($typeName, '[]')) { + if (strpos($typeName, '[]') !== false) { $result['items'] = ['$ref' => $this->getDefinitionReference($trimedTypeName)]; } else { $result = ['$ref' => $this->getDefinitionReference($trimedTypeName)]; diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/BackendDecorator.php b/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/BackendDecorator.php index ab333dc7c005a..bb82715e4b402 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/BackendDecorator.php +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/BackendDecorator.php @@ -76,7 +76,7 @@ protected function authorize() ]; $this->transport->write($url, $data, CurlInterface::POST); $response = $this->read(); - if (strpos($response, 'login-form')) { + if (strpos($response, 'login-form') !== false) { throw new \Exception( 'Admin user cannot be logged in by curl handler!' ); diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/FrontendDecorator.php b/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/FrontendDecorator.php index 2c78e1913605a..83f86b264737c 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/FrontendDecorator.php +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Protocol/CurlTransport/FrontendDecorator.php @@ -74,7 +74,7 @@ protected function authorize(Customer $customer) ]; $this->transport->write($url, $data, CurlInterface::POST, ['Set-Cookie:' . $this->cookies]); $response = $this->read(); - if (strpos($response, 'customer/account/login')) { + if (strpos($response, 'customer/account/login') !== false) { throw new \Exception($customer->getFirstname() . ', cannot be logged in by curl handler!'); } } diff --git a/dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleProductOnConfigureCartPage.php b/dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleProductOnConfigureCartPage.php index 8828f31f9965a..e6a7ec013470c 100644 --- a/dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleProductOnConfigureCartPage.php +++ b/dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleProductOnConfigureCartPage.php @@ -100,7 +100,7 @@ private function prepareBundleOptions(BundleProduct $product, array $cartItemOpt 'price' => number_format($price, 2), ]; foreach ($cartItemOptions as $option) { - if (strpos($option['value'], $title)) { + if (strpos($option['value'], $title) !== false) { $optionData['options'][$productKey]['selected'] = true; } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/Options.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/Options.php index bb12146360c04..ce27efe8d508a 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/Options.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/Options.php @@ -340,7 +340,8 @@ protected function optionNameConvert($inputType) { $option = substr($inputType, strpos($inputType, "/") + 1); $option = str_replace([' ', '&'], "", $option); - if ($end = strpos($option, '-')) { + $end = strpos($option, '-'); + if ($end !== false) { $option = substr($option, 0, $end) . ucfirst(substr($option, ($end + 1))); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php index f1086f4871f3b..d78095f05fe45 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php @@ -109,7 +109,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { $this->_eventManager->dispatchEvent(['curl_failed'], [$response]); throw new \Exception($this->responseExceptionMessage); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php index 16931f3662c75..001e815ce2d2b 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php @@ -239,7 +239,7 @@ protected function createProduct(array $data, array $config) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { $this->_eventManager->dispatchEvent(['curl_failed'], [$response]); throw new \Exception('Product creation by curl handler was not successful!'); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/Category/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/Category/Curl.php index a7a421785e391..5c54b366b7ab4 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/Category/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/Category/Curl.php @@ -138,7 +138,7 @@ public function persist(FixtureInterface $fixture = null) $response = $this->backendTransport->read(); $this->backendTransport->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { $this->_eventManager->dispatchEvent(['curl_failed'], [$response]); throw new \Exception('Category creation by curl handler was not successful!'); } diff --git a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Handler/CatalogRule/Curl.php b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Handler/CatalogRule/Curl.php index b1f888424d162..47b3bd881cf3f 100644 --- a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Handler/CatalogRule/Curl.php +++ b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Handler/CatalogRule/Curl.php @@ -100,7 +100,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception( "Catalog Price Rule entity creating by curl handler was not successful! Response: $response" ); diff --git a/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Handler/CheckoutAgreement/Curl.php b/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Handler/CheckoutAgreement/Curl.php index 9c14e91a06c0b..66e8f29302f5c 100644 --- a/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Handler/CheckoutAgreement/Curl.php +++ b/dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Handler/CheckoutAgreement/Curl.php @@ -55,7 +55,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Checkout agreement creating by curl handler was not successful! Response: $response"); } preg_match('~id\/(\d*?)\/~', $response, $matches); diff --git a/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/PageForm.php b/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/PageForm.php index 5693d3ffaed92..0b7c31a092280 100644 --- a/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/PageForm.php +++ b/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/PageForm.php @@ -84,7 +84,7 @@ public function openTab($tabName) $this->browser->find($this->header)->hover(); $tab = $this->getContainerElement($tabName); $tabHeader = $tab->find('.//*[contains(@class,"admin__collapsible-title")]', Locator::SELECTOR_XPATH); - if ($tabHeader->isVisible() && !strpos($tabHeader->getAttribute('class'), '_show')) { + if ($tabHeader->isVisible() && strpos($tabHeader->getAttribute('class'), '_show') === false) { $tabHeader->hover(); $tabHeader->click(); }; diff --git a/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsBlock/Curl.php b/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsBlock/Curl.php index a60629e341811..919280ec5ea6a 100644 --- a/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsBlock/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsBlock/Curl.php @@ -59,7 +59,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("CMS Block entity creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsPage/Curl.php b/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsPage/Curl.php index f1c3becb28be4..8a18f96b99b94 100644 --- a/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsPage/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Cms/Test/Handler/CmsPage/Curl.php @@ -80,7 +80,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Cms page entity creating by curl handler was not successful! Response: $response"); } preg_match("~page_id\/(\d*?)\/~", $response, $matches); diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Curl.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Curl.php index f23ee4038db9b..91422cfa54bcf 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Curl.php @@ -101,7 +101,7 @@ public function persist(FixtureInterface $customer = null) $response = $curl->read(); $curl->close(); // After caching My Account page we cannot check by success message - if (!strpos($response, 'block-dashboard-info')) { + if (strpos($response, 'block-dashboard-info') === false) { throw new \Exception("Customer entity creating by curl handler was not successful! Response: $response"); } @@ -192,7 +192,7 @@ protected function updateCustomer(array $data) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { $this->_eventManager->dispatchEvent(['curl_failed'], [$response]); throw new \Exception('Failed to update customer!'); } diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/CustomerGroup/Curl.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/CustomerGroup/Curl.php index bca1738467c6a..0c1b4b7600605 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/CustomerGroup/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/CustomerGroup/Curl.php @@ -42,7 +42,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception( "Customer Group entity creating by curl handler was not successful! Response: $response" ); diff --git a/dev/tests/functional/tests/app/Magento/Directory/Test/Handler/CurrencyRate/Curl.php b/dev/tests/functional/tests/app/Magento/Directory/Test/Handler/CurrencyRate/Curl.php index 5316bca5a814f..9783a06813b89 100644 --- a/dev/tests/functional/tests/app/Magento/Directory/Test/Handler/CurrencyRate/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Directory/Test/Handler/CurrencyRate/Curl.php @@ -34,7 +34,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Currency rates setting by curl handler was not successful! Response:\n" . $response); } } diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Curl.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Curl.php index 81cbb40567c0e..a9e246ce1b7ca 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Curl.php @@ -116,7 +116,7 @@ protected function createProduct(array $data, array $config) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Product creation by curl handler was not successful! Response: $response"); } preg_match("~Location: [^\s]*\/id\/(\d+)~", $response, $matches); diff --git a/dev/tests/functional/tests/app/Magento/Integration/Test/Handler/Integration/Curl.php b/dev/tests/functional/tests/app/Magento/Integration/Test/Handler/Integration/Curl.php index f2dfd420ad632..5820b6c0747f8 100644 --- a/dev/tests/functional/tests/app/Magento/Integration/Test/Handler/Integration/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Integration/Test/Handler/Integration/Curl.php @@ -58,7 +58,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Integration creation by curl handler was not successful! Response: $response"); } $result['integration_id'] = $this->getIntegrationId($fixture); diff --git a/dev/tests/functional/tests/app/Magento/Newsletter/Test/Handler/Template/Curl.php b/dev/tests/functional/tests/app/Magento/Newsletter/Test/Handler/Template/Curl.php index 3f57c485d518d..5b295490ede9a 100644 --- a/dev/tests/functional/tests/app/Magento/Newsletter/Test/Handler/Template/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Newsletter/Test/Handler/Template/Curl.php @@ -37,7 +37,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Newsletter template creation by curl was not successful! Response: $response"); } $curl->close(); diff --git a/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Rating/Curl.php b/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Rating/Curl.php index e249d90166934..9205b74df5bb5 100644 --- a/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Rating/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Rating/Curl.php @@ -57,7 +57,7 @@ public function persist(FixtureInterface $rating = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception( 'Product Rating entity creating by curl handler was not successful! Response:' . $response ); diff --git a/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Review/Curl.php b/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Review/Curl.php index ebd2f9828e517..2aa4f12dd267c 100644 --- a/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Review/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Review/Test/Handler/Review/Curl.php @@ -53,7 +53,7 @@ public function persist(FixtureInterface $review = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception( 'Product Review entity creating by curl handler was not successful! Response:' . $response ); diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/Curl.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/Curl.php index 132100ee999b0..f58f4a1adafbe 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/Curl.php @@ -364,7 +364,7 @@ protected function createOrder(array $data) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Order creation by curl handler was not successful! Response: $response"); } preg_match("~

#(.*)

~", $response, $matches); diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/Curl.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/Curl.php index af332075306d8..c65bb9ad213fc 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/Curl.php @@ -61,7 +61,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("OrderStatus entity creating by curl handler was not successful! Response: $response"); } @@ -73,7 +73,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception( "Assigning OrderStatus entity by curl handler was not successful! Response: $response" ); diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php index 8d2cd72d3d494..c0fa46cfb6d18 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRule/Curl.php @@ -177,7 +177,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Sales rule entity creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Search/Test/Handler/SynonymGroup/Curl.php b/dev/tests/functional/tests/app/Magento/Search/Test/Handler/SynonymGroup/Curl.php index 20b6e490bc25f..da8837fd2edfc 100644 --- a/dev/tests/functional/tests/app/Magento/Search/Test/Handler/SynonymGroup/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Search/Test/Handler/SynonymGroup/Curl.php @@ -56,7 +56,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception( "Synonym Group entity creation by curl handler was not successful! Response: $response" ); diff --git a/dev/tests/functional/tests/app/Magento/Sitemap/Test/Handler/Sitemap/Curl.php b/dev/tests/functional/tests/app/Magento/Sitemap/Test/Handler/Sitemap/Curl.php index df3e86f885b7e..38e79e0bf0ed1 100644 --- a/dev/tests/functional/tests/app/Magento/Sitemap/Test/Handler/Sitemap/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Sitemap/Test/Handler/Sitemap/Curl.php @@ -43,7 +43,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Sitemap entity creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Store/Curl.php b/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Store/Curl.php index 2fb05e59c379a..b6a9873970815 100644 --- a/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Store/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Store/Curl.php @@ -55,7 +55,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Store View entity creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Store/Test/Handler/StoreGroup/Curl.php b/dev/tests/functional/tests/app/Magento/Store/Test/Handler/StoreGroup/Curl.php index be74cc92223cb..10ebd2b6d5f66 100644 --- a/dev/tests/functional/tests/app/Magento/Store/Test/Handler/StoreGroup/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Store/Test/Handler/StoreGroup/Curl.php @@ -33,7 +33,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Store group entity creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Website/Curl.php b/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Website/Curl.php index 95a8ac8d203dd..ab0b1f2096808 100644 --- a/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Website/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Store/Test/Handler/Website/Curl.php @@ -76,7 +76,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Website entity creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Handler/TaxRule/Curl.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Handler/TaxRule/Curl.php index 64f69d44abc80..bdc3015a81272 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/Handler/TaxRule/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Handler/TaxRule/Curl.php @@ -46,7 +46,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { $this->_eventManager->dispatchEvent(['curl_failed'], [$response]); throw new \Exception("Tax rate creation by curl handler was not successful!"); } diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php index b31bd9e4bc02b..7ea32f31f0aaa 100644 --- a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php @@ -56,7 +56,7 @@ public function persist(FixtureInterface $fixture = null) $curl->write($url, $data); $response = $curl->read(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("URL Rewrite creation by curl handler was not successful! Response: $response"); } $curl->close(); diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Handler/Role/Curl.php b/dev/tests/functional/tests/app/Magento/User/Test/Handler/Role/Curl.php index 69c42e99b1d0a..343ff844f31c7 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Handler/Role/Curl.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Handler/Role/Curl.php @@ -57,7 +57,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Role creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Handler/User/Curl.php b/dev/tests/functional/tests/app/Magento/User/Test/Handler/User/Curl.php index e200299dc6f8f..66faa243d6491 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Handler/User/Curl.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Handler/User/Curl.php @@ -40,7 +40,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Admin user entity creating by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Variable/Test/Handler/SystemVariable/Curl.php b/dev/tests/functional/tests/app/Magento/Variable/Test/Handler/SystemVariable/Curl.php index a2319e9b39bc3..b8242ca795b38 100644 --- a/dev/tests/functional/tests/app/Magento/Variable/Test/Handler/SystemVariable/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Variable/Test/Handler/SystemVariable/Curl.php @@ -34,7 +34,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("System Variable creation by curl handler was not successful! Response: $response"); } diff --git a/dev/tests/functional/tests/app/Magento/Widget/Test/Handler/Widget/Curl.php b/dev/tests/functional/tests/app/Magento/Widget/Test/Handler/Widget/Curl.php index 5cbea89222905..7077def5a4a25 100644 --- a/dev/tests/functional/tests/app/Magento/Widget/Test/Handler/Widget/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Widget/Test/Handler/Widget/Curl.php @@ -102,7 +102,7 @@ public function persist(FixtureInterface $fixture = null) $response = $curl->read(); $curl->close(); - if (!strpos($response, 'data-ui-id="messages-message-success"')) { + if (strpos($response, 'data-ui-id="messages-message-success"') === false) { throw new \Exception("Widget instance creation by curl handler was not successful! Response: $response"); } $id = null; diff --git a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php index aadeb4d0fcceb..ea155894d7299 100644 --- a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php +++ b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php @@ -284,7 +284,7 @@ private function getDirectoryIterator($path) */ private function splitPath($path) { - if (strpos($path, '::') > 0) { + if (strpos($path, '::') !== false) { list($module, $path) = explode('::', $path); return [ 'module' => $module != 'Lib' ? $module : null, diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/BlockInstantiationTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/BlockInstantiationTest.php index acaecd43e1442..20e0ceef465e4 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/BlockInstantiationTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/BlockInstantiationTest.php @@ -116,10 +116,10 @@ private function _addBlock($module, $blockClass, $class, $templateBlocks) if ($module == 'Magento_Backend' || strpos( $blockClass, '\\Adminhtml\\' - ) || strpos( + ) !== false || strpos( $blockClass, '_Backend_' - ) || $class->isSubclassOf( + ) !== false || $class->isSubclassOf( \Magento\Backend\Block\Template::class ) ) { diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/TemplateFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/TemplateFilesTest.php index 98bb054add98a..6fd67341439bc 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/TemplateFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/TemplateFilesTest.php @@ -72,10 +72,10 @@ public function allTemplatesDataProvider() if ($module == 'Magento_Backend' || strpos( $blockClass, '\\Adminhtml\\' - ) || strpos( + ) !== false || strpos( $blockClass, '\\Backend\\' - ) || $class->isSubclassOf( + ) !== false || $class->isSubclassOf( \Magento\Backend\Block\Template::class ) ) { diff --git a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php deleted file mode 100644 index 8ff5571abb494..0000000000000 --- a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/GotoSniff.php +++ /dev/null @@ -1,50 +0,0 @@ -addError($this->errorMessage, $stackPtr, $this->errorCode); - } -} diff --git a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php index 9873c9be916ab..a3a49adf62a62 100644 --- a/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php +++ b/dev/tests/static/framework/Magento/Sniffs/LanguageConstructs/LanguageConstructsSniff.php @@ -14,8 +14,7 @@ * Examples: * echo 'echo text'; * print('print text'); - * $ = `back quotes`; - * exit(1); + * $string = `back quotes`; */ class LanguageConstructsSniff implements Sniff { @@ -41,13 +40,6 @@ class LanguageConstructsSniff implements Sniff */ protected $backtickCode = 'WrongBackQuotesUsage'; - /** - * Exit usage code. - * - * @var string - */ - protected $exitUsage = 'ExitUsage'; - /** * Direct output code. * @@ -61,7 +53,6 @@ class LanguageConstructsSniff implements Sniff public function register() { return [ - T_EXIT, T_ECHO, T_PRINT, T_BACKTICK, @@ -81,11 +72,6 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->addError($this->errorMessageBacktick, $stackPtr, $this->backtickCode); return; } - if ($tokens[$stackPtr]['code'] === T_EXIT) { - $code = $this->exitUsage; - } else { - $code = $this->directOutput; - } - $phpcsFile->addError($this->errorMessage, $stackPtr, $code, [$tokens[$stackPtr]['content']]); + $phpcsFile->addError($this->errorMessage, $stackPtr, $this->directOutput, [$tokens[$stackPtr]['content']]); } } diff --git a/dev/tests/static/framework/Magento/Sniffs/Less/ClassNamingSniff.php b/dev/tests/static/framework/Magento/Sniffs/Less/ClassNamingSniff.php index cde667bc53843..9d138c2efc6d3 100644 --- a/dev/tests/static/framework/Magento/Sniffs/Less/ClassNamingSniff.php +++ b/dev/tests/static/framework/Magento/Sniffs/Less/ClassNamingSniff.php @@ -63,8 +63,8 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->addError('Class name contains not allowed symbols', $stackPtr, 'NotAllowedSymbol', $matches); } - if (!empty(strpos($className, self::STRING_HELPER_CLASSES_PREFIX)) - && empty(strpos($className, self::STRING_ALLOWED_UNDERSCORES)) + if (strpos($className, self::STRING_HELPER_CLASSES_PREFIX) !== false + && strpos($className, self::STRING_ALLOWED_UNDERSCORES) === false ) { $phpcsFile->addError('"_" symbol allowed only for helper classes', $stackPtr, 'UnderscoreSymbol'); } diff --git a/dev/tests/static/framework/Magento/ruleset.xml b/dev/tests/static/framework/Magento/ruleset.xml index c886c87be10a4..ba85f3e04c62d 100644 --- a/dev/tests/static/framework/Magento/ruleset.xml +++ b/dev/tests/static/framework/Magento/ruleset.xml @@ -29,6 +29,5 @@ - diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php index 40b88ecdf80ba..5c3f627ca35f2 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php @@ -182,7 +182,7 @@ private static function getLibraryWhiteLists() $componentRegistrar = new ComponentRegistrar(); foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $library) { $library = str_replace('\\', '/', $library); - if (strpos($library, 'Framework/')) { + if (strpos($library, 'Framework/') !== false) { $partOfLibraryPath = explode('/', $library); self::$whiteList[] = implode('\\', array_slice($partOfLibraryPath, -3)); } diff --git a/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php b/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php index 1c7e821d0409a..d2e6c01997b30 100644 --- a/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php +++ b/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php @@ -105,7 +105,7 @@ private function processType(\ReflectionClass $class, \Zend\Code\Reflection\Para return null; } - if (strpos($type, '[]')) { + if (strpos($type, '[]') !== false) { return 'array'; } diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index a6ebc50fe98bc..9ff004c53bb9b 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -122,7 +122,7 @@ public function getData($key = '', $index = null) } /* process a/b/c key as ['a']['b']['c'] */ - if (strpos($key, '/')) { + if (strpos($key, '/') !== false) { $data = $this->getDataByPath($key); } else { $data = $this->_getData($key); diff --git a/lib/internal/Magento/Framework/DataObject/Cache.php b/lib/internal/Magento/Framework/DataObject/Cache.php index 01e3a972eb94d..07394412d9be4 100644 --- a/lib/internal/Magento/Framework/DataObject/Cache.php +++ b/lib/internal/Magento/Framework/DataObject/Cache.php @@ -134,7 +134,7 @@ public function save($object, $idx = null, $tags = null) } $hash = spl_object_hash($object); - if ($idx !== null && strpos($idx, '{')) { + if ($idx !== null && strpos($idx, '{') !== false) { $idx = str_replace('{hash}', $hash, $idx); } if (isset($this->_hashes[$hash])) { diff --git a/lib/internal/Magento/Framework/EntityManager/TypeResolver.php b/lib/internal/Magento/Framework/EntityManager/TypeResolver.php index f996936ee012e..79cdbae126d7a 100644 --- a/lib/internal/Magento/Framework/EntityManager/TypeResolver.php +++ b/lib/internal/Magento/Framework/EntityManager/TypeResolver.php @@ -50,7 +50,7 @@ public function resolve($type) $interfaceNames = $reflectionClass->getInterfaceNames(); $dataInterfaces = []; foreach ($interfaceNames as $interfaceName) { - if (strpos($interfaceName, '\Api\Data\\')) { + if (strpos($interfaceName, '\Api\Data\\') !== false) { $dataInterfaces[] = $interfaceName; } } diff --git a/lib/internal/Magento/Framework/Parse/Zip.php b/lib/internal/Magento/Framework/Parse/Zip.php index 993d67a3a2120..365c279a3f2c9 100644 --- a/lib/internal/Magento/Framework/Parse/Zip.php +++ b/lib/internal/Magento/Framework/Parse/Zip.php @@ -32,7 +32,7 @@ public static function parseRegions($state, $zip) */ public static function parseZip($zip) { - if (strpos($zip, '-') == -1) { + if (strpos($zip, '-') === false) { return [$zip]; } else { return self::zipRangeToZipPattern($zip); diff --git a/lib/internal/Magento/Framework/Session/SessionManager.php b/lib/internal/Magento/Framework/Session/SessionManager.php index 2cea02fa3b361..30d214a76609d 100644 --- a/lib/internal/Magento/Framework/Session/SessionManager.php +++ b/lib/internal/Magento/Framework/Session/SessionManager.php @@ -536,7 +536,7 @@ protected function clearSubDomainSessionCookie() { foreach (array_keys($this->_getHosts()) as $host) { // Delete cookies with the same name for parent domains - if (strpos($this->sessionConfig->getCookieDomain(), $host) > 0) { + if (strpos($this->sessionConfig->getCookieDomain(), $host) !== false) { $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata(); $metadata->setPath($this->sessionConfig->getCookiePath()); $metadata->setDomain($host); diff --git a/lib/internal/Magento/Framework/View/Asset/Bundle/Manager.php b/lib/internal/Magento/Framework/View/Asset/Bundle/Manager.php index e1851bc66947a..ee1368c0e6230 100644 --- a/lib/internal/Magento/Framework/View/Asset/Bundle/Manager.php +++ b/lib/internal/Magento/Framework/View/Asset/Bundle/Manager.php @@ -175,7 +175,7 @@ protected function compareModules($filePathInfo, $asset) */ protected function splitPath($path) { - if (strpos($path, '::') > 0) { + if (strpos($path, '::') !== false) { list($excludedModule, $excludedPath) = explode('::', $path); return [ 'excludedModule' => $excludedModule, diff --git a/setup/src/Magento/Setup/Model/PackagesData.php b/setup/src/Magento/Setup/Model/PackagesData.php index d9ef28953edc7..67ab85ab64205 100644 --- a/setup/src/Magento/Setup/Model/PackagesData.php +++ b/setup/src/Magento/Setup/Model/PackagesData.php @@ -480,7 +480,7 @@ private function getPackageAvailableVersions($package) // Check we have only one repo.magento.com repository if (count($magentoRepositories) === 1 - && strpos($magentoRepositories[0], $this->packagesAuth->getCredentialBaseUrl()) + && strpos($magentoRepositories[0], $this->packagesAuth->getCredentialBaseUrl()) !== false ) { $packagesJson = $this->getPackagesJson(); diff --git a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php index a1f8d77ca77d3..d46b5d7787ad8 100644 --- a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php +++ b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php @@ -71,7 +71,7 @@ public function getList($path) try { // validate all classes except classes in generated/code dir $generatedCodeDir = DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_CODE]; - if (!strpos($path, $generatedCodeDir[DirectoryList::PATH])) { + if (strpos($path, $generatedCodeDir[DirectoryList::PATH]) === false) { $this->validator->validate($className); } $nameList[] = $className; From 6d728a5992826448ca9ac5abce0c0c2e7cdf1b7d Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Thu, 30 Nov 2017 22:14:56 +0200 Subject: [PATCH 4/5] MAGETWO-84354: Copy EQP sniffs to Magento 2 Core repo - fixed issue with admin login --- lib/internal/Magento/Framework/Session/SessionManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Session/SessionManager.php b/lib/internal/Magento/Framework/Session/SessionManager.php index 30d214a76609d..cfabff6955e49 100644 --- a/lib/internal/Magento/Framework/Session/SessionManager.php +++ b/lib/internal/Magento/Framework/Session/SessionManager.php @@ -536,7 +536,7 @@ protected function clearSubDomainSessionCookie() { foreach (array_keys($this->_getHosts()) as $host) { // Delete cookies with the same name for parent domains - if (strpos($this->sessionConfig->getCookieDomain(), $host) !== false) { + if ($this->sessionConfig->getCookieDomain() !== $host) { $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata(); $metadata->setPath($this->sessionConfig->getCookiePath()); $metadata->setDomain($host); From 704f3d16ee61c27e47f31911470c4b00919dd077 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 4 Dec 2017 16:58:14 +0200 Subject: [PATCH 5/5] MAGETWO-84354: Copy EQP sniffs to Magento 2 Core repo - fixed StringPosition sniff description --- .../framework/Magento/Sniffs/Strings/StringPositionSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php b/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php index bc3b790537e75..d98a55a6f3ee8 100644 --- a/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php +++ b/dev/tests/static/framework/Magento/Sniffs/Strings/StringPositionSniff.php @@ -9,11 +9,11 @@ use PHP_CodeSniffer\Files\File; /** - * Detects misusing of IS_IDENTICAL operators. + * Detects misusing of IS_IDENTICAL operators when `strpos` and `stripos` functions are used in a condition. * * Examples: * if (!strpos($haystack, $needle)) {} - * if (strpos($haystack, $needle) == false) {} + * if (stripos($haystack, $needle) == false) {} */ class StringPositionSniff implements Sniff {