Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a2cfd7e

Browse filesBrowse files
committed
bug #45720 [PropertyInfo] strip only leading \ when unknown docType (EmilMassey)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [PropertyInfo] strip only leading `\` when unknown docType | Q | A | ------------- | --- | Branch? | 4.4, 5.4, 6.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44455 (partially) | License | MIT | Doc PR | - Fixes issue in `PhpDocExtractor` when dealing with some pseudo-types (`non-empty-string`, `positive-int`, etc.): ```php class TestClass { /** @var non-empty-string */ public $foo; /** @var positive-int */ public $bar; } $extractor = new \Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor(); $fooType = $extractor->getTypes(TestClass::class, 'foo'); // $builtinType: object, $class: on-empty-string (first character trimmed) $barType = $extractor->getTypes(TestClass::class, 'bar'); // $builtinType: object, $class: ositive-int (first character trimmed) ``` The bug exists in 4.4, 5.4 and 6.0. It may exist in 6.1 as the invalid line is still there, but due to changes made in #44451, above snippet will no longer produce the bug. I was not able to reproduce the error in 6.1, but I suspect there may exist some pseudo-type that is still affected by the bug. I'm not sure if the test I wrote is OK, but it is the only way I could think of to validate my fix. In my opinion (see #44455), unknown pseudo-type should not be mapped to an object, so after the fix handling of pseudo-types is still broken but at least the results are consistent between `PhpStanExtractor` and `PhpDocExtractor`. But I agree with @derrabus (#44455 (comment)) that until there is no way to detect if we are dealing with a pseudo-type, assuming it is a reference to an object is the sanest thing to do. Commits ------- 723cd09 [PropertyInfo] strip only leading `\` when unknown docType
2 parents c1aa7b5 + 723cd09 commit a2cfd7e
Copy full SHA for a2cfd7e

File tree

3 files changed

+18
-1
lines changed
Filter options

3 files changed

+18
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1919
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
2020
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
21+
use Symfony\Component\PropertyInfo\Tests\Fixtures\PseudoTypeDummy;
2122
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
2223
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
2324
use Symfony\Component\PropertyInfo\Type;
@@ -350,6 +351,11 @@ public function propertiesParentTypeProvider(): array
350351
];
351352
}
352353

354+
public function testUnknownPseudoType()
355+
{
356+
$this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, 'scalar')], $this->extractor->getTypes(PseudoTypeDummy::class, 'unknownPseudoType'));
357+
}
358+
353359
protected function isPhpDocumentorV5()
354360
{
355361
if (class_exists(InvalidTag::class)) {
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
4+
5+
class PseudoTypeDummy
6+
{
7+
/**
8+
* @var scalar
9+
*/
10+
public $unknownPseudoType;
11+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ private function getPhpTypeAndClass(string $docType): array
164164
return ['object', $docType];
165165
}
166166

167-
return ['object', substr($docType, 1)];
167+
return ['object', ltrim($docType, '\\')];
168168
}
169169
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.