0

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?

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah but I want to understand what I am doing with the tools i use ;) Thanks for the hint that this works on level 2. checkOnlyThis needs to be false :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.