1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
Go to file
Alberto Piai 144bb37f76
Fix array_key_exists() with all int literal keys (#5197)
When checking code like the following:

```
<?php

function checkNegated(string $key): void {
    $arr = [
        0 => "foo",
        1 => "bar",
    ];

    if (!array_key_exists($key, $arr)) {
        printf("not found\n");
    }
}

function check(string $key): void {
    $arr = [
        0 => "foo",
        1 => "bar",
    ];

    if (array_key_exists($key, $arr)) {
        printf("found\n");
    }
}
```

the `if` in `checkNegated` would cause:

```
ERROR: RedundantCondition - 9:10 - Type string for $key is never =int(0)
```

This happens when the array keys are all int literals, but the "needle"
is a string.

`array_key_exists()` uses a loose equality comparison, but the generated
assertions for this specific case
(`AssertionFinder::getArrayKeyExistsAssertions`) was generating strict
equality clauses. This commit fixes it by changing the generated clause
from `=` to `~`.
2021-02-12 17:00:38 -05:00
.circleci Remove ProxyManager run 2021-01-25 22:04:29 -05:00
.github/workflows Add explicit env 2021-02-11 13:59:52 -05:00
assets/psalm-phar Fix other check 2020-12-29 12:57:09 +00:00
bin Don't push master 2021-02-11 14:06:10 -05:00
build/phpunit
dictionaries Improved PDO::pgsqlGetNotify signature (#5169) 2021-02-06 22:07:37 -05:00
docs Add detail about non-empty-string 2021-02-10 12:20:36 -05:00
examples implement DTO for plugins (#4881) 2021-01-06 09:05:53 -05:00
src Fix array_key_exists() with all int literal keys (#5197) 2021-02-12 17:00:38 -05:00
stubs Fix #5099 - use class constant for default 2021-01-26 21:33:52 -05:00
tests Fix array_key_exists() with all int literal keys (#5197) 2021-02-12 17:00:38 -05:00
vendor-bin/box Fix lack of autoload_real in latest humbug/box 2020-12-29 14:01:22 +00:00
.appveyor.yml Fix windows builds (#4775) 2020-12-04 15:11:14 -05:00
.editorconfig
.gitattributes Removed misc files from dist archives (#4968) 2021-01-09 16:14:08 -05:00
.gitignore
.scrutinizer.yml More config 2020-05-19 17:51:28 -04:00
box.json.dist PHAR: Include issue docs for SARIF output (#4925) 2021-01-03 16:54:52 +00:00
CODE_OF_CONDUCT.md
composer.json Fix lack of autoload_real in latest humbug/box 2020-12-29 14:01:22 +00:00
config.xsd Add less severe issue for docblock property type invariance cc @bdsl 2021-02-07 00:52:29 -05:00
CONTRIBUTING.md Add contributing section of docs 2020-11-29 23:51:09 -05:00
infection.json.dist
keys.asc.gpg Change GPG key 2021-01-11 13:36:23 -05:00
LICENSE
phpcs.xml Simplify calling of replacer methods 2020-11-29 16:27:00 -05:00
phpunit.xml.dist Fix windows builds (#4775) 2020-12-04 15:11:14 -05:00
psalm
psalm-language-server
psalm-plugin
psalm-refactor
psalm.xml.dist Make complex method break the build 2021-01-22 09:58:25 -05:00
PsalmLogo.png
psalter
README.md Grammar 2020-11-19 19:40:40 -05:00
scoper.inc.php Move static code out of src 2020-10-12 00:59:19 -04:00

Psalm

Packagist Packagist Coverage Status Psalm coverage

Psalm is a static analysis tool for finding errors in PHP applications.

Installation

To get started, check out the installation guide.

Live Demo

You can play around with Psalm on its website.

Documentation

Documentation is available on Psalms website, generated from the docs folder.

Interested in contributing?

Have a look at CONTRIBUTING.md.

Who made this

Built by Matt Brown (@muglug).

Maintained by Matt and Bruce Weirdan (@weirdan).

The engineering team at Vimeo have provided a lot encouragement, especially @nbeliard, @erunion and @nickyr.