Skip to content

Commit 24ae250

Browse files
committed
Reenable PHP7.3 support for 2.x branch
1 parent 8c3374a commit 24ae250

6 files changed

+34
-10
lines changed

.travis.coverage.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set -x
2-
if [ "$TRAVIS_PHP_VERSION" = '7.1' ] ; then
2+
if [ "$TRAVIS_PHP_VERSION" = '7.3' ] ; then
33
wget https://scrutinizer-ci.com/ocular.phar
44
php ocular.phar code-coverage:upload --format=php-clover ./clover.xml
55
fi

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ language: php
33
php:
44
- 7.1
55
- 7.2
6+
- 7.3
7+
- 7.4
8+
9+
matrix:
10+
allow_failures:
11+
- php: 7.4
612

713
before_script:
814
- composer install

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
},
2424
"require": {
25-
"php": ">=7.1 <7.3.0",
25+
"php": ">=7.1 <7.4.0",
2626
"nikic/php-parser": "^4.0"
2727
},
2828
"require-dev": {

src/ReflectionClassConstant.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,18 @@ public function isPublic()
191191
*/
192192
public function __toString()
193193
{
194+
# Starting from PHP7.3 gettype returns different names, need to remap them
195+
static $typeMap = [
196+
'integer' => 'int',
197+
'boolean' => 'bool',
198+
'double' => 'float',
199+
];
194200
$value = $this->getValue();
195-
$valueType = new ReflectionType(gettype($value), null, true);
201+
$type = gettype($value);
202+
if (PHP_VERSION_ID >= 70300 && isset($typeMap[$type])) {
203+
$type = $typeMap[$type];
204+
}
205+
$valueType = new ReflectionType($type, null, true);
196206

197207
return sprintf(
198208
"Constant [ %s %s %s ] { %s }\n",

src/ReflectionType.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Go\ParserReflection;
1212

13+
use ReflectionNamedType;
1314
use ReflectionType as BaseReflectionType;
1415

1516
/**
@@ -82,11 +83,18 @@ public function __toString()
8283
public static function convertToDisplayType(\ReflectionType $type)
8384
{
8485
static $typeMap = [
85-
'int' => 'integer',
86-
'bool' => 'boolean'
86+
'int' => 'integer',
87+
'bool' => 'boolean',
88+
'double' => 'float',
8789
];
88-
$displayType = (string)$type;
89-
if (isset($typeMap[$displayType])) {
90+
91+
if ($type instanceof ReflectionNamedType) {
92+
$displayType = $type->getName();
93+
} else {
94+
$displayType = (string) $type;
95+
};
96+
97+
if (PHP_VERSION_ID < 70300 && isset($typeMap[$displayType])) {
9098
$displayType = $typeMap[$displayType];
9199
}
92100

tests/Stub/FileWithClasses71.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ class ClassWithPhp71Features
4141
* Description for PUBLIC_CONST_A
4242
*/
4343
const PUBLIC_CONST_A = 1;
44-
44+
4545
/**
4646
* Description for PUBLIC_CONST_B
4747
*/
4848
public const PUBLIC_CONST_B = 2;
49-
49+
5050
/**
5151
* Description for PROTECTED_CONST
5252
*/
5353
protected const PROTECTED_CONST = 3;
54-
54+
5555
/**
5656
* Description for PRIVATE_CONST
5757
*/

0 commit comments

Comments
 (0)