VKCOM / noverify

Pretty fast linter (code static analysis utility) for PHP
MIT License
673 stars 57 forks source link

linter: fixed false positives in Chevere projects #1143

Closed i582 closed 3 years ago

i582 commented 3 years ago

Chevere: https://github.com/chevere/chevere

Warnings after

This seems to be correct since the result is not used.

<critical> WARNING discardExpr: Expression evaluated but not used at /Users/petrmakhnev/chevere/src/Chevere/Components/Action/Action.php:76
        new Arguments($this->responseParameters, ...$namedData);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Correct, name is static

<critical> WARNING callStatic: Calling static method as instance method at /Users/petrmakhnev/chevere/src/Chevere/Components/Router/Route/RouteEndpoints.php:30
            $routeEndpoint->method()->name(),
                                      ^^^^

Incorrect, an analysis is required for reflection. Fixed.

<critical> ERROR   undefinedMethod: Call to undefined method {\ReflectionType|null}->getName() at /Users/petrmakhnev/chevere/src/Chevere/Components/Var/VarStorable.php:106
                ? $property->getType()->getName() . ' '
                                        ^^^^^^^

Seems to be correct since PHPStorm is giving a warning here as well.

<critical> ERROR   undefinedVariable: Cannot find referenced variable $actionName at /Users/petrmakhnev/chevere/src/Chevere/Components/Workflow/WorkflowRunner.php:70
                        ->code('%action%', $actionName)
                                           ^^^^^^^^^^^

Correct.

<critical> WARNING callStatic: Calling static method as instance method at /Users/petrmakhnev/chevere/src/Chevere/Components/Router/Route/Route.php:105
        $key = $endpoint->method()->name();
                                    ^^^^

The name method does not exist in the RoutePathInterface interface, so the linter gives a warning, which is probably correct, since the name method in the new inheritor will not necessarily be, which can lead to a runtime error.

<critical> ERROR   undefinedMethod: Call to undefined method {\Chevere\Interfaces\Router\Route\RoutePathInterface}->name() at /Users/petrmakhnev/chevere/src/Chevere/Components/Spec/Specs/RouteSpec.php:41
        $this->path = $path->name();
                             ^^^^
<critical> ERROR   undefinedMethod: Call to undefined method {\Chevere\Interfaces\Router\Route\RoutePathInterface}->name() at /Users/petrmakhnev/chevere/src/Chevere/Components/Spec/Specs/RouteSpec.php:42
        $this->key = $path->name();
                            ^^^^

This seems to be correct since the result is not used.

<critical> WARNING discardExpr: Expression evaluated but not used at /Users/petrmakhnev/chevere/src/Chevere/Components/Var/functions.php:30
            new ObjectClonable($value);
            ^^^^^^^^^^^^^^^^^^^^^^^^^^

Correct.

<critical> WARNING strictCmp: 3rd argument of in_array must be true when comparing strings at /Users/petrmakhnev/chevere/src/Chevere/Components/Type/Type.php:101
        if (isset(self::TYPE_VALIDATORS[$this->type]) && in_array($this->type, self::TYPE_ARGUMENTS)) {
                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MAYBE   assignOp: Could rewrite as `$this->timeTaken ??= (int) hrtime(true) - $this->startupTime` at /Users/petrmakhnev/chevere/src/Chevere/Components/Benchmark/BenchmarkRun.php:177
                $this->timeTaken = $this->timeTaken ?? (int) hrtime(true) - $this->startupTime;
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Incorrect.

<critical> ERROR   undefinedMethod: Call to undefined method {\Ds\Map}->getIterator() at /Users/petrmakhnev/chevere/src/Chevere/Components/Benchmark/BenchmarkRun.php:241
            foreach ($this->records->getIterator() as $name => $timeTaken) {
                                     ^^^^^^^^^^^

Incorrect, an analysis is required for reflection.

<critical> ERROR   undefinedMethod: Call to undefined method {\ReflectionType|null}->getName() at /Users/petrmakhnev/chevere/src/Chevere/Components/Var/ObjectClonable.php:82
                ? $property->getType()->getName() . ' '
                                        ^^^^^^^

This seems to be correct since the result is not used.

<critical> WARNING discardExpr: Expression evaluated but not used at /Users/petrmakhnev/chevere/src/Chevere/Components/Workflow/WorkflowRun.php:68
        new Arguments(
        ^

Correct.

<critical> WARNING callStatic: Calling static method as instance method at /Users/petrmakhnev/chevere/src/Chevere/Components/Spec/Specs/RouteEndpointSpec.php:29
        $this->key = $routeEndpoint->method()->name();
                                               ^^^^

It is necessary to investigate.

<critical> WARNING parentConstructor: Missing parent::__construct() call at /Users/petrmakhnev/chevere/src/Chevere/Components/Workflow/Attributes/Provider.php:28
    public function __construct(protected string $attribute)
                    ^^^^^^^^^^^

Seems to be correct since PHPStorm is giving a warning here as well.

<critical> ERROR   undefinedClass: Class or interface named \Chevere\Components\Workflow\ActionInterface does not exist at /Users/petrmakhnev/chevere/src/Chevere/Components/Workflow/Steps.php:164
        /** @var ActionInterface $action */
                 ^^^^^^^^^^^^^^^

It seems to be correct, since this is an atypical format and PHPStorm does not understand it either.

<critical> WARNING invalidDocblockRef: @see tag refers to unknown symbol `VarDumpHighlightInterface::KEYS` at /Users/petrmakhnev/chevere/src/Chevere/Interfaces/VarDump/VarDumpHighlightInterface.php:45
     * @see `VarDumpHighlightInterface::KEYS`
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Correct.

        <critical> WARNING strictCmp: 3rd argument of in_array must be true when comparing strings at /Users/petrmakhnev/chevere/src/Chevere/Components/Controller/Controller.php:43
        if (in_array('', [$this->relation, $this->dispatch])) {
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It is necessary to investigate.

        <critical> WARNING parentConstructor: Missing parent::__construct() call at /Users/petrmakhnev/chevere/src/Chevere/Components/Controller/Controller.php:36
        public function __construct(
                    ^^^^^^^^^^^

Correct.

        <critical> WARNING callStatic: Calling static method as instance method at /Users/petrmakhnev/chevere/src/Chevere/Components/Router/Route/RouteEndpoint.php:38
            $this->description = $method->description();
                                          ^^^^^^^^^^^