phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
585 stars 96 forks source link

Crash: Service 'rules.56' (type of PHPStan\Rules\Doctrine\ORM\DqlRule): Service of type PHPStan\Type\Doctrine\ObjectMetadataResolver needed by $objectMetadat aResolver in __construct() not found #51

Closed josefsabl closed 5 years ago

josefsabl commented 5 years ago

Hey, I just tried to enable these rules and get this crash:

In Autowiring.php line 190:

  Service 'rules.56' (type of PHPStan\Rules\Doctrine\ORM\DqlRule): Service of  
   type PHPStan\Type\Doctrine\ObjectMetadataResolver needed by $objectMetadat  
  aResolver in __construct() not found. Did you register it in configuration   
  file?                                                                                                                                                    

analyse [--paths-file PATHS-FILE] [-c|--configuration CONFIGURATION] [-l|--level LEVEL] [--no-progress] [--debug] [-a|--autoload-file AUTOLOAD-FILE] [--error-format ERROR-FORMAT] [--memory-limit MEMORY-LIMIT] [--] [<paths>...]

I have these things in composer.json

"phpstan/phpstan": "0.11.2",
"phpstan/phpstan-doctrine": "0.11.1",
"phpstan/phpstan-mockery": "0.11.0",
"phpstan/phpstan-nette": "0.11.0",
"thecodingmachine/phpstan-safe-rule": "0.1.2"

and dev-master nette.

It should be noted that I don't use ORM but ODM.

ondrejmirtes commented 5 years ago

Hi, can you show me your phpstan.neon?

On Wed, 13 Feb 2019 at 17:36, josefsabl notifications@github.com wrote:

Hey, I just tried to enable these rules and get this crash:

In Autowiring.php line 190:

Service 'rules.56' (type of PHPStan\Rules\Doctrine\ORM\DqlRule): Service of type PHPStan\Type\Doctrine\ObjectMetadataResolver needed by $objectMetadat aResolver in __construct() not found. Did you register it in configuration file?

analyse [--paths-file PATHS-FILE] [-c|--configuration CONFIGURATION] [-l|--level LEVEL] [--no-progress] [--debug] [-a|--autoload-file AUTOLOAD-FILE] [--error-format ERROR-FORMAT] [--memory-limit MEMORY-LIMIT] [--] [...]

I have these things in composer.json

"phpstan/phpstan": "0.11.2", "phpstan/phpstan-doctrine": "0.11.1", "phpstan/phpstan-mockery": "0.11.0", "phpstan/phpstan-nette": "0.11.0", "thecodingmachine/phpstan-safe-rule": "0.1.2"

and dev-master nette.

It should be noted that I don't use ORM but ODM.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/phpstan/phpstan-doctrine/issues/51, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuNT2JBlRzPdmOHIdt0OBSlnZ-W8Pks5vND8TgaJpZM4a5zGl .

--

Ondřej Mirtes

ondrejmirtes commented 5 years ago

I suspect you included only rules.neon but not extension.neon. Please follow the README how to use the extension.

josefsabl commented 5 years ago

Correct, thank you! Silly me not RTFM, sorry :-/

But now I get:

Internal error: Class Doctrine\ORM\EntityRepository does not exist
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new

Obviously, because I don use ORM at all.

ondrejmirtes commented 5 years ago

Can you show the stack trace as PHPStan recommmends?

What does it mean that you don’t use the ORM? Just ODM?

On Mon, 18 Feb 2019 at 12:14, josefsabl notifications@github.com wrote:

Correct, thank you! Silly me not RTFM, sorry :-/

But now I get:

Internal error: Class Doctrine\ORM\EntityRepository does not exist Run PHPStan with --debug option and post the stack trace to: https://github.com/phpstan/phpstan/issues/new

Obviously, because I don use ORM at all.

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/phpstan/phpstan-doctrine/issues/51#issuecomment-464691665, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuGPX0iIS0rCc1KhsfJGQ4mqgl2Ziks5vOosBgaJpZM4a5zGl .

--

Ondřej Mirtes

josefsabl commented 5 years ago

Can you show the stack trace as PHPStan recommmends?

Fatal error: Uncaught ReflectionException: Class Doctrine\ORM\EntityRepository does not exist in D:\projects\agfin\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php:334
Stack trace:
#0 D:\projects\agfin\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php(334): ReflectionClass->isSubclassOf('Doctrine\\ORM\\En...')
#1 D:\projects\agfin\vendor\phpstan\phpstan-doctrine\src\Reflection\Doctrine\EntityRepositoryClassReflectionExtension.php(14): PHPStan\Reflection\ClassReflection->isSubclassOf('Doctrine\\ORM\\En...')
#2 D:\projects\agfin\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php(196): PHPStan\Reflection\Doctrine\EntityRepositoryClassReflectionExtension->hasMethod(Object(PHPStan\Reflection\ClassReflection), 'startup')
#3 D:\projects\agfin\vendor\phpstan\phpstan\src\Rules\Methods\MethodSignatureRule.php(134): PHPStan\Reflection\ClassReflection->hasMethod('startup')
#4 *****\vendor\phpstan\phpstan\src\Rules\Methods\MethodSignatureRule.php(67): PHPStan\Rules\Methods\MethodSignatureRule->colle in *****\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php on line 334
PHP Fatal error:  Uncaught ReflectionException: Class Doctrine\ORM\EntityRepository does not exist in *****\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php:334
Stack trace:
#0 *****\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php(334): ReflectionClass->isSubclassOf('Doctrine\\ORM\\En...')
#1 *****\vendor\phpstan\phpstan-doctrine\src\Reflection\Doctrine\EntityRepositoryClassReflectionExtension.php(14): PHPStan\Reflection\ClassReflection->isSubclassOf('Doctrine\\ORM\\En...')
#2 *****\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php(196): PHPStan\Reflection\Doctrine\EntityRepositoryClassReflectionExtension->hasMethod(Object(PHPStan\Reflection\ClassReflection), 'startup')
#3 *****\vendor\phpstan\phpstan\src\Rules\Methods\MethodSignatureRule.php(134): PHPStan\Reflection\ClassReflection->hasMethod('startup')
#4 *****\vendor\phpstan\phpstan\src\Rules\Methods\MethodSignatureRule.php(67): PHPStan\Rules\Methods\MethodSignatureRule->colle in *****\vendor\phpstan\phpstan\src\Reflection\ClassReflection.php on line 334

Process finished with exit code 255

What does it mean that you don’t use the ORM? Just ODM?

Well, I don't have Doctrine\ORM installed, simple as that :-) We use Doctrine\ODM since our database is MongoDB.

And as the documentation states that this "Also supports Doctrine ODM." I thought I could use these rules to improve static analysis somehow and save some /* @var / annotations.

This is all I have in my composer regarding Doctrine

    "doctrine/annotations": "1.6.0",
    "doctrine/common": "2.10.0",
    "doctrine/mongodb-odm": "2.0.0-beta1",
github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.