Skip to content

Commit 1db371f

Browse files
committed
bug symfony#49207 [PropertyInfo] Add meaningful message when phpstan/phpdoc-parser is not installed when using PhpStanExtractor (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Add meaningful message when `phpstan/phpdoc-parser` is not installed when using `PhpStanExtractor` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | _NA_ | License | MIT | Doc PR | _NA_ Folow-up of symfony#49146, as `phpstan/phpdoc-parser` is only defined in `require-dev` of PropertyInfo. Also, I took this opportunity to convert a few data providers to static ones cc `@OskarStark` 👍 Commits ------- 404d6cc [PropertyInfo] Add meaningful message when `phpstan/phpdoc-parser` is not installed when using `PhpStanExtractor`
2 parents e53785b + 404d6cc commit 1db371f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function __construct(array $mutatorPrefixes = null, array $accessorPrefix
6464
throw new \LogicException(sprintf('Unable to use the "%s" class as the "phpdocumentor/type-resolver" package is not installed. Try running composer require "phpdocumentor/type-resolver".', __CLASS__));
6565
}
6666

67+
if (!class_exists(PhpDocParser::class)) {
68+
throw new \LogicException(sprintf('Unable to use the "%s" class as the "phpstan/phpdoc-parser" package is not installed. Try running composer require "phpstan/phpdoc-parser".', __CLASS__));
69+
}
70+
6771
$this->phpStanTypeHelper = new PhpStanTypeHelper();
6872
$this->mutatorPrefixes = $mutatorPrefixes ?? ReflectionExtractor::$defaultMutatorPrefixes;
6973
$this->accessorPrefixes = $accessorPrefixes ?? ReflectionExtractor::$defaultAccessorPrefixes;

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testParamTagTypeIsOmitted()
5353
$this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType'));
5454
}
5555

56-
public function invalidTypesProvider()
56+
public static function invalidTypesProvider()
5757
{
5858
return [
5959
'pub' => ['pub', null, null],
@@ -83,7 +83,7 @@ public function testExtractTypesWithNoPrefixes($property, array $type = null)
8383
$this->assertEquals($type, $noPrefixExtractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
8484
}
8585

86-
public function typesProvider()
86+
public static function typesProvider()
8787
{
8888
return [
8989
['foo', null, 'Short description.', 'Long description.'],
@@ -166,7 +166,7 @@ public function testExtractCollection($property, array $type = null, $shortDescr
166166
$this->testExtract($property, $type, $shortDescription, $longDescription);
167167
}
168168

169-
public function provideCollectionTypes()
169+
public static function provideCollectionTypes()
170170
{
171171
return [
172172
['iteratorCollection', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Iterator', true, null, new Type(Type::BUILTIN_TYPE_STRING))], null, null],
@@ -230,7 +230,7 @@ public function testExtractTypesWithCustomPrefixes($property, array $type = null
230230
$this->assertEquals($type, $customExtractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
231231
}
232232

233-
public function typesWithCustomPrefixesProvider()
233+
public static function typesWithCustomPrefixesProvider()
234234
{
235235
return [
236236
['foo', null, 'Short description.', 'Long description.'],
@@ -271,7 +271,7 @@ public function typesWithCustomPrefixesProvider()
271271
];
272272
}
273273

274-
public function typesWithNoPrefixesProvider()
274+
public static function typesWithNoPrefixesProvider()
275275
{
276276
return [
277277
['foo', null, 'Short description.', 'Long description.'],
@@ -317,7 +317,7 @@ public function testReturnNullOnEmptyDocBlock()
317317
$this->assertNull($this->extractor->getShortDescription(EmptyDocBlock::class, 'foo'));
318318
}
319319

320-
public function dockBlockFallbackTypesProvider()
320+
public static function dockBlockFallbackTypesProvider()
321321
{
322322
return [
323323
'pub' => [
@@ -348,7 +348,7 @@ public function testPropertiesDefinedByTraits(string $property, Type $type)
348348
$this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property));
349349
}
350350

351-
public function propertiesDefinedByTraitsProvider(): array
351+
public static function propertiesDefinedByTraitsProvider(): array
352352
{
353353
return [
354354
['propertyInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
@@ -368,7 +368,7 @@ public function testMethodsDefinedByTraits(string $property, Type $type)
368368
$this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property));
369369
}
370370

371-
public function methodsDefinedByTraitsProvider(): array
371+
public static function methodsDefinedByTraitsProvider(): array
372372
{
373373
return [
374374
['methodInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
@@ -388,7 +388,7 @@ public function testPropertiesStaticType(string $class, string $property, Type $
388388
$this->assertEquals([$type], $this->extractor->getTypes($class, $property));
389389
}
390390

391-
public function propertiesStaticTypeProvider(): array
391+
public static function propertiesStaticTypeProvider(): array
392392
{
393393
return [
394394
[ParentDummy::class, 'propertyTypeStatic', new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)],
@@ -404,7 +404,7 @@ public function testPropertiesParentType(string $class, string $property, ?array
404404
$this->assertEquals($types, $this->extractor->getTypes($class, $property));
405405
}
406406

407-
public function propertiesParentTypeProvider(): array
407+
public static function propertiesParentTypeProvider(): array
408408
{
409409
return [
410410
[ParentDummy::class, 'parentAnnotationNoParent', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'parent')]],
@@ -435,7 +435,7 @@ public function testExtractConstructorTypes($property, array $type = null)
435435
$this->assertEquals($type, $this->extractor->getTypesFromConstructor('Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy', $property));
436436
}
437437

438-
public function constructorTypesProvider()
438+
public static function constructorTypesProvider()
439439
{
440440
return [
441441
['date', [new Type(Type::BUILTIN_TYPE_INT)]],

0 commit comments

Comments
 (0)