I want to configure phpstan such that it reports use of undefined method calls
<?php
namespace App;
class Testeroni
{
public function asdf()
{
$this->iDoNotExist(); // Ok
self::whatIsThat(); // OK
$me = new self();
$me->iDoNotExist(); // does not get reported!! why?
}
}
But it does not report the last method call. Anybody an idea?
this is the config used
parameters:
customRulesetUsed: true
paths:
- src
- libs
services:
-
class: PHPStan\Rules\Methods\CallMethodsRule
tags: [phpstan.rules.rule]
-
class: PHPStan\Rules\Methods\CallStaticMethodsRule
tags: [phpstan.rules.rule]
-
class: PHPStan\Rules\Methods\ExistingClassesInTypehintsRule
tags: [phpstan.rules.rule]
It also reports an error Parameter has invalid Type
. How can I disable that?
Short answer: Because you should not use custom rule sets unless you know what you’re doing 😊 Stick to official rule levels, you will have much better experience: https://phpstan.org/user-guide/rule-levels
Long answer: besides including specific rule classes, you also need to pay attention to specific parameters that need to be set and that PHPStan takes care of on your behalf. This error would be reported on level 2.