Skip to content

[PropertyInfo] Add meaningful message when phpstan/phpdoc-parser is not installed when using PhpStanExtractor #49207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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