Skip to content

Commit

Permalink
bug #49207 [PropertyInfo] Add meaningful message when `phpstan/phpdoc…
Browse files Browse the repository at this point in the history
…-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 #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`
  • Loading branch information
fabpot committed Feb 4, 2023
2 parents e53785b + 404d6cc commit 1db371f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public function __construct(array $mutatorPrefixes = null, array $accessorPrefix
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__));
}

if (!class_exists(PhpDocParser::class)) {
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__));
}

$this->phpStanTypeHelper = new PhpStanTypeHelper();
$this->mutatorPrefixes = $mutatorPrefixes ?? ReflectionExtractor::$defaultMutatorPrefixes;
$this->accessorPrefixes = $accessorPrefixes ?? ReflectionExtractor::$defaultAccessorPrefixes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testParamTagTypeIsOmitted()
$this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType'));
}

public function invalidTypesProvider()
public static function invalidTypesProvider()
{
return [
'pub' => ['pub', null, null],
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testExtractTypesWithNoPrefixes($property, array $type = null)
$this->assertEquals($type, $noPrefixExtractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
}

public function typesProvider()
public static function typesProvider()
{
return [
['foo', null, 'Short description.', 'Long description.'],
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testExtractCollection($property, array $type = null, $shortDescr
$this->testExtract($property, $type, $shortDescription, $longDescription);
}

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

public function typesWithCustomPrefixesProvider()
public static function typesWithCustomPrefixesProvider()
{
return [
['foo', null, 'Short description.', 'Long description.'],
Expand Down Expand Up @@ -271,7 +271,7 @@ public function typesWithCustomPrefixesProvider()
];
}

public function typesWithNoPrefixesProvider()
public static function typesWithNoPrefixesProvider()
{
return [
['foo', null, 'Short description.', 'Long description.'],
Expand Down Expand Up @@ -317,7 +317,7 @@ public function testReturnNullOnEmptyDocBlock()
$this->assertNull($this->extractor->getShortDescription(EmptyDocBlock::class, 'foo'));
}

public function dockBlockFallbackTypesProvider()
public static function dockBlockFallbackTypesProvider()
{
return [
'pub' => [
Expand Down Expand Up @@ -348,7 +348,7 @@ public function testPropertiesDefinedByTraits(string $property, Type $type)
$this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property));
}

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

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

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

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

public function constructorTypesProvider()
public static function constructorTypesProvider()
{
return [
['date', [new Type(Type::BUILTIN_TYPE_INT)]],
Expand Down

0 comments on commit 1db371f

Please sign in to comment.