Skip to content

Commit

Permalink
Reenable PHP7.3 support for 2.x branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Aug 12, 2020
1 parent 8c3374a commit 24ae250
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.coverage.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
},
"require": {
"php": ">=7.1 <7.3.0",
"php": ">=7.1 <7.4.0",
"nikic/php-parser": "^4.0"
},
"require-dev": {
Expand Down
12 changes: 11 additions & 1 deletion src/ReflectionClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions src/ReflectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Go\ParserReflection;

use ReflectionNamedType;
use ReflectionType as BaseReflectionType;

/**
Expand Down Expand Up @@ -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];
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Stub/FileWithClasses71.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 24ae250

Please sign in to comment.