diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/CurlClient.php b/dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/CurlClient.php index 1c1d1bb7cea5a..43491f0949d31 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/CurlClient.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/CurlClient.php @@ -13,7 +13,7 @@ class CurlClient extends \OAuth\Common\Http\Client\CurlClient { /** - * {@inheritdoc} + * @inheritdoc */ public function retrieveResponse( UriInterface $endpoint, diff --git a/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/StaticCalls.php b/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/StaticCalls.php index e70c7c3b5c1c6..f1f9d68491f33 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/StaticCalls.php +++ b/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/StaticCalls.php @@ -82,6 +82,13 @@ protected function getClassByStaticCall($staticCall) { $step = 1; $staticClassParts = []; + + $token = $this->tokens->getTokenCodeByKey($staticCall - $step); + if ($token === T_NAME_FULLY_QUALIFIED || $token === T_NAME_QUALIFIED) { + return $this->tokens->getTokenValueByKey($staticCall - $step); + } + + // PHP 7 compatibility while ($this->tokens->getTokenCodeByKey( $staticCall - $step ) == T_STRING || $this->tokens->getTokenCodeByKey( @@ -90,6 +97,7 @@ protected function getClassByStaticCall($staticCall) $staticClassParts[] = $this->tokens->getTokenValueByKey($staticCall - $step); $step++; } + return implode(array_reverse($staticClassParts)); } diff --git a/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/Throws.php b/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/Throws.php index 5e60333b24492..e14b3f21ab95c 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/Throws.php +++ b/dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/Throws.php @@ -57,14 +57,19 @@ public function getDependencies(Uses $uses) $class = ''; if ($this->tokens->getTokenCodeByKey($throw + 2) == T_NEW) { $step = 4; - while ($this->tokens->getTokenCodeByKey( - $throw + $step - ) == T_STRING || $this->tokens->getTokenCodeByKey( - $throw + $step - ) == T_NS_SEPARATOR) { - $class .= trim($this->tokens->getTokenValueByKey($throw + $step)); - $step++; + + $token = $this->tokens->getTokenCodeByKey($throw + $step); + if ($token === T_NAME_FULLY_QUALIFIED || $token === T_NAME_QUALIFIED) { + $class = $this->tokens->getTokenValueByKey($throw + $step); + } else { + // PHP 7 compatibility + while ($this->tokens->getTokenCodeByKey($throw + $step) === T_STRING + || $this->tokens->getTokenCodeByKey($throw + $step) === T_NS_SEPARATOR) { + $class .= trim($this->tokens->getTokenValueByKey($throw + $step)); + $step++; + } } + if ($uses->hasUses()) { $class = $uses->getClassNameWithNamespace($class); } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php index 622dfb329acac..0a917a8a3f20d 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php @@ -127,11 +127,9 @@ private function getPluginBlacklist(): array ); $blacklistItems = []; foreach (glob($blacklistFiles) as $fileName) { - $blacklistItems = array_merge( - $blacklistItems, - file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) - ); + $blacklistItems[] = file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } + $blacklistItems = array_merge([], ...$blacklistItems); $this->pluginBlacklist = $blacklistItems; } return $this->pluginBlacklist; @@ -243,10 +241,10 @@ protected function _phpClassesDataProvider() $allowedFiles = array_keys($classes); foreach ($classes as $class) { if (!in_array($class, $output)) { - $output = array_merge($output, $this->_buildInheritanceHierarchyTree($class, $allowedFiles)); - $output = array_unique($output); + $output[] = $this->_buildInheritanceHierarchyTree($class, $allowedFiles); } } + $output = array_unique(array_merge([], ...$output)); /** Convert data into data provider format */ $outputClasses = []; @@ -409,7 +407,7 @@ protected function pluginDataProvider() $plugin = $node->attributes->getNamedItem('type')->nodeValue; if (!in_array($plugin, $this->getPluginBlacklist())) { $plugin = \Magento\Framework\App\Utility\Classes::resolveVirtualType($plugin); - $plugins[] = ['plugin' => $plugin, 'intercepted type' => $type]; + $plugins[] = [$plugin, $type]; } } } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Framework/Api/ExtensibleInterfacesTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Framework/Api/ExtensibleInterfacesTest.php index d7ed6e2127f44..323f379fdffa9 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Framework/Api/ExtensibleInterfacesTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Framework/Api/ExtensibleInterfacesTest.php @@ -135,9 +135,10 @@ private function checkSetExtensionAttributes( } else { // Get the parameter name via a regular expression capture because the class may // not exist which causes a fatal error - preg_match('/\[\s\<\w+?>\s([\w]+)/s', $methodParameters[0]->__toString(), $matches); + preg_match('/\[\s\<\w+?>\s([?]?[\w\\\]+)/s', $methodParameters[0]->__toString(), $matches); $isCorrectParameter = false; - if (isset($matches[1]) && '\\' . $matches[1] != $extensionInterfaceName) { + if (isset($matches[1]) + && ('\\' . ltrim($matches[1], '?')) === $extensionInterfaceName) { $isCorrectParameter = true; } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/PublicCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/PublicCodeTest.php index 59183dc174682..2c94ab8ead5fc 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/PublicCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/PublicCodeTest.php @@ -11,6 +11,7 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionException; +use ReflectionMethod; use ReflectionParameter; /** @@ -111,9 +112,9 @@ public function testAllPHPClassesReferencedFromPublicClassesArePublic($class) { $nonPublishedClasses = []; $reflection = new \ReflectionClass($class); - $filter = \ReflectionMethod::IS_PUBLIC; + $filter = ReflectionMethod::IS_PUBLIC; if ($reflection->isAbstract()) { - $filter = $filter | \ReflectionMethod::IS_PROTECTED; + $filter = $filter | ReflectionMethod::IS_PROTECTED; } $methods = $reflection->getMethods($filter); foreach ($methods as $method) { @@ -125,8 +126,11 @@ public function testAllPHPClassesReferencedFromPublicClassesArePublic($class) is written on early php 7 when return types are not actively used */ $returnTypes = []; if ($method->hasReturnType()) { - if (!$method->getReturnType()->isBuiltin()) { - $returnTypes = [trim($method->getReturnType()->getName(), '?[]')]; + $methodReturnType = $method->getReturnType(); + // For PHP 8.0 - ReflectionUnionType doesn't have isBuiltin method. + if (method_exists($methodReturnType, 'isBuiltin') + && !$methodReturnType->isBuiltin()) { + $returnTypes = [trim($methodReturnType->getName(), '?[]')]; } } else { $returnTypes = $this->getReturnTypesFromDocComment($method->getDocComment()); @@ -260,16 +264,20 @@ private function checkReturnValues($class, array $returnTypes, array $nonPublish /** * Check if all method parameters are public + * * @param string $class - * @param \ReflectionMethod $method + * @param ReflectionMethod $method * @param array $nonPublishedClasses + * * @return array + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - private function checkParameters($class, \ReflectionMethod $method, array $nonPublishedClasses) + private function checkParameters($class, ReflectionMethod $method, array $nonPublishedClasses) { /* Ignoring docblocks for argument types */ foreach ($method->getParameters() as $parameter) { if ($parameter->hasType() + && method_exists($parameter->getType(), 'isBuiltin') && !$parameter->getType()->isBuiltin() && !$this->isGenerated($parameter->getType()->getName()) ) { diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/ReadmeTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/ReadmeTest.php index 050c9ca05a5ef..053da8c41d55a 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/ReadmeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/ReadmeTest.php @@ -57,7 +57,7 @@ private function getDirectories() $directories = []; foreach ($this->scanList as $dir) { if (!$this->isInBlacklist($dir)) { - $directories[][$dir] = $dir; + $directories[][] = $dir; } }