Skip to content

ObjectMetadataResolver::loadObjectManager not supporting Doctrine\ORM\EntityManager #130

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

Closed
hwmatthewa opened this issue May 31, 2020 · 12 comments

Comments

@hwmatthewa
Copy link

In ObjectMetadataResolver.php line 69:

  [TypeError]
  Return value of PHPStan\Type\Doctrine\ObjectMetadataResolver::loadObjectMan
  ager() must be an instance of Doctrine\Common\Persistence\ObjectManager or
  null, instance of Doctrine\ORM\EntityManager returned

object-manager.php:

<?php

use Windy\Utility\DB\DB;

require '../hwinit.php';

return DB::get('MainDB')->getEM();

getEM() method:

abstract public function getEM(): EntityManager;

Returning an EntityManager worked previously. Was something changed to make this incompatible?

@ondrejmirtes
Copy link
Member

My theory is that this is caused by doctrine/persistence 2.0. Please check that the code works if you stay on ^1.1. Thanks.

@hwmatthewa
Copy link
Author

My theory is that this is caused by doctrine/persistence 2.0. Please check that the code works if you stay on ^1.1. Thanks.

This was the correct answer. Thank you.

@ondrejmirtes
Copy link
Member

Just pushed the right solution to dev-master: b43fe3e Can you test that it works with whatever version of doctrine/persistence you want to use? Thanks :)

@mente
Copy link

mente commented Jun 23, 2020

@ondrejmirtes then I would suggest bumping doctrine/orm requirement to 2.7 (the one which introduced doctrine/persistence). We have 2.5 and it doesn't know anything about doctrin/persistence. Thus we can't use latest features of this library :(

@ondrejmirtes
Copy link
Member

@mente Why? What error message are you seeing?

@mente
Copy link

mente commented Jun 23, 2020

Wow, thanks for prompt reply!

TL;DR I can't use objectManagerLoader with doctrine/orm 2.5 due to doctrine/persistence dependency.
I have following versions:

phpstan/phpstan                             0.12.30             PHPStan - PHP Static Analysis Tool
phpstan/phpstan-beberlei-assert             0.12.2              PHPStan beberlei/assert extension
phpstan/phpstan-doctrine                    0.12.17             Doctrine extensions for PHPStan
phpstan/phpstan-symfony                     0.12.6              Symfony Framework extensions and rules for PHPStan
doctrine/annotations                        1.10.2              Docblock Annotations Parser
doctrine/cache                              1.10.0              PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, m...
doctrine/collections                        1.6.4               PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                             v2.8.1              Common Library for Doctrine projects
doctrine/data-fixtures                      v1.3.1              Data Fixtures for all Doctrine Object Managers
doctrine/dbal                               v2.6.3              Database Abstraction Layer
doctrine/doctrine-bundle                    1.10.3              Symfony DoctrineBundle
doctrine/doctrine-cache-bundle              1.3.5               Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle           v2.4.1              Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle         v1.3.2              Symfony DoctrineMigrationsBundle
doctrine/inflector                          1.3.1               Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                       1.3.0               A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                              1.0.2               PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                         v1.5.0              Database Schema migrations using Doctrine DBAL
doctrine/orm                                v2.5.14             Object-Relational-Mapper for PHP
symfony/symfony                             v3.4.41             The Symfony PHP framework

And following tests/object_manager.php:

<?php

require dirname(__DIR__) . '/app/autoload.php';
require dirname(__DIR__) . '/app/AppKernel.php';
require dirname(__DIR__) . '/app/bootstrap.php';
$kernel = new AppKernel('dev', false);
$kernel->boot();

return $kernel->getContainer()->get('doctrine')->getManager();

I get following error:

$ ./bin/phpstan analyse src -c config/phpstan.neon -l 6 --debug
....

In ObjectMetadataResolver.php line 69:

  Type error: Return value of PHPStan\Type\Doctrine\ObjectMetadataResolver::loadObjectManager() must be an instance of Doctrine\Persistence\ObjectManager or null, instance of EntityManager_9a5be93 returned


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

EntityManager_9a5be93 is a proxy wrapper generated by ocramius/proxy-manager.
But the fact is that I have doctrine/orm 2.5.14 with following EntityManager which uses ObjectManager from doctrine/common namespace and not doctrine/persistence

@mente
Copy link

mente commented Jun 23, 2020

if you're willing to support orm 2.5 I can try to find a possible options how to fix it and provide PR

@ondrejmirtes
Copy link
Member

I see, I haven't thought of this. I thought that declaring conflict with doctrine/persistence < 1.3 would be enough. Anyway, you should upgrade, nothing should block you to do so. doctrine/orm 2.5.x haven't been updated for almost 3 years.

@ondrejmirtes
Copy link
Member

Alternatively, you can lock in an older version of phpstan/phpstan and phpstan/phpstan-doctrine - phpstan/phpstan 0.12.25 and phpstan/phpstan-doctrine 0.12.13 work together.

@mente
Copy link

mente commented Jun 23, 2020

Anyway, you should upgrade, nothing should block you to do so. doctrine/orm 2.5.x haven't been updated for almost 3 years.

Sure thing, just wish it was that easy :). Wanted to point out the disrepancy between phpstan dependencies in composer.json and actual runtime expectations

@ondrejmirtes
Copy link
Member

I wasn't aware of this problem, I'll add a conflict :)

@github-actions
Copy link

github-actions bot commented May 1, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants