Issues (64)

src/leetcode/ImplementStrstr.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class ImplementStrstr
8
{
9
    public static function strstr(string $haystack, string $needle): int
0 ignored issues
show
The parameter $haystack is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

9
    public static function strstr(/** @scrutinizer ignore-unused */ string $haystack, string $needle): int

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $needle is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

9
    public static function strstr(string $haystack, /** @scrutinizer ignore-unused */ string $needle): int

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
10
    {
11
        $ans = -1;
0 ignored issues
show
The assignment to $ans is dead and can be removed.
Loading history...
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return integer. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
12
    }
13
}
14