From 49917cd4341be4e3e8a908c20a86277e7be3bb73 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 21 Oct 2020 15:12:04 +0200 Subject: [PATCH 1/8] Tests pass on PHP 7.4 Signed-off-by: Filippo Tessarotto --- .travis.yml | 18 ++++++------------ composer.json | 14 +++++++------- phpunit.xml.dist | 2 +- test/Generator/ParameterGeneratorTest.php | 4 ++-- test/Generator/PropertyGeneratorTest.php | 8 ++++---- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index c17820b2..4bafca3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,30 +13,24 @@ env: matrix: fast_finish: true include: - - php: 7.1 + - php: 7.3 env: - DEPS=lowest - - php: 7.1 + - php: 7.3 env: - DEPS=latest - CS_CHECK=true - TEST_COVERAGE=true - - php: 7.2 - env: - - DEPS=lowest - - php: 7.2 - env: - - DEPS=latest - - php: 7.3 + - php: 7.4 env: - DEPS=lowest - - php: 7.3 + - php: 7.4 env: - DEPS=latest - - php: 7.4 + - php: nightly env: - DEPS=lowest - - php: 7.4 + - php: nightly env: - DEPS=latest diff --git a/composer.json b/composer.json index 1ca6563e..e7ed93b8 100644 --- a/composer.json +++ b/composer.json @@ -21,16 +21,16 @@ "extra": { }, "require": { - "php": "^7.1", - "laminas/laminas-eventmanager": "^2.6 || ^3.0", - "laminas/laminas-zendframework-bridge": "^1.0" + "php": "^7.3 || ~8.0.0", + "laminas/laminas-eventmanager": "^2.6 || ^3.3", + "laminas/laminas-zendframework-bridge": "^1.1" }, "require-dev": { "ext-phar": "*", - "doctrine/annotations": "^1.7", - "laminas/laminas-coding-standard": "^1.0", - "laminas/laminas-stdlib": "^2.7 || ^3.0", - "phpunit/phpunit": "^7.5.16 || ^8.4" + "doctrine/annotations": "^1.10.4", + "laminas/laminas-coding-standard": "^1.0.0", + "laminas/laminas-stdlib": "^2.7.7 || ^3.3.0", + "phpunit/phpunit": "^9.4.2" }, "conflict": { "phpspec/prophecy": "<1.9.0" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 375eeb0a..94730953 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,6 +18,6 @@ - + diff --git a/test/Generator/ParameterGeneratorTest.php b/test/Generator/ParameterGeneratorTest.php index 2292d248..e3ff3ae5 100644 --- a/test/Generator/ParameterGeneratorTest.php +++ b/test/Generator/ParameterGeneratorTest.php @@ -210,7 +210,7 @@ public function testCreateFromArray() $parameterGenerator = ParameterGenerator::fromArray([ 'name' => 'SampleParameter', 'type' => 'int', - 'defaultvalue' => 'foo', + 'defaultvalue' => 'default-foo', 'passedbyreference' => false, 'position' => 1, 'sourcedirty' => false, @@ -227,7 +227,7 @@ public function testCreateFromArray() self::assertFalse($parameterGenerator->isSourceDirty()); self::assertEquals('foo', $parameterGenerator->getSourceContent()); self::assertEquals('-', $parameterGenerator->getIndentation()); - self::assertAttributeEquals(true, 'omitDefaultValue', $parameterGenerator); + self::assertStringNotContainsString('default-foo', $parameterGenerator->generate()); } /** diff --git a/test/Generator/PropertyGeneratorTest.php b/test/Generator/PropertyGeneratorTest.php index 72728121..724e47ad 100644 --- a/test/Generator/PropertyGeneratorTest.php +++ b/test/Generator/PropertyGeneratorTest.php @@ -240,8 +240,8 @@ public function testCreateFromArray() : void { $propertyGenerator = PropertyGenerator::fromArray([ 'name' => 'SampleProperty', - 'const' => true, - 'defaultvalue' => 'foo', + 'const' => false, + 'defaultvalue' => 'default-foo', 'docblock' => [ 'shortdescription' => 'foo', ], @@ -253,14 +253,14 @@ public function testCreateFromArray() : void ]); self::assertEquals('SampleProperty', $propertyGenerator->getName()); - self::assertTrue($propertyGenerator->isConst()); + self::assertFalse($propertyGenerator->isConst()); self::assertInstanceOf(ValueGenerator::class, $propertyGenerator->getDefaultValue()); self::assertInstanceOf(DocBlockGenerator::class, $propertyGenerator->getDocBlock()); self::assertTrue($propertyGenerator->isAbstract()); self::assertTrue($propertyGenerator->isFinal()); self::assertTrue($propertyGenerator->isStatic()); self::assertEquals(PropertyGenerator::VISIBILITY_PROTECTED, $propertyGenerator->getVisibility()); - self::assertAttributeEquals(true, 'omitDefaultValue', $propertyGenerator); + self::assertStringNotContainsString('default-foo', $propertyGenerator->generate()); } /** From 4be18f6f654ab7f0337024c8dd54b913b88abacc Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 21 Oct 2020 15:14:21 +0200 Subject: [PATCH 2/8] Migrate PHPUnit config Signed-off-by: Filippo Tessarotto --- phpunit.xml.dist | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 94730953..f2fa1800 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,21 +3,19 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true"> - - - ./test - - - - - - ./src - - - - - - - + + From 426452b9947fd3270355290b2974e913414af984 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 21 Oct 2020 16:24:22 +0200 Subject: [PATCH 3/8] Tests pass o n PHP 8.0 Signed-off-by: Filippo Tessarotto --- src/Reflection/ParameterReflection.php | 20 +++++++------------- src/Scanner/ClassScanner.php | 4 +++- src/Scanner/MethodScanner.php | 2 ++ src/Scanner/ParameterScanner.php | 10 +++++++++- src/Scanner/TokenArrayScanner.php | 14 ++++++++++++-- test/Generator/TypeGeneratorTest.php | 4 ++-- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/Reflection/ParameterReflection.php b/src/Reflection/ParameterReflection.php index d9a80822..891973ef 100644 --- a/src/Reflection/ParameterReflection.php +++ b/src/Reflection/ParameterReflection.php @@ -40,13 +40,13 @@ public function getDeclaringClass() */ public function getClass() { - $phpReflection = parent::getClass(); - if ($phpReflection === null) { + $phpReflectionType = parent::getType(); + if ($phpReflectionType === null) { return null; } - $laminasReflection = new ClassReflection($phpReflection->getName()); - unset($phpReflection); + $laminasReflection = new ClassReflection($phpReflectionType->getName()); + unset($phpReflectionType); return $laminasReflection; } @@ -77,20 +77,14 @@ public function getDeclaringFunction() public function detectType() { if (method_exists($this, 'getType') - && ($type = $this->getType()) + && null !== ($type = $this->getType()) && $type->isBuiltin() ) { return $type->getName(); } - // can be dropped when dropping PHP7 support: - if ($this->isArray()) { - return 'array'; - } - - // can be dropped when dropping PHP7 support: - if ($this->isCallable()) { - return 'callable'; + if (null !== $type && $type->getName() === 'self') { + return $this->getDeclaringClass()->getName(); } if (($class = $this->getClass()) instanceof \ReflectionClass) { diff --git a/src/Scanner/ClassScanner.php b/src/Scanner/ClassScanner.php index 60c3152f..6d5f675e 100644 --- a/src/Scanner/ClassScanner.php +++ b/src/Scanner/ClassScanner.php @@ -999,6 +999,8 @@ protected function scan() case T_NS_SEPARATOR: case T_STRING: + case T_NAME_FULLY_QUALIFIED: + case T_NAME_QUALIFIED: switch ($classContext) { case T_EXTENDS: if ($this->isInterface) { @@ -1160,7 +1162,7 @@ protected function scan() if ($tokenType !== null) { // use context if (false === $useAliasContext) { - if ($tokenType == T_NS_SEPARATOR || $tokenType == T_STRING) { + if ($tokenType == T_NS_SEPARATOR || $tokenType == T_STRING || $tokenType == T_NAME_FULLY_QUALIFIED) { $infos[$infoIndex]['use_statements'][$useStatementIndex] .= $tokenContent; } } else { diff --git a/src/Scanner/MethodScanner.php b/src/Scanner/MethodScanner.php index e69eb91b..f6e9d540 100644 --- a/src/Scanner/MethodScanner.php +++ b/src/Scanner/MethodScanner.php @@ -538,6 +538,8 @@ protected function scan() case T_VARIABLE: case T_STRING: + case T_NAME_QUALIFIED: + case T_NAME_FULLY_QUALIFIED: if ($tokenType === T_STRING && $parentCount === 0) { $this->name = $tokenContent; } diff --git a/src/Scanner/ParameterScanner.php b/src/Scanner/ParameterScanner.php index c87c339e..51961939 100644 --- a/src/Scanner/ParameterScanner.php +++ b/src/Scanner/ParameterScanner.php @@ -190,7 +190,15 @@ protected function scan() goto SCANNER_CONTINUE; } } else { - if ($this->name === null && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR)) { + if ( + $this->name === null + && ( + $token[0] === T_STRING + || $token[0] === T_NS_SEPARATOR + || $token[0] === T_NAME_QUALIFIED + || $token[0] === T_NAME_FULLY_QUALIFIED + ) + ) { $this->class .= $token[1]; goto SCANNER_CONTINUE; } diff --git a/src/Scanner/TokenArrayScanner.php b/src/Scanner/TokenArrayScanner.php index 710f8329..7050b0b5 100644 --- a/src/Scanner/TokenArrayScanner.php +++ b/src/Scanner/TokenArrayScanner.php @@ -426,7 +426,12 @@ protected function scan() goto SCANNER_NAMESPACE_CONTINUE; } - if ($tokenType === T_NS_SEPARATOR || $tokenType === T_STRING) { + if ( + $tokenType === T_NS_SEPARATOR + || $tokenType === T_STRING + || $tokenType === T_NAME_QUALIFIED + || $tokenType === T_NAME_FULLY_QUALIFIED + ) { $infos[$infoIndex]['namespace'] .= $tokenContent; } @@ -491,7 +496,12 @@ protected function scan() goto SCANNER_USE_CONTINUE; } - if ($tokenType == T_NS_SEPARATOR || $tokenType == T_STRING) { + if ( + $tokenType == T_NS_SEPARATOR + || $tokenType == T_STRING + || $tokenType == T_NAME_QUALIFIED + || $tokenType == T_NAME_FULLY_QUALIFIED + ) { if ($useAsContext == false) { $infos[$infoIndex]['statements'][$useStatementIndex]['use'] .= $tokenContent; } else { diff --git a/test/Generator/TypeGeneratorTest.php b/test/Generator/TypeGeneratorTest.php index 671dc7ac..d35fd02c 100644 --- a/test/Generator/TypeGeneratorTest.php +++ b/test/Generator/TypeGeneratorTest.php @@ -178,7 +178,7 @@ public function validType() ]; return array_combine( - array_map('reset', $valid), + array_map('current', $valid), $valid ); } @@ -253,7 +253,7 @@ public function invalidType() ]; return array_combine( - array_map('reset', $invalid), + array_map('current', $invalid), $invalid ); } From 62efbb44f089cb46a548069e99f1b87e3593c52e Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Thu, 22 Oct 2020 07:41:55 +0200 Subject: [PATCH 4/8] Ensure PHP BC Signed-off-by: Filippo Tessarotto --- src/Scanner/ClassScanner.php | 6 +++++- src/Scanner/ParameterScanner.php | 3 +-- src/Scanner/TokenArrayScanner.php | 14 ++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Scanner/ClassScanner.php b/src/Scanner/ClassScanner.php index 6d5f675e..72b49dd0 100644 --- a/src/Scanner/ClassScanner.php +++ b/src/Scanner/ClassScanner.php @@ -1162,7 +1162,11 @@ protected function scan() if ($tokenType !== null) { // use context if (false === $useAliasContext) { - if ($tokenType == T_NS_SEPARATOR || $tokenType == T_STRING || $tokenType == T_NAME_FULLY_QUALIFIED) { + if ($tokenType == T_NS_SEPARATOR + || $tokenType == T_STRING + || $tokenType == T_NAME_QUALIFIED + || $tokenType == T_NAME_FULLY_QUALIFIED + ) { $infos[$infoIndex]['use_statements'][$useStatementIndex] .= $tokenContent; } } else { diff --git a/src/Scanner/ParameterScanner.php b/src/Scanner/ParameterScanner.php index 51961939..0aa3df52 100644 --- a/src/Scanner/ParameterScanner.php +++ b/src/Scanner/ParameterScanner.php @@ -190,8 +190,7 @@ protected function scan() goto SCANNER_CONTINUE; } } else { - if ( - $this->name === null + if ($this->name === null && ( $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR diff --git a/src/Scanner/TokenArrayScanner.php b/src/Scanner/TokenArrayScanner.php index 7050b0b5..f2368dfa 100644 --- a/src/Scanner/TokenArrayScanner.php +++ b/src/Scanner/TokenArrayScanner.php @@ -380,6 +380,14 @@ protected function scan() return $infoIndex; }; + // ensure php backwards compatibility + if (! defined('T_NAME_QUALIFIED')) { + define('T_NAME_QUALIFIED', 24000); + } + if (! defined('T_NAME_FULLY_QUALIFIED')) { + define('T_NAME_FULLY_QUALIFIED', 24000); + } + /** * START FINITE STATE MACHINE FOR SCANNING TOKENS */ @@ -426,8 +434,7 @@ protected function scan() goto SCANNER_NAMESPACE_CONTINUE; } - if ( - $tokenType === T_NS_SEPARATOR + if ($tokenType === T_NS_SEPARATOR || $tokenType === T_STRING || $tokenType === T_NAME_QUALIFIED || $tokenType === T_NAME_FULLY_QUALIFIED @@ -496,8 +503,7 @@ protected function scan() goto SCANNER_USE_CONTINUE; } - if ( - $tokenType == T_NS_SEPARATOR + if ($tokenType == T_NS_SEPARATOR || $tokenType == T_STRING || $tokenType == T_NAME_QUALIFIED || $tokenType == T_NAME_FULLY_QUALIFIED From 3278b0494f74303cfacf667d7329416723703bb5 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Thu, 22 Oct 2020 07:51:15 +0200 Subject: [PATCH 5/8] Each token const must have different value Signed-off-by: Filippo Tessarotto --- src/Scanner/TokenArrayScanner.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Scanner/TokenArrayScanner.php b/src/Scanner/TokenArrayScanner.php index f2368dfa..fce02c53 100644 --- a/src/Scanner/TokenArrayScanner.php +++ b/src/Scanner/TokenArrayScanner.php @@ -382,10 +382,10 @@ protected function scan() // ensure php backwards compatibility if (! defined('T_NAME_QUALIFIED')) { - define('T_NAME_QUALIFIED', 24000); + define('T_NAME_QUALIFIED', 24001); } if (! defined('T_NAME_FULLY_QUALIFIED')) { - define('T_NAME_FULLY_QUALIFIED', 24000); + define('T_NAME_FULLY_QUALIFIED', 24002); } /** From 6bc541bba1afb2b8f21918b5bb7d963b2662607f Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 2 Nov 2020 08:23:42 +0100 Subject: [PATCH 6/8] Drop support for laminas-eventmanagar < 3.3 since it doesn't support PHP 8.0 Signed-off-by: Filippo Tessarotto --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e7ed93b8..6a480f9b 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "require": { "php": "^7.3 || ~8.0.0", - "laminas/laminas-eventmanager": "^2.6 || ^3.3", + "laminas/laminas-eventmanager": "^3.3", "laminas/laminas-zendframework-bridge": "^1.1" }, "require-dev": { From 95434716b966c2ba2f72569cc31f6f64bc2644fb Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 4 Nov 2020 08:36:42 +0100 Subject: [PATCH 7/8] Drop laminas-stdlib < 3.3 Signed-off-by: Filippo Tessarotto --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6a480f9b..cd9dd0cd 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "ext-phar": "*", "doctrine/annotations": "^1.10.4", "laminas/laminas-coding-standard": "^1.0.0", - "laminas/laminas-stdlib": "^2.7.7 || ^3.3.0", + "laminas/laminas-stdlib": "^3.3.0", "phpunit/phpunit": "^9.4.2" }, "conflict": { From e3a1c6abf6ce1757cc8599c1ca3c369c8ba59096 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 11 Nov 2020 15:53:13 -0600 Subject: [PATCH 8/8] docs: adds CHANGELOG entry for #47 Signed-off-by: Matthew Weier O'Phinney --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ac0a73..3464bff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file, in reverse ### Added -- Nothing. +- [#47](https://github.com/laminas/laminas-code/pull/47) adds support for PHP 8. NOTE: this simply means the code runs on PHP 8, not that it can generate code specific to PHP 8. ### Changed