phpstan complains about Doctrine Migrations in Symfony 3.4 with Flex project
Asked Answered
D

2

8

I have a project built on Symfony 3.4 with Flex and I've added phpstan to it for static analysis.

It is complaining about not finding my migration classes:

Class DoctrineMigrations\Version20180831185050 was not found while trying to analyse it - autoloading is probably not configured properly.

Indeed, the files generated by Doctrine Migrations don't fit with the autoloader pattern, but works just fine otherwise.

Is there anything I can do to stop complaining about this?

Dishpan answered 10/9, 2018 at 10:59 Comment(0)
P
9

You can exclude files from analysis

Create phpstan.neon configuration file in the project directory and insert:

parameters:
    excludes_analyse:
        - %currentWorkingDirectory%/src/DoctrineMigrations/*

Every file inside src/DoctrineMigrations directory will be excluded from analysis.

Polyhistor answered 10/9, 2018 at 11:21 Comment(2)
That worked, but with Flex the directory is src/Migrations, without Doctrine in the name.Dishpan
It's better to include with autoload_directories than to exclude, like in @ondřej-mirtes answerDunt
M
9

You can add the directory with the migrations to Composer autoloader, or preferably add it to autoload_directories in phpstan.neon:

parameters:
    autoload_directories:
        - src/Migrations

Check out the Autoloading section in the PHPStan’s documentation for more details.

Mccloskey answered 12/9, 2018 at 19:57 Comment(2)
Hm, not sure about this. If you look at config/packages/doctrine_migrations.yaml the symfony devs made a comment "# namespace is arbitrary but should be different from App\Migrations as migrations classes should NOT be autoloaded".Emulsify
@agoldev While in application context yes, they should not be autoloaded to prevent them from executing by accident, in case of PhpStan you want to run checks on them to see if they are syntactically correct. Therefore you add them to PhpStan onlySorority

© 2022 - 2024 — McMap. All rights reserved.