From 80b4640fbb7b183478daef0474242e96fc088297 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 20:56:42 +0700 Subject: [PATCH 01/38] [Step 3 Upgrade] Bump requirement to php 8.1 --- .github/workflows/phpunit.yml | 2 +- composer.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 42a6481c..e8605273 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -16,7 +16,7 @@ jobs: - "lowest" - "highest" php-version: - - "8.0" + - "8.1" operating-system: - "ubuntu-latest" diff --git a/composer.json b/composer.json index 4cd8ef00..3cef9a69 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,11 @@ } }, "require": { - "php": ">=8.0", + "php": ">=8.1", "nikic/php-parser": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^10.0", "tracy/tracy": "^2.10" }, "extra": { From 084a9bc5c05cb12cf44d628ea8bfcabdaff46ed3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 21:06:36 +0700 Subject: [PATCH 02/38] update phpunit syntax compatibility --- composer.json | 3 ++- phpunit.xml.dist | 12 ++++++------ rector.php | 20 ++++++++++++++++++++ tests/AbstractTestCase.php | 5 +++-- tests/ReflectionClassConstantTest.php | 1 + tests/ReflectionClassTest.php | 18 +++++++++--------- tests/ReflectionFileTest.php | 5 ++--- tests/ReflectionFunctionTest.php | 1 + tests/ReflectionMethodTest.php | 10 +++++----- tests/ReflectionParameterTest.php | 12 +++++------- tests/ReflectionPropertyTest.php | 10 +++++----- 11 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index 3cef9a69..ac9a8f1d 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ }, "require-dev": { "phpunit/phpunit": "^10.0", - "tracy/tracy": "^2.10" + "tracy/tracy": "^2.10", + "rector/rector": "^0.19.0" }, "extra": { "branch-alias": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 88f4b939..4dc11c2c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ - - - - ./src/ - - + ./tests/ + + + ./src/ + + diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..5d2797a3 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +paths([ + __DIR__ . '/tests', + ]); + + $rectorConfig->sets([ + PHPUnitSetList::PHPUNIT_60, + PHPUnitSetList::PHPUNIT_70, + PHPUnitSetList::PHPUNIT_80, + PHPUnitSetList::PHPUNIT_90, + PHPUnitSetList::PHPUNIT_100, + ]); +}; diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index c05cc145..74d5cfce 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -41,6 +41,7 @@ abstract class AbstractTestCase extends TestCase */ protected static $defaultClassToLoad = AbstractClassWithMethods::class; + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testCoverAllMethods() { $allInternalMethods = get_class_methods(static::$reflectionClassToTest); @@ -68,7 +69,7 @@ public function testCoverAllMethods() * * @return array */ - public function getFilesToAnalyze() + public static function getFilesToAnalyze() { $files = ['PHP5.5' => [__DIR__ . '/Stub/FileWithClasses55.php']]; $files['PHP5.6'] = [__DIR__ . '/Stub/FileWithClasses56.php']; @@ -83,7 +84,7 @@ public function getFilesToAnalyze() * * @return array */ - abstract protected function getGettersToCheck(); + abstract static protected function getGettersToCheck(); /** * Setups file for parsing diff --git a/tests/ReflectionClassConstantTest.php b/tests/ReflectionClassConstantTest.php index a7c2e569..7d322b43 100644 --- a/tests/ReflectionClassConstantTest.php +++ b/tests/ReflectionClassConstantTest.php @@ -77,6 +77,7 @@ public function testGetClassConstant() $this->assertSame($classConstants[4], $parsedClass->getReflectionConstant('CALCULATED_CONST')); } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testCoverAllMethods() { $allInternalMethods = get_class_methods(\ReflectionClassConstant::class); diff --git a/tests/ReflectionClassTest.php b/tests/ReflectionClassTest.php index 2d1a0b78..058d7bca 100644 --- a/tests/ReflectionClassTest.php +++ b/tests/ReflectionClassTest.php @@ -24,10 +24,10 @@ class ReflectionClassTest extends AbstractTestCase * Tests getModifier() method * NB: value is masked because there are many internal constants that aren't exported in the userland * - * @dataProvider getFilesToAnalyze * * @param string $fileName File name to test */ + #[\PHPUnit\Framework\Attributes\DataProvider('getFilesToAnalyze')] public function testGetModifiers($fileName) { $mask = @@ -48,12 +48,12 @@ public function testGetModifiers($fileName) /** * Performs method-by-method comparison with original reflection * - * @dataProvider caseProvider * * @param ReflectionClass $parsedClass Parsed class * @param \ReflectionMethod $refMethod Method to analyze * @param string $getterName Name of the reflection method to test */ + #[\PHPUnit\Framework\Attributes\DataProvider('caseProvider')] public function testReflectionMethodParity( ReflectionClass $parsedClass, $getterName @@ -75,12 +75,12 @@ public function testReflectionMethodParity( * * @return array */ - public function caseProvider() + public static function caseProvider() { - $allNameGetters = $this->getGettersToCheck(); + $allNameGetters = static::getGettersToCheck(); $testCases = []; - $files = $this->getFilesToAnalyze(); + $files = static::getFilesToAnalyze(); foreach ($files as $fileList) { foreach ($fileList as $fileName) { $fileName = stream_resolve_include_path($fileName); @@ -108,10 +108,10 @@ public function caseProvider() /** * Tests getMethods() returns correct number of methods for the class * - * @dataProvider getFilesToAnalyze * * @param string $fileName File name to test */ + #[\PHPUnit\Framework\Attributes\DataProvider('getFilesToAnalyze')] public function testGetMethodCount($fileName) { $this->setUpFile($fileName); @@ -131,10 +131,10 @@ public function testGetMethodCount($fileName) /** * Tests getReflectionConstants() returns correct number of reflectionConstants for the class * - * @dataProvider getFilesToAnalyze * * @param string $fileName File name to test */ + #[\PHPUnit\Framework\Attributes\DataProvider('getFilesToAnalyze')] public function testGetReflectionConstantCount($fileName) { $this->setUpFile($fileName); @@ -153,10 +153,10 @@ public function testGetReflectionConstantCount($fileName) /** * Tests getProperties() returns correct number of properties for the class * - * @dataProvider getFilesToAnalyze * * @param string $fileName File name to test */ + #[\PHPUnit\Framework\Attributes\DataProvider('getFilesToAnalyze')] public function testGetProperties($fileName) { $this->setUpFile($fileName); @@ -316,7 +316,7 @@ public function testGetReflectionConstant() * * @return array */ - protected function getGettersToCheck() + protected static function getGettersToCheck() { $allNameGetters = [ 'getStartLine', 'getEndLine', 'getDocComment', 'getExtension', 'getExtensionName', diff --git a/tests/ReflectionFileTest.php b/tests/ReflectionFileTest.php index d6229a33..3290518d 100644 --- a/tests/ReflectionFileTest.php +++ b/tests/ReflectionFileTest.php @@ -70,9 +70,8 @@ public function testGetGlobalFileNamespace() * * @param string $fileName Filename to analyse * @param bool $shouldBeStrict - * - * @dataProvider fileNameProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('fileNameProvider')] public function testIsStrictType($fileName, $shouldBeStrict) { $fileName = stream_resolve_include_path(__DIR__ . $fileName); @@ -81,7 +80,7 @@ public function testIsStrictType($fileName, $shouldBeStrict) $this->assertSame($shouldBeStrict, $reflectionFile->isStrictMode()); } - public function fileNameProvider() + public static function fileNameProvider() { return [ '/Stub/FileWithClasses56.php' => ['/Stub/FileWithClasses56.php', false], diff --git a/tests/ReflectionFunctionTest.php b/tests/ReflectionFunctionTest.php index 1239983f..481a9888 100644 --- a/tests/ReflectionFunctionTest.php +++ b/tests/ReflectionFunctionTest.php @@ -53,6 +53,7 @@ public function testGeneralInfoGetters() } } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testCoverAllMethods() { $allInternalMethods = get_class_methods(\ReflectionFunction::class); diff --git a/tests/ReflectionMethodTest.php b/tests/ReflectionMethodTest.php index 9d84b183..5292f1ea 100644 --- a/tests/ReflectionMethodTest.php +++ b/tests/ReflectionMethodTest.php @@ -63,12 +63,12 @@ public function testGetPrototypeMethod() /** * Performs method-by-method comparison with original reflection * - * @dataProvider caseProvider * * @param ReflectionClass $parsedClass Parsed class * @param \ReflectionMethod $refMethod Method to analyze * @param string $getterName Name of the reflection method to test */ + #[\PHPUnit\Framework\Attributes\DataProvider('caseProvider')] public function testReflectionMethodParity( ReflectionClass $parsedClass, \ReflectionMethod $refMethod, @@ -96,12 +96,12 @@ public function testReflectionMethodParity( * * @return array */ - public function caseProvider() + public static function caseProvider() { - $allNameGetters = $this->getGettersToCheck(); + $allNameGetters = static::getGettersToCheck(); $testCases = []; - $files = $this->getFilesToAnalyze(); + $files = static::getFilesToAnalyze(); foreach ($files as $fileList) { foreach ($fileList as $fileName) { $fileName = stream_resolve_include_path($fileName); @@ -136,7 +136,7 @@ public function caseProvider() * * @return array */ - protected function getGettersToCheck() + protected static function getGettersToCheck() { $allNameGetters = [ 'getStartLine', 'getEndLine', 'getDocComment', 'getExtension', 'getExtensionName', 'getName', diff --git a/tests/ReflectionParameterTest.php b/tests/ReflectionParameterTest.php index 5210fb7a..4f7cbef4 100644 --- a/tests/ReflectionParameterTest.php +++ b/tests/ReflectionParameterTest.php @@ -20,9 +20,7 @@ protected function setUp(): void $this->setUpFile(__DIR__ . '/Stub/FileWithParameters55.php'); } - /** - * @dataProvider fileProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('fileProvider')] public function testGeneralInfoGetters($fileName) { $this->setUpFile($fileName); @@ -68,7 +66,7 @@ public function testGeneralInfoGetters($fileName) * * @return array */ - public function fileProvider() + public static function fileProvider() { $files = ['PHP5.5' => [__DIR__ . '/Stub/FileWithParameters55.php']]; $files['PHP5.6'] = [__DIR__ . '/Stub/FileWithParameters56.php']; @@ -187,10 +185,9 @@ public function testDebugInfoMethod() } /** - * @dataProvider listOfDefaultGetters - * * @param string $getterName Name of the getter to call */ + #[\PHPUnit\Framework\Attributes\DataProvider('listOfDefaultGetters')] public function testGetDefaultValueThrowsAnException($getterName) { $originalException = null; @@ -219,7 +216,7 @@ public function testGetDefaultValueThrowsAnException($getterName) $this->assertSame($originalException->getMessage(), $parsedException->getMessage()); } - public function listOfDefaultGetters() + public static function listOfDefaultGetters() { return [ ['getDefaultValue'], @@ -227,6 +224,7 @@ public function listOfDefaultGetters() ]; } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testCoverAllMethods() { $allInternalMethods = get_class_methods(\ReflectionParameter::class); diff --git a/tests/ReflectionPropertyTest.php b/tests/ReflectionPropertyTest.php index 6af6969b..5f9df6fd 100644 --- a/tests/ReflectionPropertyTest.php +++ b/tests/ReflectionPropertyTest.php @@ -25,12 +25,12 @@ class ReflectionPropertyTest extends AbstractTestCase /** * Performs method-by-method comparison with original reflection * - * @dataProvider caseProvider * * @param ReflectionClass $parsedClass Parsed class * @param \ReflectionProperty $refProperty Property to analyze * @param string $getterName Name of the reflection method to test */ + #[\PHPUnit\Framework\Attributes\DataProvider('caseProvider')] public function testReflectionMethodParity( ReflectionClass $parsedClass, \ReflectionProperty $refProperty, @@ -54,12 +54,12 @@ public function testReflectionMethodParity( * * @return array */ - public function caseProvider() + public static function caseProvider() { - $allNameGetters = $this->getGettersToCheck(); + $allNameGetters = static::getGettersToCheck(); $testCases = []; - $files = $this->getFilesToAnalyze(); + $files = static::getFilesToAnalyze(); foreach ($files as $fileList) { foreach ($fileList as $fileName) { $fileName = stream_resolve_include_path($fileName); @@ -134,7 +134,7 @@ public function testDebugInfoMethod() * * @return array */ - protected function getGettersToCheck() + protected static function getGettersToCheck() { $allNameGetters = [ 'isDefault', 'getName', 'getModifiers', 'getDocComment', From 66d040cd249bad2159da9b4d35b953234662b911 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 21:08:16 +0700 Subject: [PATCH 03/38] rollback rector temporary usage --- composer.json | 3 +-- rector.php | 20 -------------------- 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 rector.php diff --git a/composer.json b/composer.json index ac9a8f1d..3cef9a69 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,7 @@ }, "require-dev": { "phpunit/phpunit": "^10.0", - "tracy/tracy": "^2.10", - "rector/rector": "^0.19.0" + "tracy/tracy": "^2.10" }, "extra": { "branch-alias": { diff --git a/rector.php b/rector.php deleted file mode 100644 index 5d2797a3..00000000 --- a/rector.php +++ /dev/null @@ -1,20 +0,0 @@ -paths([ - __DIR__ . '/tests', - ]); - - $rectorConfig->sets([ - PHPUnitSetList::PHPUNIT_60, - PHPUnitSetList::PHPUNIT_70, - PHPUnitSetList::PHPUNIT_80, - PHPUnitSetList::PHPUNIT_90, - PHPUnitSetList::PHPUNIT_100, - ]); -}; From 1404d82da103b5bef037b1a8315e742b4a04d356 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 21:21:29 +0700 Subject: [PATCH 04/38] fix default value on ReflectionProperty and ReflectionParameter --- src/ReflectionParameter.php | 10 +--------- src/ReflectionProperty.php | 18 +----------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 6fd65068..aadbf424 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -140,15 +140,7 @@ public function __toString() $defaultValue = ''; if ($hasDefaultValue) { $defaultValue = $this->getDefaultValue(); - if (is_string($defaultValue) && strlen($defaultValue) > 15) { - $defaultValue = substr($defaultValue, 0, 15) . '...'; - } - /* @see https://3v4l.org/DJOEb for behaviour changes */ - if (is_float($defaultValue) && fmod($defaultValue, 1.0) === 0.0) { - $defaultValue = (int)$defaultValue; - } - - $defaultValue = str_replace('\\\\', '\\', var_export($defaultValue, true)); + $defaultValue = str_replace('\\', '\\', var_export($defaultValue, true)); } return sprintf( diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 05ecc556..2a4e9ebf 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -118,23 +118,7 @@ public function __toString() if ($this->isDefault()) { $this->__initialize(); $defaultValue = $this->getDefaultValue(); - if (is_string($defaultValue)) { - if (strlen($defaultValue) > 18) { - $defaultValue = substr($defaultValue, 0, 15) . '...'; - } - - $defaultValue = "'" . $defaultValue . "'"; - } - - if ($defaultValue === null) { - $defaultValue = "NULL"; - } - - if (is_array($defaultValue)) { - $defaultValueDisplay = '= Array'; - } else { - $defaultValueDisplay = '= ' . $defaultValue; - } + $defaultValueDisplay = '= ' . str_replace('\\', '\\', var_export($defaultValue, true)); } return sprintf( From 7133ac45d1039c0000621792f8d647825ef5d90e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 21:35:56 +0700 Subject: [PATCH 05/38] general default value display --- src/ReflectionParameter.php | 4 +++- src/ReflectionProperty.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index aadbf424..a9711cde 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -140,7 +140,9 @@ public function __toString() $defaultValue = ''; if ($hasDefaultValue) { $defaultValue = $this->getDefaultValue(); - $defaultValue = str_replace('\\', '\\', var_export($defaultValue, true)); + $defaultValue = is_array($defaultValue) + ? $defaultValue + : str_replace('\\', '\\', var_export($defaultValue, true)); } return sprintf( diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 2a4e9ebf..b941e1a1 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -118,7 +118,9 @@ public function __toString() if ($this->isDefault()) { $this->__initialize(); $defaultValue = $this->getDefaultValue(); - $defaultValueDisplay = '= ' . str_replace('\\', '\\', var_export($defaultValue, true)); + $defaultValueDisplay = is_array($defaultValue) + ? '= ' . $defaultValue + : '= ' . str_replace('\\', '\\', var_export($defaultValue, true)); } return sprintf( From c9bb8feceb4536d543d12ada80affad4d26afc87 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 21:43:43 +0700 Subject: [PATCH 06/38] various return type add --- src/ReflectionClassConstant.php | 2 +- src/ReflectionFileNamespace.php | 2 +- src/ReflectionProperty.php | 2 +- src/Traits/ReflectionClassLikeTrait.php | 17 +++++++++-------- src/Traits/ReflectionFunctionLikeTrait.php | 11 ++++++----- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ReflectionClassConstant.php b/src/ReflectionClassConstant.php index bb14c626..06cb69fe 100644 --- a/src/ReflectionClassConstant.php +++ b/src/ReflectionClassConstant.php @@ -119,7 +119,7 @@ public function getDeclaringClass() /** * @inheritDoc */ - public function getDocComment() + public function getDocComment(): string|false { $docBlock = $this->classConstantNode->getDocComment(); diff --git a/src/ReflectionFileNamespace.php b/src/ReflectionFileNamespace.php index 39f34232..62a577d6 100644 --- a/src/ReflectionFileNamespace.php +++ b/src/ReflectionFileNamespace.php @@ -165,7 +165,7 @@ public function getConstants(bool $withDefined = false): array * * @return string|false The doc comment if it exists, otherwise "false" */ - public function getDocComment() + public function getDocComment(): string|false { $docComment = false; $comments = $this->namespaceNode->getAttribute('comments'); diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index b941e1a1..4c94405e 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -142,7 +142,7 @@ public function getDeclaringClass() /** * @inheritDoc */ - public function getDocComment() + public function getDocComment(): string|false { $docBlock = $this->propertyTypeNode->getDocComment(); diff --git a/src/Traits/ReflectionClassLikeTrait.php b/src/Traits/ReflectionClassLikeTrait.php index 5e1b6dad..d1c7f5ff 100644 --- a/src/Traits/ReflectionClassLikeTrait.php +++ b/src/Traits/ReflectionClassLikeTrait.php @@ -26,6 +26,7 @@ use PhpParser\Node\Stmt\Interface_; use PhpParser\Node\Stmt\Trait_; use PhpParser\Node\Stmt\TraitUseAdaptation; +use ReflectionExtension; use ReflectionObject; use RuntimeException; @@ -209,7 +210,7 @@ public function __toString() /** * {@inheritDoc} */ - public function getConstant($name) + public function getConstant($name): mixed { if ($this->hasConstant($name)) { return $this->constants[$name]; @@ -238,7 +239,7 @@ function (array &$result, \ReflectionClass $instance) { /** * {@inheritDoc} */ - public function getConstructor() + public function getConstructor(): ?ReflectionMethod { $constructor = $this->getMethod('__construct'); if (!$constructor) { @@ -256,7 +257,7 @@ public function getConstructor() * @return array An array of default properties, with the key being the name of the property and the value being * the default value of the property or NULL if the property doesn't have a default value */ - public function getDefaultProperties() + public function getDefaultProperties(): array { $defaultValues = []; $properties = $this->getProperties(); @@ -289,29 +290,29 @@ public function getDefaultProperties() /** * {@inheritDoc} */ - public function getDocComment() + public function getDocComment(): string|false { $docComment = $this->classLikeNode->getDocComment(); return $docComment ? $docComment->getText() : false; } - public function getEndLine() + public function getEndLine(): int { return $this->classLikeNode->getAttribute('endLine'); } - public function getExtension() + public function getExtension(): ?ReflectionExtension { return null; } - public function getExtensionName() + public function getExtensionName(): string|false { return false; } - public function getFileName() + public function getFileName(): string|false { return $this->classLikeNode->getAttribute('fileName'); } diff --git a/src/Traits/ReflectionFunctionLikeTrait.php b/src/Traits/ReflectionFunctionLikeTrait.php index b6282b10..cd6de89c 100644 --- a/src/Traits/ReflectionFunctionLikeTrait.php +++ b/src/Traits/ReflectionFunctionLikeTrait.php @@ -24,6 +24,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use PhpParser\NodeTraverser; +use ReflectionExtension; /** * General trait for all function-like reflections @@ -69,29 +70,29 @@ public function getClosureThis() return parent::getClosureThis(); } - public function getDocComment() + public function getDocComment(): string|false { $docComment = $this->functionLikeNode->getDocComment(); return $docComment ? $docComment->getText() : false; } - public function getEndLine() + public function getEndLine(): int { return $this->functionLikeNode->getAttribute('endLine'); } - public function getExtension() + public function getExtension(): ?ReflectionExtension { return null; } - public function getExtensionName() + public function getExtensionName(): string|false { return false; } - public function getFileName() + public function getFileName(): string|false { return $this->functionLikeNode->getAttribute('fileName'); } From f795b7e2505e04796255d209901bebf8b51df504 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 22:05:55 +0700 Subject: [PATCH 07/38] fix various return type --- src/ReflectionClassConstant.php | 2 +- src/ReflectionMethod.php | 2 +- src/ReflectionProperty.php | 2 +- src/Traits/ReflectionClassLikeTrait.php | 42 +++++++++++----------- src/Traits/ReflectionFunctionLikeTrait.php | 36 +++++++++---------- 5 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/ReflectionClassConstant.php b/src/ReflectionClassConstant.php index 06cb69fe..6bc07a7c 100644 --- a/src/ReflectionClassConstant.php +++ b/src/ReflectionClassConstant.php @@ -129,7 +129,7 @@ public function getDocComment(): string|false /** * @inheritDoc */ - public function getModifiers() + public function getModifiers(): int { $modifiers = 0; if ($this->isPublic()) { diff --git a/src/ReflectionMethod.php b/src/ReflectionMethod.php index 49276775..b5f5d1a2 100644 --- a/src/ReflectionMethod.php +++ b/src/ReflectionMethod.php @@ -156,7 +156,7 @@ public function getDeclaringClass() /** * {@inheritDoc} */ - public function getModifiers() + public function getModifiers(): int { $modifiers = 0; if ($this->isPublic()) { diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 4c94405e..f5ad7a9c 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -152,7 +152,7 @@ public function getDocComment(): string|false /** * {@inheritDoc} */ - public function getModifiers() + public function getModifiers(): int { $modifiers = 0; if ($this->isPublic()) { diff --git a/src/Traits/ReflectionClassLikeTrait.php b/src/Traits/ReflectionClassLikeTrait.php index d1c7f5ff..ee92b577 100644 --- a/src/Traits/ReflectionClassLikeTrait.php +++ b/src/Traits/ReflectionClassLikeTrait.php @@ -320,7 +320,7 @@ public function getFileName(): string|false /** * {@inheritDoc} */ - public function getInterfaceNames() + public function getInterfaceNames(): array { return array_keys($this->getInterfaces()); } @@ -328,7 +328,7 @@ public function getInterfaceNames() /** * {@inheritDoc} */ - public function getInterfaces() + public function getInterfaces(): array { if (!isset($this->interfaceClasses)) { $this->interfaceClasses = $this->recursiveCollect( @@ -365,9 +365,9 @@ public function getMethod($name) * * @param null|int $filter Optional filter * - * @return array|\ReflectionMethod[] + * @return \ReflectionMethod[] */ - public function getMethods($filter = null) + public function getMethods($filter = null): array { if (!isset($this->methods)) { $directMethods = ReflectionMethod::collectFromClassNode($this->classLikeNode, $this); @@ -407,10 +407,8 @@ function (array &$result, \ReflectionClass $instance, $isParent) { * @link http://php.net/manual/en/reflectionclass.getmodifiers.php * * NB: this method is not fully compatible with original value because of hidden internal constants - * - * @return int */ - public function getModifiers() + public function getModifiers(): int { $modifiers = 0; @@ -584,7 +582,7 @@ public function getShortName() return $this->className; } - public function getStartLine() + public function getStartLine(): int { return $this->classLikeNode->getAttribute('startLine'); } @@ -625,7 +623,7 @@ public function getTraitAliases() * * @return array */ - public function getTraitNames() + public function getTraitNames(): array { return array_keys($this->getTraits()); } @@ -635,9 +633,9 @@ public function getTraitNames() * * @link http://php.net/manual/en/reflectionclass.gettraits.php * - * @return array|\ReflectionClass[] + * @return \ReflectionClass[] */ - public function getTraits() + public function getTraits(): array { if (!isset($this->traits)) { $traitAdaptations = []; @@ -781,7 +779,7 @@ public function isInstance($object) /** * {@inheritDoc} */ - public function isInstantiable() + public function isInstantiable(): bool { if ($this->isInterface() || $this->isTrait() || $this->isAbstract()) { return false; @@ -797,15 +795,15 @@ public function isInstantiable() /** * {@inheritDoc} */ - public function isInterface() + public function isInterface(): bool { - return ($this->classLikeNode instanceof Interface_); + return $this->classLikeNode instanceof Interface_; } /** * {@inheritDoc} */ - public function isInternal() + public function isInternal(): bool { // never can be an internal method return false; @@ -814,7 +812,7 @@ public function isInternal() /** * {@inheritDoc} */ - public function isIterateable() + public function isIterateable(): bool { return $this->implementsInterface('Traversable'); } @@ -822,7 +820,7 @@ public function isIterateable() /** * {@inheritDoc} */ - public function isSubclassOf($class) + public function isSubclassOf($class): bool { if (is_object($class)) { if ($class instanceof ReflectionClass) { @@ -851,15 +849,15 @@ public function isSubclassOf($class) /** * {@inheritDoc} */ - public function isTrait() + public function isTrait(): bool { - return ($this->classLikeNode instanceof Trait_); + return $this->classLikeNode instanceof Trait_; } /** * {@inheritDoc} */ - public function isUserDefined() + public function isUserDefined(): bool { // always defined by user, because we parse the source code return true; @@ -872,7 +870,7 @@ public function isUserDefined() * * @return array */ - public function getStaticProperties() + public function getStaticProperties(): array { // In runtime static properties can be changed in any time if ($this->__isInitialized()) { @@ -985,7 +983,7 @@ public function setStaticPropertyValue($name, $value) parent::setStaticPropertyValue($name, $value); } - private function recursiveCollect(Closure $collector) + private function recursiveCollect(Closure $collector): array { $result = []; $isParent = true; diff --git a/src/Traits/ReflectionFunctionLikeTrait.php b/src/Traits/ReflectionFunctionLikeTrait.php index cd6de89c..5387639d 100644 --- a/src/Traits/ReflectionFunctionLikeTrait.php +++ b/src/Traits/ReflectionFunctionLikeTrait.php @@ -100,7 +100,7 @@ public function getFileName(): string|false /** * {@inheritDoc} */ - public function getName() + public function getName(): string { if ($this->functionLikeNode instanceof Function_ || $this->functionLikeNode instanceof ClassMethod) { $functionName = $this->functionLikeNode->name->toString(); @@ -108,13 +108,13 @@ public function getName() return $this->namespaceName ? $this->namespaceName . '\\' . $functionName : $functionName; } - return false; + return ''; } /** * {@inheritDoc} */ - public function getNamespaceName() + public function getNamespaceName(): string { return $this->namespaceName; } @@ -123,10 +123,8 @@ public function getNamespaceName() * Get the number of parameters that a function defines, both optional and required. * * @link http://php.net/manual/en/reflectionfunctionabstract.getnumberofparameters.php - * - * @return int */ - public function getNumberOfParameters() + public function getNumberOfParameters(): int { return count($this->functionLikeNode->getParams()); } @@ -135,10 +133,8 @@ public function getNumberOfParameters() * Get the number of required parameters that a function defines. * * @link http://php.net/manual/en/reflectionfunctionabstract.getnumberofrequiredparameters.php - * - * @return int */ - public function getNumberOfRequiredParameters() + public function getNumberOfRequiredParameters(): int { $requiredParameters = 0; foreach ($this->getParameters() as $parameter) { @@ -153,7 +149,7 @@ public function getNumberOfRequiredParameters() /** * {@inheritDoc} */ - public function getParameters() + public function getParameters(): array { if (!isset($this->parameters)) { $parameters = []; @@ -218,7 +214,7 @@ public function getShortName() return false; } - public function getStartLine() + public function getStartLine(): int { return $this->functionLikeNode->getAttribute('startLine'); } @@ -245,7 +241,7 @@ public function getStaticVariables() * * @link http://php.net/manual/en/reflectionfunctionabstract.hasreturntype.php */ - public function hasReturnType() + public function hasReturnType(): bool { $returnType = $this->functionLikeNode->getReturnType(); @@ -255,7 +251,7 @@ public function hasReturnType() /** * {@inheritDoc} */ - public function inNamespace() + public function inNamespace(): bool { return !empty($this->namespaceName); } @@ -263,7 +259,7 @@ public function inNamespace() /** * {@inheritDoc} */ - public function isClosure() + public function isClosure(): bool { return $this->functionLikeNode instanceof Closure; } @@ -271,7 +267,7 @@ public function isClosure() /** * {@inheritDoc} */ - public function isDeprecated() + public function isDeprecated(): bool { // user-land method/function/closure can not be deprecated return false; @@ -280,7 +276,7 @@ public function isDeprecated() /** * {@inheritDoc} */ - public function isGenerator() + public function isGenerator(): bool { $nodeTraverser = new NodeTraverser(); $nodeDetector = new GeneratorDetector(); @@ -295,7 +291,7 @@ public function isGenerator() /** * {@inheritDoc} */ - public function isInternal() + public function isInternal(): bool { // never can be an internal method return false; @@ -304,7 +300,7 @@ public function isInternal() /** * {@inheritDoc} */ - public function isUserDefined() + public function isUserDefined(): bool { // always defined by user, because we parse the source code return true; @@ -313,7 +309,7 @@ public function isUserDefined() /** * {@inheritDoc} */ - public function isVariadic() + public function isVariadic(): bool { foreach ($this->getParameters() as $parameter) { if ($parameter->isVariadic()) { @@ -327,7 +323,7 @@ public function isVariadic() /** * {@inheritDoc} */ - public function returnsReference() + public function returnsReference(): bool { return $this->functionLikeNode->returnsByRef(); } From daf9d9f8be22c84eb040a49550ade0f012136567 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 22:20:23 +0700 Subject: [PATCH 08/38] fix various return type --- src/ReflectionClassConstant.php | 6 +++--- src/ReflectionFunction.php | 2 +- src/ReflectionMethod.php | 18 +++++++++--------- src/ReflectionNamedType.php | 8 ++++---- src/ReflectionParameter.php | 16 ++++++++-------- src/ReflectionProperty.php | 16 ++++++++-------- src/ReflectionType.php | 2 +- src/Traits/ReflectionClassLikeTrait.php | 14 +++++++------- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/ReflectionClassConstant.php b/src/ReflectionClassConstant.php index 6bc07a7c..0ea30812 100644 --- a/src/ReflectionClassConstant.php +++ b/src/ReflectionClassConstant.php @@ -166,7 +166,7 @@ public function getValue() /** * @inheritDoc */ - public function isPrivate() + public function isPrivate(): bool { return $this->classConstantNode->isPrivate(); } @@ -174,7 +174,7 @@ public function isPrivate() /** * @inheritDoc */ - public function isProtected() + public function isProtected(): bool { return $this->classConstantNode->isProtected(); } @@ -182,7 +182,7 @@ public function isProtected() /** * @inheritDoc */ - public function isPublic() + public function isPublic(): bool { return $this->classConstantNode->isPublic(); } diff --git a/src/ReflectionFunction.php b/src/ReflectionFunction.php index 7a3d74c3..fece905a 100644 --- a/src/ReflectionFunction.php +++ b/src/ReflectionFunction.php @@ -100,7 +100,7 @@ public function invokeArgs(array $args) * Only internal functions can be disabled using disable_functions directive. * User-defined functions are unaffected. */ - public function isDisabled() + public function isDisabled(): bool { return false; } diff --git a/src/ReflectionMethod.php b/src/ReflectionMethod.php index b5f5d1a2..f22fd555 100644 --- a/src/ReflectionMethod.php +++ b/src/ReflectionMethod.php @@ -222,7 +222,7 @@ public function invokeArgs(?object $object, array $args): mixed /** * {@inheritDoc} */ - public function isAbstract() + public function isAbstract(): bool { return $this->getDeclaringClass()->isInterface() || $this->getClassMethodNode()->isAbstract(); } @@ -230,7 +230,7 @@ public function isAbstract() /** * {@inheritDoc} */ - public function isConstructor() + public function isConstructor(): bool { return $this->getClassMethodNode()->name->toLowerString() === '__construct'; } @@ -238,7 +238,7 @@ public function isConstructor() /** * {@inheritDoc} */ - public function isDestructor() + public function isDestructor(): bool { return $this->getClassMethodNode()->name->toLowerString() === '__destruct'; } @@ -246,7 +246,7 @@ public function isDestructor() /** * {@inheritDoc} */ - public function isFinal() + public function isFinal(): bool { return $this->getClassMethodNode()->isFinal(); } @@ -254,7 +254,7 @@ public function isFinal() /** * {@inheritDoc} */ - public function isPrivate() + public function isPrivate(): bool { return $this->getClassMethodNode()->isPrivate(); } @@ -262,7 +262,7 @@ public function isPrivate() /** * {@inheritDoc} */ - public function isProtected() + public function isProtected(): bool { return $this->getClassMethodNode()->isProtected(); } @@ -270,7 +270,7 @@ public function isProtected() /** * {@inheritDoc} */ - public function isPublic() + public function isPublic(): bool { return $this->getClassMethodNode()->isPublic(); } @@ -278,7 +278,7 @@ public function isPublic() /** * {@inheritDoc} */ - public function isStatic() + public function isStatic(): bool { return $this->getClassMethodNode()->isStatic(); } @@ -286,7 +286,7 @@ public function isStatic() /** * {@inheritDoc} */ - public function setAccessible($accessible) + public function setAccessible($accessible): void { $this->initializeInternalReflection(); diff --git a/src/ReflectionNamedType.php b/src/ReflectionNamedType.php index 569be319..9098825e 100644 --- a/src/ReflectionNamedType.php +++ b/src/ReflectionNamedType.php @@ -51,7 +51,7 @@ public function __construct($type, $allowsNull, $isBuiltin) /** * @inheritDoc */ - public function allowsNull() + public function allowsNull(): bool { return $this->allowsNull; } @@ -59,7 +59,7 @@ public function allowsNull() /** * @inheritDoc */ - public function isBuiltin() + public function isBuiltin(): bool { return $this->isBuiltin; } @@ -67,7 +67,7 @@ public function isBuiltin() /** * @inheritDoc */ - public function __toString() + public function __toString(): string { return $this->type; } @@ -75,7 +75,7 @@ public function __toString() /** * @inheritDoc */ - public function getName() + public function getName(): string { return $this->type; } diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index a9711cde..9e35ba20 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -260,7 +260,7 @@ public function getDefaultValueConstantName() /** * @inheritDoc */ - public function getName() + public function getName(): string { return (string)$this->parameterNode->var->name; } @@ -312,7 +312,7 @@ public function hasType() /** * @inheritDoc */ - public function isArray() + public function isArray(): bool { $type = $this->parameterNode->type; @@ -322,7 +322,7 @@ public function isArray() /** * @inheritDoc */ - public function isCallable() + public function isCallable(): bool { $type = $this->parameterNode->type; @@ -332,7 +332,7 @@ public function isCallable() /** * @inheritDoc */ - public function isDefaultValueAvailable() + public function isDefaultValueAvailable(): bool { return isset($this->parameterNode->default); } @@ -340,7 +340,7 @@ public function isDefaultValueAvailable() /** * {@inheritDoc} */ - public function isDefaultValueConstant() + public function isDefaultValueConstant(): bool { return $this->isDefaultValueConstant; } @@ -348,7 +348,7 @@ public function isDefaultValueConstant() /** * {@inheritDoc} */ - public function isOptional() + public function isOptional(): bool { return $this->isVariadic() || ($this->isDefaultValueAvailable() && $this->haveSiblingsDefaultValues()); } @@ -356,7 +356,7 @@ public function isOptional() /** * @inheritDoc */ - public function isPassedByReference() + public function isPassedByReference(): bool { return (bool) $this->parameterNode->byRef; } @@ -364,7 +364,7 @@ public function isPassedByReference() /** * @inheritDoc */ - public function isVariadic() + public function isVariadic(): bool { return (bool) $this->parameterNode->variadic; } diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index f5ad7a9c..6f823916 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -174,7 +174,7 @@ public function getModifiers(): int /** * @inheritDoc */ - public function getName() + public function getName(): string { return $this->propertyNode->name->toString(); } @@ -202,7 +202,7 @@ public function getValue($object = null) /** * @inheritDoc */ - public function isDefault() + public function isDefault(): bool { // TRUE if the property was declared at compile-time @@ -212,7 +212,7 @@ public function isDefault() /** * {@inheritDoc} */ - public function isPrivate() + public function isPrivate(): bool { return $this->propertyTypeNode->isPrivate(); } @@ -220,7 +220,7 @@ public function isPrivate() /** * {@inheritDoc} */ - public function isProtected() + public function isProtected(): bool { return $this->propertyTypeNode->isProtected(); } @@ -228,7 +228,7 @@ public function isProtected() /** * {@inheritDoc} */ - public function isPublic() + public function isPublic(): bool { return $this->propertyTypeNode->isPublic(); } @@ -236,7 +236,7 @@ public function isPublic() /** * {@inheritDoc} */ - public function isStatic() + public function isStatic(): bool { return $this->propertyTypeNode->isStatic(); } @@ -244,7 +244,7 @@ public function isStatic() /** * {@inheritDoc} */ - public function setAccessible($accessible) + public function setAccessible($accessible): void { $this->initializeInternalReflection(); @@ -254,7 +254,7 @@ public function setAccessible($accessible) /** * @inheritDoc */ - public function setValue($object, $value = null) + public function setValue($object, $value = null): void { $this->initializeInternalReflection(); diff --git a/src/ReflectionType.php b/src/ReflectionType.php index fd4572de..31f34fee 100644 --- a/src/ReflectionType.php +++ b/src/ReflectionType.php @@ -61,7 +61,7 @@ public function allowsNull() /** * @inheritDoc */ - public function isBuiltin() + public function isBuiltin(): bool { return $this->isBuiltin; } diff --git a/src/Traits/ReflectionClassLikeTrait.php b/src/Traits/ReflectionClassLikeTrait.php index ee92b577..a90bb063 100644 --- a/src/Traits/ReflectionClassLikeTrait.php +++ b/src/Traits/ReflectionClassLikeTrait.php @@ -435,7 +435,7 @@ public function getModifiers(): int /** * {@inheritDoc} */ - public function getName() + public function getName(): string { $namespaceName = $this->namespaceName ? $this->namespaceName . '\\' : ''; @@ -445,7 +445,7 @@ public function getName() /** * {@inheritDoc} */ - public function getNamespaceName() + public function getNamespaceName(): string { return $this->namespaceName; } @@ -705,7 +705,7 @@ public function implementsInterface($interfaceName) /** * {@inheritDoc} */ - public function inNamespace() + public function inNamespace(): bool { return !empty($this->namespaceName); } @@ -713,7 +713,7 @@ public function inNamespace() /** * {@inheritDoc} */ - public function isAbstract() + public function isAbstract(): bool { if ($this->classLikeNode instanceof Class_ && $this->classLikeNode->isAbstract()) { return true; @@ -729,7 +729,7 @@ public function isAbstract() /** * Currently, anonymous classes aren't supported for parsed reflection */ - public function isAnonymous() + public function isAnonymous(): bool { return false; } @@ -737,7 +737,7 @@ public function isAnonymous() /** * {@inheritDoc} */ - public function isCloneable() + public function isCloneable(): bool { if ($this->isInterface() || $this->isTrait() || $this->isAbstract()) { return false; @@ -755,7 +755,7 @@ public function isCloneable() /** * {@inheritDoc} */ - public function isFinal() + public function isFinal(): bool { $isFinal = $this->classLikeNode instanceof Class_ && $this->classLikeNode->isFinal(); From bb410259ba00ad44018905edae8865c56d726e28 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 22:39:42 +0700 Subject: [PATCH 09/38] more return type --- src/ReflectionClassConstant.php | 2 +- src/ReflectionFunction.php | 2 +- src/ReflectionMethod.php | 6 ++-- src/ReflectionParameter.php | 2 +- src/ReflectionProperty.php | 2 +- src/Traits/ReflectionClassLikeTrait.php | 35 +++++++++------------- src/Traits/ReflectionFunctionLikeTrait.php | 15 +++++----- 7 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/ReflectionClassConstant.php b/src/ReflectionClassConstant.php index 0ea30812..2ee11a3c 100644 --- a/src/ReflectionClassConstant.php +++ b/src/ReflectionClassConstant.php @@ -111,7 +111,7 @@ public function __debugInfo(): array /** * @inheritDoc */ - public function getDeclaringClass() + public function getDeclaringClass(): \ReflectionClass { return new ReflectionClass($this->className); } diff --git a/src/ReflectionFunction.php b/src/ReflectionFunction.php index fece905a..9b54f7e5 100644 --- a/src/ReflectionFunction.php +++ b/src/ReflectionFunction.php @@ -67,7 +67,7 @@ public function getNode(): Function_ /** * {@inheritDoc} */ - public function getClosure() + public function getClosure(): \Closure { $this->initializeInternalReflection(); diff --git a/src/ReflectionMethod.php b/src/ReflectionMethod.php index f22fd555..7c897d1f 100644 --- a/src/ReflectionMethod.php +++ b/src/ReflectionMethod.php @@ -138,7 +138,7 @@ public function __toString() /** * {@inheritDoc} */ - public function getClosure($object = null) + public function getClosure($object = null): \Closure { $this->initializeInternalReflection(); @@ -148,7 +148,7 @@ public function getClosure($object = null) /** * {@inheritDoc} */ - public function getDeclaringClass() + public function getDeclaringClass(): \ReflectionClass { return $this->declaringClass ?? new ReflectionClass($this->className); } @@ -184,7 +184,7 @@ public function getModifiers(): int /** * {@inheritDoc} */ - public function getPrototype() + public function getPrototype(): \ReflectionMethod { $parent = $this->getDeclaringClass()->getParentClass(); if (!$parent) { diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 9e35ba20..0e1ab9cb 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -216,7 +216,7 @@ public function getClass() /** * {@inheritDoc} */ - public function getDeclaringClass() + public function getDeclaringClass(): ?\ReflectionClass { if ($this->declaringFunction instanceof \ReflectionMethod) { return $this->declaringFunction->getDeclaringClass(); diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 6f823916..51c8ef4b 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -134,7 +134,7 @@ public function __toString() /** * {@inheritDoc} */ - public function getDeclaringClass() + public function getDeclaringClass(): \ReflectionClass { return new ReflectionClass($this->className); } diff --git a/src/Traits/ReflectionClassLikeTrait.php b/src/Traits/ReflectionClassLikeTrait.php index a90bb063..2bcc9be7 100644 --- a/src/Traits/ReflectionClassLikeTrait.php +++ b/src/Traits/ReflectionClassLikeTrait.php @@ -453,7 +453,7 @@ public function getNamespaceName(): string /** * {@inheritDoc} */ - public function getParentClass() + public function getParentClass(): \ReflectionClass|false { if (!isset($this->parentClass)) { static $extendsField = 'extends'; @@ -479,7 +479,7 @@ public function getParentClass() * * @return ReflectionProperty[] */ - public function getProperties($filter = null) + public function getProperties($filter = null): array { if (!isset($this->properties)) { $directProperties = ReflectionProperty::collectFromClassNode($this->classLikeNode, $this->getName()); @@ -533,7 +533,7 @@ public function getProperty($name) /** * @inheritDoc */ - public function getReflectionConstant($name) + public function getReflectionConstant($name): \ReflectionClassConstant|false { $classConstants = $this->getReflectionConstants(); foreach ($classConstants as $classConstant) { @@ -577,7 +577,7 @@ function (array &$result, \ReflectionClass $instance, $isParent) { /** * {@inheritDoc} */ - public function getShortName() + public function getShortName(): string { return $this->className; } @@ -595,7 +595,7 @@ public function getStartLine(): int * @return array|null an array with new method names in keys and original names (in the format * "TraitName::original") in values. */ - public function getTraitAliases() + public function getTraitAliases(): array { $aliases = []; $traits = $this->getTraits(); @@ -652,7 +652,7 @@ public function getTraits(): array /** * {@inheritDoc} */ - public function hasConstant($name) + public function hasConstant($name): bool { $constants = $this->getConstants(); $hasConstant = isset($constants[$name]) || array_key_exists($name, $constants); @@ -664,7 +664,7 @@ public function hasConstant($name) * {@inheritdoc} * @param string $name */ - public function hasMethod($name) + public function hasMethod($name): bool { $methods = $this->getMethods(); foreach ($methods as $method) { @@ -679,7 +679,7 @@ public function hasMethod($name) /** * {@inheritdoc} */ - public function hasProperty($name) + public function hasProperty($name): bool { $properties = $this->getProperties(); foreach ($properties as $property) { @@ -695,7 +695,7 @@ public function hasProperty($name) * {@inheritDoc} * @param string $interfaceName */ - public function implementsInterface($interfaceName) + public function implementsInterface($interfaceName): bool { $allInterfaces = $this->getInterfaces(); @@ -765,7 +765,7 @@ public function isFinal(): bool /** * {@inheritDoc} */ - public function isInstance($object) + public function isInstance($object): bool { if (!is_object($object)) { throw new RuntimeException(sprintf('Parameter must be an object, "%s" provided.', gettype($object))); @@ -897,10 +897,9 @@ public function getStaticProperties(): array * @param mixed $default A default value to return in case the class does not declare * a static property with the given name * - * @return mixed * @throws ReflectionException If there is no such property and no default value was given */ - public function getStaticPropertyValue($name, $default = null) + public function getStaticPropertyValue($name, $default = null): mixed { $properties = $this->getStaticProperties(); $propertyExists = array_key_exists($name, $properties); @@ -925,10 +924,8 @@ public function getStaticPropertyValue($name, $default = null) * * @param mixed $arg First argument * @param mixed $args Accepts a variable number of arguments which are passed to the class constructor - * - * @return object */ - public function newInstance($arg = null, ...$args) + public function newInstance($arg = null, ...$args): object { $args = array_slice(array_merge([$arg], $args), 0, func_num_args()); $this->initializeInternalReflection(); @@ -942,10 +939,8 @@ public function newInstance($arg = null, ...$args) * @link http://php.net/manual/en/reflectionclass.newinstanceargs.php * * @param array $args The parameters to be passed to the class constructor as an array. - * - * @return object */ - public function newInstanceArgs(array $args = []) + public function newInstanceArgs(array $args = []): ?object { $function = __FUNCTION__; $this->initializeInternalReflection(); @@ -957,10 +952,8 @@ public function newInstanceArgs(array $args = []) * Creates a new class instance without invoking the constructor. * * @link http://php.net/manual/en/reflectionclass.newinstancewithoutconstructor.php - * - * @return object */ - public function newInstanceWithoutConstructor() + public function newInstanceWithoutConstructor(): object { $function = __FUNCTION__; $this->initializeInternalReflection(); diff --git a/src/Traits/ReflectionFunctionLikeTrait.php b/src/Traits/ReflectionFunctionLikeTrait.php index 5387639d..8d0977cd 100644 --- a/src/Traits/ReflectionFunctionLikeTrait.php +++ b/src/Traits/ReflectionFunctionLikeTrait.php @@ -24,6 +24,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use PhpParser\NodeTraverser; +use ReflectionException; use ReflectionExtension; /** @@ -53,7 +54,7 @@ trait ReflectionFunctionLikeTrait /** * {@inheritDoc} */ - public function getClosureScopeClass() + public function getClosureScopeClass(): ?\ReflectionClass { $this->initializeInternalReflection(); @@ -63,7 +64,7 @@ public function getClosureScopeClass() /** * {@inheritDoc} */ - public function getClosureThis() + public function getClosureThis(): ?object { $this->initializeInternalReflection(); @@ -175,11 +176,9 @@ public function getParameters(): array /** * Gets the specified return type of a function * - * @return \ReflectionType - * * @link http://php.net/manual/en/reflectionfunctionabstract.getreturntype.php */ - public function getReturnType() + public function getReturnType(): ?\ReflectionType { $isBuiltin = false; $returnType = $this->functionLikeNode->getReturnType(); @@ -205,13 +204,13 @@ public function getReturnType() /** * {@inheritDoc} */ - public function getShortName() + public function getShortName(): string { if ($this->functionLikeNode instanceof Function_ || $this->functionLikeNode instanceof ClassMethod) { return $this->functionLikeNode->name->toString(); } - return false; + throw new ReflectionException('unable to get short name'); } public function getStartLine(): int @@ -222,7 +221,7 @@ public function getStartLine(): int /** * {@inheritDoc} */ - public function getStaticVariables() + public function getStaticVariables(): array { $nodeTraverser = new NodeTraverser(); $variablesCollector = new StaticVariablesCollector($this); From 8663cc3bdcb1aedb32b10383a7b826770c465e49 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 22:48:57 +0700 Subject: [PATCH 10/38] utilize ReturnTypeWillChange on allow return false --- src/Traits/ReflectionClassLikeTrait.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Traits/ReflectionClassLikeTrait.php b/src/Traits/ReflectionClassLikeTrait.php index 2bcc9be7..a20ce08b 100644 --- a/src/Traits/ReflectionClassLikeTrait.php +++ b/src/Traits/ReflectionClassLikeTrait.php @@ -346,9 +346,9 @@ function (array &$result, \ReflectionClass $instance) { /** * {@inheritdoc} - * @param string $name */ - public function getMethod($name) + #[\ReturnTypeWillChange] + public function getMethod(string $name) { $methods = $this->getMethods(); foreach ($methods as $method) { @@ -518,7 +518,8 @@ function (array &$result, \ReflectionClass $instance, $isParent) { /** * {@inheritdoc} */ - public function getProperty($name) + #[\ReturnTypeWillChange] + public function getProperty(string $name) { $properties = $this->getProperties(); foreach ($properties as $property) { @@ -969,7 +970,7 @@ public function newInstanceWithoutConstructor(): object * @param string $name Property name * @param mixed $value New property value */ - public function setStaticPropertyValue($name, $value) + public function setStaticPropertyValue($name, $value): void { $this->initializeInternalReflection(); From 3cd467da7bd39ab68f4c6828de73c1268a4ee828 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 23:18:43 +0700 Subject: [PATCH 11/38] more return types --- src/ReflectionParameter.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 0e1ab9cb..2c39a7f5 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -132,7 +132,7 @@ public function __debugInfo(): array * * @return string */ - public function __toString() + public function __toString(): string { $parameterType = $this->getType(); $isOptional = $this->isOptional(); @@ -160,7 +160,7 @@ public function __toString() /** * {@inheritDoc} */ - public function allowsNull() + public function allowsNull(): bool { // Enable 7.1 nullable types support if ($this->parameterNode->type instanceof NullableType) { @@ -178,7 +178,7 @@ public function allowsNull() /** * {@inheritDoc} */ - public function canBePassedByValue() + public function canBePassedByValue(): bool { return !$this->isPassedByReference(); } @@ -186,7 +186,7 @@ public function canBePassedByValue() /** * @inheritDoc */ - public function getClass() + public function getClass(): \ReflectionClass { $parameterType = $this->parameterNode->type; if ($parameterType instanceof Name) { @@ -228,7 +228,7 @@ public function getDeclaringClass(): ?\ReflectionClass /** * {@inheritDoc} */ - public function getDeclaringFunction() + public function getDeclaringFunction(): \ReflectionFunction { return $this->declaringFunction; } @@ -302,7 +302,7 @@ public function getType() /** * @inheritDoc */ - public function hasType() + public function hasType(): bool { $hasType = isset($this->parameterNode->type); From 2fb021768d1f3fdbf40d9903da48dbb262685da0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 23:23:50 +0700 Subject: [PATCH 12/38] fix return type --- src/ReflectionParameter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 2c39a7f5..547a005e 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -186,7 +186,7 @@ public function canBePassedByValue(): bool /** * @inheritDoc */ - public function getClass(): \ReflectionClass + public function getClass(): ?\ReflectionClass { $parameterType = $this->parameterNode->type; if ($parameterType instanceof Name) { @@ -228,7 +228,7 @@ public function getDeclaringClass(): ?\ReflectionClass /** * {@inheritDoc} */ - public function getDeclaringFunction(): \ReflectionFunction + public function getDeclaringFunction(): ReflectionFunctionAbstract { return $this->declaringFunction; } From 042b71262d065a7df23338f593109f9579ce7ceb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Jan 2024 23:29:29 +0700 Subject: [PATCH 13/38] more return type --- src/ReflectionParameter.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 547a005e..6a368e04 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -248,7 +248,7 @@ public function getDefaultValue() /** * {@inheritDoc} */ - public function getDefaultValueConstantName() + public function getDefaultValueConstantName(): null|string { if (!$this->isDefaultValueAvailable()) { throw new ReflectionException('Internal error: Failed to retrieve the default value'); @@ -268,7 +268,7 @@ public function getName(): string /** * {@inheritDoc} */ - public function getPosition() + public function getPosition(): int { return $this->parameterIndex; } @@ -276,7 +276,7 @@ public function getPosition() /** * @inheritDoc */ - public function getType() + public function getType(): ?\ReflectionType { $isBuiltin = false; $parameterType = $this->parameterNode->type; @@ -372,10 +372,9 @@ public function isVariadic(): bool /** * Returns if all following parameters have a default value definition. * - * @return bool * @throws ReflectionException If could not fetch declaring function reflection */ - protected function haveSiblingsDefaultValues() + protected function haveSiblingsDefaultValues(): bool { $function = $this->getDeclaringFunction(); if (null === $function) { From 07109335fa51d940c08f47cbb98bb19f111eddc2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 16 Jan 2024 00:06:24 +0700 Subject: [PATCH 14/38] Fix default value display on ReflectionProperty --- src/ReflectionProperty.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 51c8ef4b..9503c88f 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -118,9 +118,16 @@ public function __toString() if ($this->isDefault()) { $this->__initialize(); $defaultValue = $this->getDefaultValue(); - $defaultValueDisplay = is_array($defaultValue) - ? '= ' . $defaultValue - : '= ' . str_replace('\\', '\\', var_export($defaultValue, true)); + + $originalDisplay = parent::__toString(); + + [, $defaultValueFromDisplay] = explode(' = ', $originalDisplay); + + $defaultValueDisplay = '= ' . rtrim($defaultValueFromDisplay, ' ]' . PHP_EOL); + + if (is_array($defaultValue) && $defaultValueDisplay === '= [') { + $defaultValueDisplay .= ']'; + } } return sprintf( From 35fc2a5286f7e6bd9e2e289486e7f68d275d252f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 16 Jan 2024 00:11:15 +0700 Subject: [PATCH 15/38] use str_starts_with() --- src/ReflectionProperty.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 9503c88f..115409cb 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -125,7 +125,7 @@ public function __toString() $defaultValueDisplay = '= ' . rtrim($defaultValueFromDisplay, ' ]' . PHP_EOL); - if (is_array($defaultValue) && $defaultValueDisplay === '= [') { + if (is_array($defaultValue) && str_starts_with($defaultValueDisplay, '= [')) { $defaultValueDisplay .= ']'; } } From 511838f744ed48a3e51cc8897dd3ea558ddda624 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 16 Jan 2024 00:21:33 +0700 Subject: [PATCH 16/38] debugging --- tests/ReflectionParameterTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/ReflectionParameterTest.php b/tests/ReflectionParameterTest.php index 4f7cbef4..cd808bde 100644 --- a/tests/ReflectionParameterTest.php +++ b/tests/ReflectionParameterTest.php @@ -50,6 +50,11 @@ public function testGeneralInfoGetters($fileName) } $expectedValue = $originalRefParameter->$getterName(); $actualValue = $refParameter->$getterName(); + + if ($parameterName === 'arrayParamWithDefault' && $expectedValue === false && $actualValue === true) { + dump($isDefaultValueAvailable); + } + $this->assertSame( $expectedValue, $actualValue, From 34699a2efe28d8ce1c3eb101c61c7c1b56b7eb1e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 16 Jan 2024 02:12:06 +0700 Subject: [PATCH 17/38] use array_shift() to ensure = inside default value included --- src/ReflectionProperty.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 115409cb..494730ac 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -121,7 +121,11 @@ public function __toString() $originalDisplay = parent::__toString(); - [, $defaultValueFromDisplay] = explode(' = ', $originalDisplay); + // @see https://3v4l.org/XToie + $list = explode(' = ', $originalDisplay); + array_shift($list); + + $defaultValueFromDisplay = implode('=', $list); $defaultValueDisplay = '= ' . rtrim($defaultValueFromDisplay, ' ]' . PHP_EOL); From c8658d7fbab20dba1eb8036e551d06ac7bab7588 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 16 Jan 2024 02:42:48 +0700 Subject: [PATCH 18/38] implode fix --- src/ReflectionProperty.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 494730ac..f3dd65da 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -121,11 +121,11 @@ public function __toString() $originalDisplay = parent::__toString(); - // @see https://3v4l.org/XToie + // @see https://3v4l.org/7q1LT $list = explode(' = ', $originalDisplay); array_shift($list); - $defaultValueFromDisplay = implode('=', $list); + $defaultValueFromDisplay = implode(' = ', $list); $defaultValueDisplay = '= ' . rtrim($defaultValueFromDisplay, ' ]' . PHP_EOL); From ec3d9de99c1a91fce0d2307657a695c7b3883651 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 17 Jan 2024 23:19:38 +0700 Subject: [PATCH 19/38] more test --- tests/Stub/FileWithClasses55.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Stub/FileWithClasses55.php b/tests/Stub/FileWithClasses55.php index 2ebe6070..18f6fe39 100644 --- a/tests/Stub/FileWithClasses55.php +++ b/tests/Stub/FileWithClasses55.php @@ -94,7 +94,7 @@ public function noGeneratorFunc() return 10; } - private function testParam($a, $b = null, $d = self::TEST) {} + private function testParam($a, $b = null, $d = self::TEST, $e = M_PI) {} } class ClassWithProperties From 23241227ad76c335fe2457c022241699f6afb4ba Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 17 Jan 2024 23:20:37 +0700 Subject: [PATCH 20/38] more test --- tests/Stub/FileWithClasses55.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Stub/FileWithClasses55.php b/tests/Stub/FileWithClasses55.php index 18f6fe39..f2686e7a 100644 --- a/tests/Stub/FileWithClasses55.php +++ b/tests/Stub/FileWithClasses55.php @@ -94,7 +94,7 @@ public function noGeneratorFunc() return 10; } - private function testParam($a, $b = null, $d = self::TEST, $e = M_PI) {} + private function testParam($a, $b = null, $d = self::TEST, $e = M_PI, $f = \M_PI) {} } class ClassWithProperties From 3be7ab663904f1f04c2f5e87cd15e74f47b0a3a2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 17 Jan 2024 23:57:12 +0700 Subject: [PATCH 21/38] add more test --- tests/Stub/FileWithClasses55.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Stub/FileWithClasses55.php b/tests/Stub/FileWithClasses55.php index f2686e7a..7ca01c56 100644 --- a/tests/Stub/FileWithClasses55.php +++ b/tests/Stub/FileWithClasses55.php @@ -94,7 +94,7 @@ public function noGeneratorFunc() return 10; } - private function testParam($a, $b = null, $d = self::TEST, $e = M_PI, $f = \M_PI) {} + private function testParam($a, $b = null, $d = self::TEST, $e = M_PI, $f = \M_PI, $g = [], $h = false, $i = true) {} } class ClassWithProperties From 40aadce43a12c9be084f6d9bf15b59aaef6e1a08 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 18 Jan 2024 17:55:42 +0700 Subject: [PATCH 22/38] print special class: self, parent, static --- src/ReflectionParameter.php | 8 +++++--- src/ValueResolver/NodeExpressionResolver.php | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 6a368e04..c90fe952 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -140,9 +140,11 @@ public function __toString(): string $defaultValue = ''; if ($hasDefaultValue) { $defaultValue = $this->getDefaultValue(); - $defaultValue = is_array($defaultValue) - ? $defaultValue - : str_replace('\\', '\\', var_export($defaultValue, true)); + if (! $this->isDefaultValueConstant() || ! is_string($defaultValue) || ! str_contains($defaultValue, '::')) { + $defaultValue = is_array($defaultValue) + ? $defaultValue + : str_replace('\\', '\\', var_export($defaultValue, true)); + } } return sprintf( diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index e4781b75..bd757936 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -17,6 +17,7 @@ use Go\ParserReflection\ReflectionFileNamespace; use PhpParser\Node; use PhpParser\Node\Expr; +use PhpParser\Node\Name; use PhpParser\Node\Scalar\DNumber; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\MagicConst\Line; @@ -278,6 +279,11 @@ protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node) $refClass = $this->fetchReflectionClass($classToReflect); $constantName = ($node->name instanceof Expr\Error) ? '' : $node->name->toString(); + if ($node->class instanceof Name && $node->class->isSpecialClassName()) { + $this->isConstant = true; + return $node->class . '::' . $constantName; + } + // special handling of ::class constants if ('class' === $constantName) { return $refClass->getName(); From 1a42011a777a5d7686758fd6c1e1e06dbe093290 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 18 Jan 2024 18:09:06 +0700 Subject: [PATCH 23/38] append --- src/ValueResolver/NodeExpressionResolver.php | 10 +++++----- tests/Stub/FileWithClasses55.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index bd757936..cdb7e8ad 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -279,16 +279,16 @@ protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node) $refClass = $this->fetchReflectionClass($classToReflect); $constantName = ($node->name instanceof Expr\Error) ? '' : $node->name->toString(); - if ($node->class instanceof Name && $node->class->isSpecialClassName()) { - $this->isConstant = true; - return $node->class . '::' . $constantName; - } - // special handling of ::class constants if ('class' === $constantName) { return $refClass->getName(); } + if ($node->class instanceof Name && $node->class->isSpecialClassName()) { + $this->isConstant = true; + return $node->class . '::' . $constantName; + } + $this->isConstant = true; $this->constantName = $classToReflect . '::' . $constantName; diff --git a/tests/Stub/FileWithClasses55.php b/tests/Stub/FileWithClasses55.php index 7ca01c56..b09d1afa 100644 --- a/tests/Stub/FileWithClasses55.php +++ b/tests/Stub/FileWithClasses55.php @@ -94,7 +94,7 @@ public function noGeneratorFunc() return 10; } - private function testParam($a, $b = null, $d = self::TEST, $e = M_PI, $f = \M_PI, $g = [], $h = false, $i = true) {} + private function testParam($a, $b = null, $d = self::TEST, $d2 = self::TEST . '_append', $e = M_PI, $f = \M_PI, $g = [], $h = false, $i = true) {} } class ClassWithProperties From 60194311af8fd1859a1c92a991be45290b055e9c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 18 Jan 2024 21:36:43 +0700 Subject: [PATCH 24/38] use ParentConnectingVisitor --- src/ReflectionEngine.php | 2 ++ src/ValueResolver/NodeExpressionResolver.php | 27 +++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ReflectionEngine.php b/src/ReflectionEngine.php index 645a4c13..92eddfe7 100644 --- a/src/ReflectionEngine.php +++ b/src/ReflectionEngine.php @@ -23,6 +23,7 @@ use PhpParser\Node\Stmt\Property; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; +use PhpParser\NodeVisitor\ParentConnectingVisitor; use PhpParser\Parser; use PhpParser\ParserFactory; @@ -80,6 +81,7 @@ public static function init(LocatorInterface $locator): void self::$traverser = $traverser = new NodeTraverser(); $traverser->addVisitor(new NameResolver()); $traverser->addVisitor(new RootNamespaceNormalizer()); + $traverser->addVisitor(new ParentConnectingVisitor()); self::$locator = $locator; } diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index cdb7e8ad..fbe00bca 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -16,13 +16,16 @@ use Go\ParserReflection\ReflectionException; use Go\ParserReflection\ReflectionFileNamespace; use PhpParser\Node; +use PhpParser\Node\Const_; use PhpParser\Node\Expr; use PhpParser\Node\Name; +use PhpParser\Node\Param; use PhpParser\Node\Scalar\DNumber; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\MagicConst\Line; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Expression; +use PhpParser\Node\Stmt\PropertyProperty; use ReflectionFunctionAbstract; use ReflectionMethod; @@ -284,15 +287,31 @@ protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node) return $refClass->getName(); } - if ($node->class instanceof Name && $node->class->isSpecialClassName()) { - $this->isConstant = true; - return $node->class . '::' . $constantName; + if ($node->class instanceof Name && $node->class->isSpecialClassName() && $this->nodeLevel === 1) { + $parentNode = $node->getAttribute('parent'); + $isFromParam = false; + + while ($parentNode instanceof Node) { + if ($parentNode instanceof Param) { + $isFromParam = true; + break; + } + + $parentNode = $parentNode->getAttribute('parent'); + } + + if ($isFromParam) { + $this->isConstant = true; + $this->constantName = $node->class . '::' . $constantName; + + return $this->constantName; + } } $this->isConstant = true; $this->constantName = $classToReflect . '::' . $constantName; - return $refClass->getConstant($constantName); + return $refClass->getConstant($constantName) ?? $this->constantName; } protected function resolveExprArray(Expr\Array_ $node): array From b5c4e8534178c0a5741a0b32761102f85b80afdf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 00:02:22 +0700 Subject: [PATCH 25/38] add return string on __toString() --- src/ReflectionClassConstant.php | 2 +- src/ReflectionFunction.php | 4 +--- src/ReflectionMethod.php | 4 +--- src/ReflectionProperty.php | 4 +--- src/ReflectionType.php | 2 +- src/Traits/ReflectionClassLikeTrait.php | 4 +--- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/ReflectionClassConstant.php b/src/ReflectionClassConstant.php index 2ee11a3c..4c29b0da 100644 --- a/src/ReflectionClassConstant.php +++ b/src/ReflectionClassConstant.php @@ -190,7 +190,7 @@ public function isPublic(): bool /** * @inheritDoc */ - public function __toString() + public function __toString(): string { # Starting from PHP7.3 gettype returns different names, need to remap them static $typeMap = [ diff --git a/src/ReflectionFunction.php b/src/ReflectionFunction.php index 9b54f7e5..ee0c40c1 100644 --- a/src/ReflectionFunction.php +++ b/src/ReflectionFunction.php @@ -107,10 +107,8 @@ public function isDisabled(): bool /** * Returns textual representation of function - * - * @return string */ - public function __toString() + public function __toString(): string { $paramFormat = ($this->getNumberOfParameters() > 0) ? "\n\n - Parameters [%d] {%s\n }" : ''; $reflectionFormat = "%sFunction [ function %s ] {\n @@ %s %d - %d{$paramFormat}\n}\n"; diff --git a/src/ReflectionMethod.php b/src/ReflectionMethod.php index 7c897d1f..29792e5b 100644 --- a/src/ReflectionMethod.php +++ b/src/ReflectionMethod.php @@ -86,10 +86,8 @@ public function __debugInfo(): array * Returns the string representation of the Reflection method object. * * @link http://php.net/manual/en/reflectionmethod.tostring.php - * - * @return string */ - public function __toString() + public function __toString(): string { // Internally $this->getReturnType() !== null is the same as $this->hasReturnType() $returnType = $this->getReturnType(); diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index f3dd65da..dbd4a010 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -108,10 +108,8 @@ public function __debugInfo(): array /** * Return string representation of this little old property. - * - * @return string */ - public function __toString() + public function __toString(): string { $defaultValueDisplay = ''; diff --git a/src/ReflectionType.php b/src/ReflectionType.php index 31f34fee..77523992 100644 --- a/src/ReflectionType.php +++ b/src/ReflectionType.php @@ -69,7 +69,7 @@ public function isBuiltin(): bool /** * @inheritDoc */ - public function __toString() + public function __toString(): string { return $this->type; } diff --git a/src/Traits/ReflectionClassLikeTrait.php b/src/Traits/ReflectionClassLikeTrait.php index a20ce08b..09ad1cb6 100644 --- a/src/Traits/ReflectionClassLikeTrait.php +++ b/src/Traits/ReflectionClassLikeTrait.php @@ -110,10 +110,8 @@ trait ReflectionClassLikeTrait /** * Returns the string representation of the ReflectionClass object. - * - * @return string */ - public function __toString() + public function __toString(): string { $isObject = $this instanceof ReflectionObject; From 97c71d44fa1b1aaaa75ff590f617b978846e7949 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 00:55:38 +0700 Subject: [PATCH 26/38] Add isParameter flag on detect as default value on parameter --- src/ReflectionEngine.php | 2 -- src/ReflectionParameter.php | 2 +- src/ValueResolver/NodeExpressionResolver.php | 27 ++++++-------------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/ReflectionEngine.php b/src/ReflectionEngine.php index 92eddfe7..645a4c13 100644 --- a/src/ReflectionEngine.php +++ b/src/ReflectionEngine.php @@ -23,7 +23,6 @@ use PhpParser\Node\Stmt\Property; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; -use PhpParser\NodeVisitor\ParentConnectingVisitor; use PhpParser\Parser; use PhpParser\ParserFactory; @@ -81,7 +80,6 @@ public static function init(LocatorInterface $locator): void self::$traverser = $traverser = new NodeTraverser(); $traverser->addVisitor(new NameResolver()); $traverser->addVisitor(new RootNamespaceNormalizer()); - $traverser->addVisitor(new ParentConnectingVisitor()); self::$locator = $locator; } diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index c90fe952..5b8f5bcb 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -99,7 +99,7 @@ public function __construct( $context = $declaringFunction; } - $expressionSolver = new NodeExpressionResolver($context); + $expressionSolver = new NodeExpressionResolver($context, true); $expressionSolver->process($this->parameterNode->default); $this->defaultValue = $expressionSolver->getValue(); $this->isDefaultValueConstant = $expressionSolver->isConstant(); diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index fbe00bca..f2ecb396 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -79,9 +79,12 @@ class NodeExpressionResolver */ private $value; - public function __construct($context) + private bool $isParameter; + + public function __construct($context, bool $isParameter = false) { $this->context = $context; + $this->isParameter = $isParameter; } public function getConstantName(): ?string @@ -287,25 +290,11 @@ protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node) return $refClass->getName(); } - if ($node->class instanceof Name && $node->class->isSpecialClassName() && $this->nodeLevel === 1) { - $parentNode = $node->getAttribute('parent'); - $isFromParam = false; - - while ($parentNode instanceof Node) { - if ($parentNode instanceof Param) { - $isFromParam = true; - break; - } + if ($node->class instanceof Name && $node->class->isSpecialClassName() && $this->isParameter) { + $this->isConstant = true; + $this->constantName = $node->class . '::' . $constantName; - $parentNode = $parentNode->getAttribute('parent'); - } - - if ($isFromParam) { - $this->isConstant = true; - $this->constantName = $node->class . '::' . $constantName; - - return $this->constantName; - } + return $this->constantName; } $this->isConstant = true; From 893893f94ad0aa9a409d8b48d98d6040fee8da11 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 04:37:49 +0700 Subject: [PATCH 27/38] Concat handling --- src/ReflectionParameter.php | 16 ++++++++++++---- src/ValueResolver/NodeExpressionResolver.php | 6 ++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 5b8f5bcb..db22a969 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -13,6 +13,8 @@ use Go\ParserReflection\Traits\InternalPropertiesEmulationTrait; use Go\ParserReflection\ValueResolver\NodeExpressionResolver; +use PhpParser\Node\Expr\BinaryOp\Concat; +use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\NullableType; @@ -140,10 +142,16 @@ public function __toString(): string $defaultValue = ''; if ($hasDefaultValue) { $defaultValue = $this->getDefaultValue(); - if (! $this->isDefaultValueConstant() || ! is_string($defaultValue) || ! str_contains($defaultValue, '::')) { - $defaultValue = is_array($defaultValue) - ? $defaultValue - : str_replace('\\', '\\', var_export($defaultValue, true)); + + if ( + (is_array($defaultValue) || $this->parameterNode->default instanceof Concat || $this->parameterNode->default instanceof ClassConstFetch || is_string($defaultValue)) + && $this->declaringFunction instanceof \ReflectionMethod + ) { + if ($this->parameterNode->default instanceof ClassConstFetch && is_string($defaultValue) && str_contains($defaultValue, '\\')) { + $defaultValue = str_replace('\\', '\\', var_export($defaultValue, true)); + } + } else { + $defaultValue = var_export($defaultValue, true); } } diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index f2ecb396..fdebca4a 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -26,6 +26,7 @@ use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\PropertyProperty; +use PhpParser\PrettyPrinter\Standard; use ReflectionFunctionAbstract; use ReflectionMethod; @@ -382,6 +383,11 @@ protected function resolveExprBinaryOpShiftRight(Expr\BinaryOp\ShiftRight $node) protected function resolveExprBinaryOpConcat(Expr\BinaryOp\Concat $node): string { + if ($this->context instanceof \ReflectionClass && $this->isParameter) { + $printer = new Standard(); + return $printer->prettyPrintExpr($node); + } + return $this->resolve($node->left) . $this->resolve($node->right); } From 3aa23ed3e0a14746164c164315fbf6439e05091f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 04:54:58 +0700 Subject: [PATCH 28/38] cs fix --- src/ReflectionParameter.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index db22a969..3f252156 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -143,9 +143,11 @@ public function __toString(): string if ($hasDefaultValue) { $defaultValue = $this->getDefaultValue(); - if ( - (is_array($defaultValue) || $this->parameterNode->default instanceof Concat || $this->parameterNode->default instanceof ClassConstFetch || is_string($defaultValue)) - && $this->declaringFunction instanceof \ReflectionMethod + if ((is_array($defaultValue) + || $this->parameterNode->default instanceof Concat + || $this->parameterNode->default instanceof ClassConstFetch + || is_string($defaultValue) + ) && $this->declaringFunction instanceof \ReflectionMethod ) { if ($this->parameterNode->default instanceof ClassConstFetch && is_string($defaultValue) && str_contains($defaultValue, '\\')) { $defaultValue = str_replace('\\', '\\', var_export($defaultValue, true)); From 6871bd4e911470c39579d515ee92427b46655606 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 04:56:26 +0700 Subject: [PATCH 29/38] get --- src/ValueResolver/NodeExpressionResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index fdebca4a..aa2a5abf 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -301,7 +301,7 @@ protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node) $this->isConstant = true; $this->constantName = $classToReflect . '::' . $constantName; - return $refClass->getConstant($constantName) ?? $this->constantName; + return $refClass->getConstant($constantName); } protected function resolveExprArray(Expr\Array_ $node): array From 3f62a99dd902b076696c74e7fdd715a81d059066 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 05:07:57 +0700 Subject: [PATCH 30/38] constant name from const fetch --- src/ValueResolver/NodeExpressionResolver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index aa2a5abf..cf7d0f46 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -261,6 +261,10 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node) if ($this->nodeLevel === 1 && !isset(self::$notConstants[$constantName])) { $this->isConstant = true; $this->constantName = $constantName; + + if ($this->isParameter) { + return $this->constantName; + } } return $constantValue; From cbd57206510d234bdbef2167ef71b81bd2d2f437 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 05:09:46 +0700 Subject: [PATCH 31/38] namespaced const fetch --- src/ValueResolver/NodeExpressionResolver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ValueResolver/NodeExpressionResolver.php b/src/ValueResolver/NodeExpressionResolver.php index cf7d0f46..295dc549 100644 --- a/src/ValueResolver/NodeExpressionResolver.php +++ b/src/ValueResolver/NodeExpressionResolver.php @@ -263,6 +263,10 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node) $this->constantName = $constantName; if ($this->isParameter) { + if (isset($namespaceName)) { + return $namespaceName . '\\' . $this->constantName; + } + return $this->constantName; } } From 73aed343a624ccfa3cb315837f2fc415e42afbc8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 05:19:19 +0700 Subject: [PATCH 32/38] fix array --- src/ReflectionParameter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 3f252156..2f0bd1a2 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -157,6 +157,10 @@ public function __toString(): string } } + if (is_array($defaultValue)) { + $defaultValue = '[]'; + } + return sprintf( 'Parameter #%d [ %s %s%s%s$%s%s ]', $this->parameterIndex, From d096c0744fa503178988a482a854a1ad8bf2843a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 05:23:48 +0700 Subject: [PATCH 33/38] use phpunit 10.5.7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3cef9a69..1026c3fd 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "nikic/php-parser": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^10.5.7", "tracy/tracy": "^2.10" }, "extra": { From babcd9e071b39b7998051436f3b1c4b37ba9fbaf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Jan 2024 05:25:48 +0700 Subject: [PATCH 34/38] remove dbeug --- tests/ReflectionParameterTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/ReflectionParameterTest.php b/tests/ReflectionParameterTest.php index cd808bde..3f8d1124 100644 --- a/tests/ReflectionParameterTest.php +++ b/tests/ReflectionParameterTest.php @@ -51,10 +51,6 @@ public function testGeneralInfoGetters($fileName) $expectedValue = $originalRefParameter->$getterName(); $actualValue = $refParameter->$getterName(); - if ($parameterName === 'arrayParamWithDefault' && $expectedValue === false && $actualValue === true) { - dump($isDefaultValueAvailable); - } - $this->assertSame( $expectedValue, $actualValue, From 768537fdc75b480522762ec134514c1fa7ac7b68 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 20 Jan 2024 05:45:44 +0700 Subject: [PATCH 35/38] isDefaultValueAvailable() is false when next parameter is required since php 8.1 --- src/ReflectionParameter.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 2f0bd1a2..4eeda9cf 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -13,6 +13,7 @@ use Go\ParserReflection\Traits\InternalPropertiesEmulationTrait; use Go\ParserReflection\ValueResolver\NodeExpressionResolver; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Identifier; @@ -350,7 +351,24 @@ public function isCallable(): bool */ public function isDefaultValueAvailable(): bool { - return isset($this->parameterNode->default); + if (! isset($this->parameterNode->default)) { + return false; + } + + // start from PHP 8.1, isDefaultValueAvailable() returns false if next parameter is required + // see https://github.com/php/php-src/issues/8090 + $parameters = $this->declaringFunction->getNode()->getParams(); + foreach ($parameters as $key => $parameter) { + if ($key <= $this->parameterIndex) { + continue; + } + + if (! $parameter->default instanceof Expr) { + return false; + } + } + + return true; } /** From b05b6aee51f9874e81443e2bc92568e8f06d1556 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 20 Jan 2024 05:53:33 +0700 Subject: [PATCH 36/38] finally green :tada: --- src/ReflectionParameter.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 4eeda9cf..9b66f077 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -16,6 +16,7 @@ use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\ClassConstFetch; +use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\NullableType; @@ -189,7 +190,12 @@ public function allowsNull(): bool return true; } - return !isset($this->parameterNode->type); + if (!isset($this->parameterNode->type)) { + return true; + } + + return $this->parameterNode->default instanceof ConstFetch + && strtolower($this->parameterNode->default->name->toString()) === 'null'; } /** From b44de115325da4c9ae08da5aa49a32f10fbf55be Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 20 Jan 2024 08:13:03 +0700 Subject: [PATCH 37/38] Final touch: only check next iteration --- src/ReflectionParameter.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index 9b66f077..ea605461 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -364,12 +364,8 @@ public function isDefaultValueAvailable(): bool // start from PHP 8.1, isDefaultValueAvailable() returns false if next parameter is required // see https://github.com/php/php-src/issues/8090 $parameters = $this->declaringFunction->getNode()->getParams(); - foreach ($parameters as $key => $parameter) { - if ($key <= $this->parameterIndex) { - continue; - } - - if (! $parameter->default instanceof Expr) { + for ($key = $this->parameterIndex + 1; $key < count($parameters); ++$key) { + if (! $parameters[$key]->default instanceof Expr) { return false; } } From f0029675afe64480e54f41b6946205d7cd368b08 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 20 Jan 2024 09:00:07 +0700 Subject: [PATCH 38/38] Final touch: fix array param --- src/ReflectionParameter.php | 13 +++++++------ tests/Stub/FileWithClasses55.php | 2 +- tests/Stub/FileWithParameters56.php | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ReflectionParameter.php b/src/ReflectionParameter.php index ea605461..4d70a91f 100644 --- a/src/ReflectionParameter.php +++ b/src/ReflectionParameter.php @@ -14,6 +14,7 @@ use Go\ParserReflection\Traits\InternalPropertiesEmulationTrait; use Go\ParserReflection\ValueResolver\NodeExpressionResolver; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\ConstFetch; @@ -21,6 +22,7 @@ use PhpParser\Node\Name; use PhpParser\Node\NullableType; use PhpParser\Node\Param; +use PhpParser\PrettyPrinter\Standard; use ReflectionFunctionAbstract; use ReflectionParameter as BaseReflectionParameter; @@ -145,8 +147,11 @@ public function __toString(): string if ($hasDefaultValue) { $defaultValue = $this->getDefaultValue(); - if ((is_array($defaultValue) - || $this->parameterNode->default instanceof Concat + if ($this->parameterNode->default instanceof Array_) { + $this->parameterNode->default->setAttribute('kind', Array_::KIND_SHORT); + $printer = new Standard(['shortArraySyntax' => true]); + $defaultValue = $printer->prettyPrintExpr($this->parameterNode->default); + } elseif (($this->parameterNode->default instanceof Concat || $this->parameterNode->default instanceof ClassConstFetch || is_string($defaultValue) ) && $this->declaringFunction instanceof \ReflectionMethod @@ -159,10 +164,6 @@ public function __toString(): string } } - if (is_array($defaultValue)) { - $defaultValue = '[]'; - } - return sprintf( 'Parameter #%d [ %s %s%s%s$%s%s ]', $this->parameterIndex, diff --git a/tests/Stub/FileWithClasses55.php b/tests/Stub/FileWithClasses55.php index b09d1afa..00434296 100644 --- a/tests/Stub/FileWithClasses55.php +++ b/tests/Stub/FileWithClasses55.php @@ -94,7 +94,7 @@ public function noGeneratorFunc() return 10; } - private function testParam($a, $b = null, $d = self::TEST, $d2 = self::TEST . '_append', $e = M_PI, $f = \M_PI, $g = [], $h = false, $i = true) {} + private function testParam($a, $b = null, $d = self::TEST, $d2 = self::TEST . '_append', $e = M_PI, $f = \M_PI, $g = ['test'], $h = false, $i = true, $j = array('yoo')) {} } class ClassWithProperties diff --git a/tests/Stub/FileWithParameters56.php b/tests/Stub/FileWithParameters56.php index 1d1db914..d110af9a 100644 --- a/tests/Stub/FileWithParameters56.php +++ b/tests/Stub/FileWithParameters56.php @@ -12,5 +12,5 @@ function arrayVariadicParameters(array ...$acceptsArrays) {} function callableVariadicParameters(callable ...$acceptsArrays) {} -function constantExpressionAsDefault($value = 0.5 * 2 * 10, $another = __FUNCTION__ . 'test') {} +function constantExpressionAsDefault($value = 0.5 * 2 * 10, $another = __FUNCTION__ . 'test', $anotherOne = ['test'], $anotherTwo = array('yoo')) {} function constantExponentiation($value = 0.5 * 2**2) {}