phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
MIT License
595 stars 46 forks source link

errors even with allRules: false #185

Closed gemal closed 2 years ago

gemal commented 2 years ago

I just updated to strict v1.4.0 and I added:

includes:
    - vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
    strictRules:
        allRules: false

but now I'm getting this:

Variable property access on $this(App\Controller\AppController).

is this correct? I thought that allRules: false disabled all strict rules

ondrejmirtes commented 2 years ago

Can you please post the code sample that reports this?

/cc @MartinMystikJonas

gemal commented 2 years ago

$this->{$model}->localeDetails['Country'] = $country['Country'];

doesn't allRules: false disable all the strict rules?

ondrejmirtes commented 2 years ago

Yeah, it should, there's gonna be some misconfiguration that should be obvious by looking at rules.neon.

MartinMystikJonas commented 2 years ago

I will check it

gemal commented 2 years ago

perhaps I dont understand the documentation I used to have this in the phpstan.neon

services:
    -
        class: PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule
        tags:
            - phpstan.rules.rule

then I updated strict and deleted it and replaced it with:

includes:
    - vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
    strictRules:
        allRules: false

and now all kind of errors

ondrejmirtes commented 2 years ago

This is the problem: https://github.com/phpstan/phpstan-strict-rules/blob/6f0133dae1ed2d5fc674ad8324441c563720a0d3/rules.neon#L133-L134

Besides allRules: false you should also check the additional parameters (that are off by default in PHPStan core but strict-rules enable them too): https://github.com/phpstan/phpstan-strict-rules/blob/6f0133dae1ed2d5fc674ad8324441c563720a0d3/rules.neon#L2-L14

MartinMystikJonas commented 2 years ago

Yeah I found it too. I am already working on PR with fix.

MartinMystikJonas commented 2 years ago

Should be fixed by PR #186

gemal commented 2 years ago

I tried to use 1.4.2 and even with allRules: false I get:

  153    PHPDoc type array of property App\Controller\AppController::$helpers is not the same as PHPDoc type mixed of overridden property
         Controller::$helpers.
         💡 You can fix 3rd party PHPDoc types with stub files:
            https://phpstan.org/user-guide/stub-files
            This error can be turned off by setting
            reportMaybesInPropertyPhpDocTypes: false in your ../phpstan.neon.

Parameter #2 $status (int) of method App\Controller\AppController::redirect() should be contravariant with parameter $status (array|int|string|null)
         of method Controller::redirect()

first one fixed by setting reportMaybesInPropertyPhpDocTypes:false but the other remain

MartinMystikJonas commented 2 years ago

@gemal That could be probably fixed by reportMaybesInMethodSignatures: false but I am not sure without code example.

MartinMystikJonas commented 2 years ago

@gemal Strict rules does not only add new rules (that could be disabled by allRules: false) but also modify settings of standard rules.

Here is complete list of settings modifications did by including strict rules:

    polluteScopeWithLoopInitialAssignments: false
    polluteScopeWithAlwaysIterableForeach: false
    checkAlwaysTrueCheckTypeFunctionCall: true
    checkAlwaysTrueInstanceof: true
    checkAlwaysTrueStrictComparison: true
    checkAlwaysTrueLooseComparison: true
    checkDynamicProperties: %featureToggles.bleedingEdge%
    checkExplicitMixedMissingReturn: true
    checkFunctionNameCase: true
    checkInternalClassCaseSensitivity: true
    reportMaybesInMethodSignatures: true
    reportStaticMethodSignatures: true
    reportMaybesInPropertyPhpDocTypes: true

You can switch them back to default if you do not want stricter settings enabled.

github-actions[bot] commented 1 year 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.