phpro / grumphp

A PHP code-quality tool
MIT License
4.14k stars 430 forks source link

PHPStan level configuration #819

Closed duboiss closed 3 years ago

duboiss commented 3 years ago
Q A
Version 0.22.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets

My configuration

# grumphp.yml
grumphp:
    tasks:
        jsonlint: ~
        phpcsfixer: ~
        phplint: ~
        phpstan:
            configuration: './phpstan.neon'
            level: 8
        phpunitbridge: ~
        twigcs:
            path: 'templates'
# phpstan.neon
includes:
    - vendor/phpstan/phpstan-symfony/extension.neon
    - vendor/phpstan/phpstan-symfony/rules.neon

parameters:
  level: 8
  paths:
    - src
  excludes_analyse:
    - src/DataFixtures/*
    - src/Migrations/*
    - tests
  symfony:
      container_xml_path: 'var/cache/dev/App_KernelDevDebugContainer.xml'
  checkGenericClassInNonGenericObjectType: false
  checkMissingIterableValueType: false
  ignoreErrors:
      - '#Property [A-z\\_]+::\$[A-z0-9_]+ has no typehint specified.#'
      - '#Call to an undefined method Symfony\\Component\\HttpFoundation\\Session\\SessionInterface::getFlashBag\(\).#'

Specifying level 8 in grumphp.yml, it works normally (1, he found one error). But without level in grumphp.yml, keeping the one in phpstan.neon, it takes level 0 (2, no error).

screenshot

I really think this is a bug, because, for exemple, excludes_analyse in phpstan.neon works without ignore_patterns in grumphp.yml.

So the problem seems to be that the task doesn't take the level into in phpstan.neon.

danilopolani commented 3 years ago

To me it does not work at all. Even if I specified level: 8 it does not report any error.

File example:

...
/**
   * TravelRepository constructor.
   *
   * @param Model $model
   */
  public function __construct(Travel $model)
  {
    parent::__construct($model);
  }
...

With level: 8 it should report the wrong PHPDoc on * @param Model $model (because the argument received is Travel $model) but it doesn't. Running PHPStan manually works fine and reports the error. My conf:

# grumphp.yml
grumphp:
  git_hook_variables:
    EXEC_GRUMPHP_COMMAND: docker exec my_container_name php
    ENV: {}
  stop_on_failure: true
  ignore_unstaged_changes: false
  fixer:
    enabled: true
    fix_by_default: true
  tasks:
    phpcsfixer:
      allow_risky: true
      verbose: true
      diff: true
    phpstan:
      configuration: './phpstan.neon'
      memory_limit: '2G'
      level: 8
      use_grumphp_paths: true
veewee commented 3 years ago

Hello @DuboisS

Tested it out here. The default configured level inside grumphp is indeed level 0. I will change it to null - which falls back to the configured value in phpstan.neon.

If none of the files provide a level, you will get an understandable error back from phpstan.

@danilopolani

To me it does not work at all.

This doesn't really give me an idea what isn't working for you. I am pretty sure it is not related to the level, since you provided it through the config. Feel free to open up a separate issue with more information so that we can tackle it together!