Skip to content

Commit 4a041e9

Browse files
committed
Make ReflectionExtractor compatible with ReflectionType changes in PHP 7.1
1 parent 356a0ac commit 4a041e9

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private function extractFromAccessor($class, $property)
231231
*/
232232
private function extractFromReflectionType(\ReflectionType $reflectionType)
233233
{
234-
$phpTypeOrClass = (string) $reflectionType;
234+
$phpTypeOrClass = method_exists($reflectionType, 'getName') ? $reflectionType->getName() : (string) $reflectionType;
235235
$nullable = $reflectionType->allowsNull();
236236

237237
if ($reflectionType->isBuiltin()) {

src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ public function php7TypesProvider()
9494
);
9595
}
9696

97+
/**
98+
* @dataProvider php71TypesProvider
99+
* @requires PHP 7.1
100+
*/
101+
public function testExtractPhp71Type($property, array $type = null)
102+
{
103+
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php71Dummy', $property, array()));
104+
}
105+
106+
public function php71TypesProvider()
107+
{
108+
return array(
109+
array('foo', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true))),
110+
array('bar', array(new Type(Type::BUILTIN_TYPE_INT, true))),
111+
array('baz', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
112+
array('donotexist', null),
113+
);
114+
}
115+
97116
public function testIsReadable()
98117
{
99118
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'bar', array()));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
/**
15+
* @author Teoh Han Hui <[email protected]>
16+
*/
17+
class Php71Dummy
18+
{
19+
public function getFoo(): ?array
20+
{
21+
}
22+
23+
public function setBar(?int $bar)
24+
{
25+
}
26+
27+
public function addBaz(string $baz)
28+
{
29+
}
30+
}

0 commit comments

Comments
 (0)