Is there a tool to analyze PHP code to check whether returned value is used properly?

330 Views Asked by At

Let's say I have the following code:

$result = $thirdPartyAPI->doSomething(); // returns false if error
if ($result == false) {
    return $someErrorCode;
}

// process the valid $result

I have lots of calls to the $thirdPartyAPI spread throughout the code, so I don't want to forget about checking if $result is a valid one or an error happened.

I've checked PHP Code Sniffer and PHP Mess Detector tools, but I've found none of their rules to be appropiate for this particular case.

I'm wondering if there is a tool (such a static code analysis one) that is able to report whether I forgot to check that a returned value has a certain value.

1

There are 1 best solutions below

2
On

Since 2017 there is: PHPStan

I use it and it works like a charm. Here is simple intro to it