Skip to content

Level 6 - Comparison operation ... results in an error ; Level 7 - No errors #3364

@czjvic

Description

@czjvic

Bug report

Strange evaluation of the comparasion operator for levels 6 and lower. Levels 7 and higher returns "No errors found."

    /**
    * @param string|array<int|string>|null $value
     *
     * @return string|array<int|string>|null
     */
    public function transform($value) {
        if ($value !== null && !is_array($value) && $value != -1) {
            $transformed = [
                'year'  => gmdate('Y', (int) $value),
                'month' => gmdate('n', (int) $value),
            ];
        } elseif ($value == -1) {
            $transformed = [
                'year'  => -1,
                'month' => -1,
            ];
        } else {
            $transformed = $value;
        }

        return $transformed;
    }

Level 6 reports:
https://phpstan.org/r/04cc3e0d-5cab-417e-a9ee-41cb96bf39d7
Comparison operation "==" between array<int|string>|string|null and -1 results in an error.

Level 7 for same code reports:
https://phpstan.org/r/d068bb79-a0e4-4fb6-a797-867538af2091
No errors!

Code snippet that reproduces the problem

Error with level 6:
https://phpstan.org/r/04cc3e0d-5cab-417e-a9ee-41cb96bf39d7

Expected output

No errors! for all levels

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions