From 24ae25076063f1a862da5735c7b9ff426164e89e Mon Sep 17 00:00:00 2001 From: Lisachenko Alexander Date: Thu, 13 Aug 2020 02:43:50 +0300 Subject: [PATCH] Reenable PHP7.3 support for 2.x branch --- .travis.coverage.sh | 2 +- .travis.yml | 6 ++++++ composer.json | 2 +- src/ReflectionClassConstant.php | 12 +++++++++++- src/ReflectionType.php | 16 ++++++++++++---- tests/Stub/FileWithClasses71.php | 6 +++--- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/.travis.coverage.sh b/.travis.coverage.sh index 6b2b2d03..f223f5b9 100755 --- a/.travis.coverage.sh +++ b/.travis.coverage.sh @@ -1,5 +1,5 @@ set -x -if [ "$TRAVIS_PHP_VERSION" = '7.1' ] ; then +if [ "$TRAVIS_PHP_VERSION" = '7.3' ] ; then wget https://scrutinizer-ci.com/ocular.phar php ocular.phar code-coverage:upload --format=php-clover ./clover.xml fi diff --git a/.travis.yml b/.travis.yml index 01905bbb..7ac15d5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,12 @@ language: php php: - 7.1 - 7.2 + - 7.3 + - 7.4 + +matrix: + allow_failures: + - php: 7.4 before_script: - composer install diff --git a/composer.json b/composer.json index 4d0ea3d3..69921f37 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } }, "require": { - "php": ">=7.1 <7.3.0", + "php": ">=7.1 <7.4.0", "nikic/php-parser": "^4.0" }, "require-dev": { diff --git a/src/ReflectionClassConstant.php b/src/ReflectionClassConstant.php index 2c19f626..eefb32b8 100644 --- a/src/ReflectionClassConstant.php +++ b/src/ReflectionClassConstant.php @@ -191,8 +191,18 @@ public function isPublic() */ public function __toString() { + # Starting from PHP7.3 gettype returns different names, need to remap them + static $typeMap = [ + 'integer' => 'int', + 'boolean' => 'bool', + 'double' => 'float', + ]; $value = $this->getValue(); - $valueType = new ReflectionType(gettype($value), null, true); + $type = gettype($value); + if (PHP_VERSION_ID >= 70300 && isset($typeMap[$type])) { + $type = $typeMap[$type]; + } + $valueType = new ReflectionType($type, null, true); return sprintf( "Constant [ %s %s %s ] { %s }\n", diff --git a/src/ReflectionType.php b/src/ReflectionType.php index ed353084..99c0a665 100644 --- a/src/ReflectionType.php +++ b/src/ReflectionType.php @@ -10,6 +10,7 @@ namespace Go\ParserReflection; +use ReflectionNamedType; use ReflectionType as BaseReflectionType; /** @@ -82,11 +83,18 @@ public function __toString() public static function convertToDisplayType(\ReflectionType $type) { static $typeMap = [ - 'int' => 'integer', - 'bool' => 'boolean' + 'int' => 'integer', + 'bool' => 'boolean', + 'double' => 'float', ]; - $displayType = (string)$type; - if (isset($typeMap[$displayType])) { + + if ($type instanceof ReflectionNamedType) { + $displayType = $type->getName(); + } else { + $displayType = (string) $type; + }; + + if (PHP_VERSION_ID < 70300 && isset($typeMap[$displayType])) { $displayType = $typeMap[$displayType]; } diff --git a/tests/Stub/FileWithClasses71.php b/tests/Stub/FileWithClasses71.php index 559ddba3..d55e3f6b 100644 --- a/tests/Stub/FileWithClasses71.php +++ b/tests/Stub/FileWithClasses71.php @@ -41,17 +41,17 @@ class ClassWithPhp71Features * Description for PUBLIC_CONST_A */ const PUBLIC_CONST_A = 1; - + /** * Description for PUBLIC_CONST_B */ public const PUBLIC_CONST_B = 2; - + /** * Description for PROTECTED_CONST */ protected const PROTECTED_CONST = 3; - + /** * Description for PRIVATE_CONST */