Skip to content

Commit d69b525

Browse files
committed
bug symfony#38385 [PropertyInfo] Fix failure over array<string,mixed> PhpDoc type (romaricdrigon)
This PR was merged into the 5.2-dev branch. Discussion ---------- [PropertyInfo] Fix failure over array<string,mixed> PhpDoc type | Q | A | ------------- | --- | Branch? | master (issue introduced in master) | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | / | License | MIT | Doc PR | / **Background** Since a few days ago ([this commit](symfony@80e5a7f)), PropertyInfo 5.2 component supports array PhpDoc types, such as `array<string,string>`. While testing SF 5.2 over my project, it was failing over: ```php class SomeDoctrineEntityProxy implements \Doctrine\ORM\Proxy\Proxy { /** * @var array<string, mixed> default values of properties to be lazy loaded, with keys being the property names * * @see \Doctrine\Common\Proxy\Proxy::__getLazyProperties */ public static $lazyPropertiesDefaults = array(); } ``` Upon investigation, it appears `array<string,mixed>` is causing the issue: `mixed` type is not handled. **Expected behavior** PropertyInfo component should not guess anything for `mixed` type (return `NULL`), but it should not throw any exception. **Comment about my fix** I added a test case (`arrayOfMixed`) you can use to reproduce the issue. Since array PhpDoc types were not tested at all, I also added a test case over `array<string,string>`. Commits ------- 590177f [PropertyInfo] Fix failure over array<string,mixed> PhpDoc type
2 parents 085d3ba + 590177f commit d69b525

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ public function typesProvider()
117117
['staticGetter', null, null, null],
118118
['staticSetter', null, null, null],
119119
['emptyVar', null, $this->isPhpDocumentorV5() ? 'This should not be removed.' : null, null],
120+
[
121+
'arrayWithKeys',
122+
$this->isPhpDocumentorV5() ? [
123+
new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_STRING)),
124+
] : null,
125+
null,
126+
null,
127+
],
128+
[
129+
'arrayOfMixed',
130+
$this->isPhpDocumentorV5() ? [
131+
new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_STRING), null),
132+
] : null,
133+
null,
134+
null,
135+
],
120136
];
121137
}
122138

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testGetProperties()
6565
'nestedIterators',
6666
'arrayWithKeys',
6767
'arrayWithKeysAndComplexValue',
68+
'arrayOfMixed',
6869
'foo',
6970
'foo2',
7071
'foo3',
@@ -115,6 +116,7 @@ public function testGetPropertiesWithCustomPrefixes()
115116
'nestedIterators',
116117
'arrayWithKeys',
117118
'arrayWithKeysAndComplexValue',
119+
'arrayOfMixed',
118120
'foo',
119121
'foo2',
120122
'foo3',
@@ -155,6 +157,7 @@ public function testGetPropertiesWithNoPrefixes()
155157
'nestedIterators',
156158
'arrayWithKeys',
157159
'arrayWithKeysAndComplexValue',
160+
'arrayOfMixed',
158161
'foo',
159162
'foo2',
160163
'foo3',

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ class Dummy extends ParentDummy
140140
*/
141141
public $arrayWithKeysAndComplexValue;
142142

143+
/**
144+
* @var array<string,mixed>
145+
*/
146+
public $arrayOfMixed;
147+
143148
public static function getStatic()
144149
{
145150
}

src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private function createType(DocType $type, bool $nullable, string $docType = nul
122122
$collectionKeyType = $this->getTypes($type->getKeyType())[0];
123123

124124
$collectionValueTypes = $this->getTypes($type->getValueType());
125-
if (\count($collectionValueTypes) > 1) {
125+
if (0 === \count($collectionValueTypes) || \count($collectionValueTypes) > 1) {
126126
// the Type class does not support union types yet, so assume that no type was defined
127127
$collectionValueType = null;
128128
} else {

0 commit comments

Comments
 (0)