proget-hq / phpstan-yii2

Yii2 extension for PHPStan
MIT License
52 stars 17 forks source link

Can't use phpstan-yii2 if there are helper functions in config #12

Open ddinchev opened 5 years ago

ddinchev commented 5 years ago

This is my phpstan.neon.

includes:
    - vendor/proget-hq/phpstan-yii2/extension.neon
parameters:
    autoload_files:
        - %rootDir%/../../../common/helpers.php
    yii2:
        config_path: %rootDir%/../../../config/web.php

I use functions defined in %rootDir%/../../../common/helpers.php in my config file, however phpstan-yii2's services seem to be executed before that file is included and it fails with a message that no such function exists.

akondas commented 5 years ago

Thanks for issue, this should be easy to fix, maybe @marmichalski have some time :D

ddinchev commented 5 years ago

Hey @akondas I just tried to use phpstan-yii2 again and hit the same issue. Can you take a look if it's not too much trouble?

akondas commented 5 years ago

Have you try to add it to composer.json to autoload files?:

{
    "autoload": {
        "files": ["src/MyLibrary/functions.php"]
    }
}
senguttuvang commented 4 years ago

Guys, for me, even the core Yii class itself is unable to load. Any idea?

➜  MMR git:(PHP-Static-Code-Analysis) ✗ vendor/bin/phpstan analyse frontend
Note: Using configuration file /vagrant/MMR/phpstan.neon.
PHP Fatal error:  Uncaught Error: Class 'Yii' not found in /vagrant/MMR/frontend/config/web.php:9
Stack trace:
#0 /vagrant/MMR/vendor/proget-hq/phpstan-yii2/src/ServiceMap.php(31): require()
#1 /tmp/phpstan/cache/nette.configurator/Container_36e5b17f91.php(3264): Proget\PHPStan\Yii2\ServiceMap->__construct('/vagrant/MMR/ve...')
#2 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(146): Container_36e5b17f91->createService0169()
#3 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(88): _HumbugBoxa35debbd0202\Nette\DI\Container->createService('0169')
#4 /tmp/phpstan/cache/nette.configurator/Container_36e5b17f91.php(3197): _HumbugBoxa35debbd0202\Nette\DI\Container->getService('0169')
#5 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(146): Container_36e5b17f91->createService0158()
#6 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(88): _HumbugBoxa35debbd0202\Nette\DI\Container- in /vagrant/MMR/frontend/config/web.php on line 9
Fatal error: Uncaught Error: Class 'Yii' not found in /vagrant/MMR/frontend/config/web.php:9
Stack trace:
#0 /vagrant/MMR/vendor/proget-hq/phpstan-yii2/src/ServiceMap.php(31): require()
#1 /tmp/phpstan/cache/nette.configurator/Container_36e5b17f91.php(3264): Proget\PHPStan\Yii2\ServiceMap->__construct('/vagrant/MMR/ve...')
#2 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(146): Container_36e5b17f91->createService0169()
#3 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(88): _HumbugBoxa35debbd0202\Nette\DI\Container->createService('0169')
#4 /tmp/phpstan/cache/nette.configurator/Container_36e5b17f91.php(3197): _HumbugBoxa35debbd0202\Nette\DI\Container->getService('0169')
#5 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(146): Container_36e5b17f91->createService0158()
#6 phar:///vagrant/MMR/vendor/phpstan/phpstan/phpstan/vendor/nette/di/src/DI/Container.php(88): _HumbugBoxa35debbd0202\Nette\DI\Container- in /vagrant/MMR/frontend/config/web.php on line 9
➜  MMR git:(PHP-Static-Code-Analysis) ✗

image