Skip to content

Commit 82ad9cc

Browse files
xabbuhnicolas-grekas
authored andcommitted
do not parse "scalar" as an object
1 parent 23950d1 commit 82ad9cc

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Tests/Extractor/PhpDocExtractorTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,19 @@ public static function propertiesParentTypeProvider(): array
400400

401401
public function testUnknownPseudoType()
402402
{
403-
$this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, 'scalar')], $this->extractor->getTypes(PseudoTypeDummy::class, 'unknownPseudoType'));
403+
$this->assertEquals([
404+
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\\Component\\PropertyInfo\\Tests\\Fixtures\\unknownpseudo')
405+
], $this->extractor->getTypes(PseudoTypeDummy::class, 'unknownPseudoType'));
406+
}
407+
408+
public function testScalarPseudoType()
409+
{
410+
$this->assertEquals([
411+
new Type(Type::BUILTIN_TYPE_BOOL),
412+
new Type(Type::BUILTIN_TYPE_FLOAT),
413+
new Type(Type::BUILTIN_TYPE_INT),
414+
new Type(Type::BUILTIN_TYPE_STRING),
415+
], $this->extractor->getTypes(PseudoTypeDummy::class, 'scalarPseudoType'));
404416
}
405417

406418
public function testGenericInterface()

Tests/Fixtures/PseudoTypeDummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ class PseudoTypeDummy
1616
/**
1717
* @var scalar
1818
*/
19+
public $scalarPseudoType;
20+
21+
/**
22+
* @var unknownpseudo
23+
*/
1924
public $unknownPseudoType;
2025
}

Util/PhpDocTypeHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use phpDocumentor\Reflection\Types\Integer;
2222
use phpDocumentor\Reflection\Types\Null_;
2323
use phpDocumentor\Reflection\Types\Nullable;
24+
use phpDocumentor\Reflection\Types\Scalar;
2425
use phpDocumentor\Reflection\Types\String_;
2526
use Symfony\Component\PropertyInfo\Type;
2627

@@ -56,6 +57,15 @@ public function getTypes(DocType $varType): array
5657
$varType = $varType->getActualType();
5758
}
5859

60+
if ($varType instanceof Scalar) {
61+
return [
62+
new Type(Type::BUILTIN_TYPE_BOOL),
63+
new Type(Type::BUILTIN_TYPE_FLOAT),
64+
new Type(Type::BUILTIN_TYPE_INT),
65+
new Type(Type::BUILTIN_TYPE_STRING),
66+
];
67+
}
68+
5969
if (!$varType instanceof Compound) {
6070
if ($varType instanceof Null_) {
6171
$nullable = true;

0 commit comments

Comments
 (0)