False positive: Call to static method Webmozart\Assert\Assert::allInArray() with array<string> and array<string> will always evaluate to true
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 45/100
Piste de recherche
Start with the test.php reproduction and run the shown PHPStan command using phpstan.neon at level 4. Inspect the phpstan-webmozart-assert extension configuration and the discussion in issue 142; done means this example no longer reports staticMethod.alreadyNarrowedType while the assertion analysis remains correct.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
The following code causes a false PHPStan error. The Assert::allInArray($enabledNames, $supportedNames); assertion certainly isn't always true.
use Webmozart\Assert\Assert;
class C
{
/**
* @param array<string> $supportedNames
* @param array<string> $enabledNames
*/
public function __construct(
array $supportedNames,
array $enabledNames,
)
{
Assert::allInArray($enabledNames, $supportedNames);
}
}
$ vendor/bin/phpstan analyse -c phpstan.neon test.php
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ --------------------------------------------------------------------------------------------------------------------------------
Line test.php
------ --------------------------------------------------------------------------------------------------------------------------------
17 Call to static method Webmozart\Assert\Assert::allInArray() with array<string> and array<string> will always evaluate to true.
🪪 staticMethod.alreadyNarrowedType
------ --------------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 1 error
===============
$ vendor/bin/phpstan diagnose
Note: Using configuration file /Users/melka/work/rh/phpstan.neon.
PHP runtime version: 8.3.22
PHP version for analysis: 8.3.22 (from runtime)
PHPStan version: 2.1.29
PHPStan running from:
/Users/melka/work/rh/vendor/phpstan/phpstan
Extension installer: Not installed
Included configs from Composer packages:
phpstan/phpstan-webmozart-assert (extension.neon): 2.0.0
Discovered Composer project root:
/Users/melka/work/rh
===============
$ cat phpstan.neon
includes:
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
parameters:
level: 4 # lowest level where this starts happening
Also discussed in https://github.com/phpstan/phpstan-webmozart-assert/issues/142#issuecomment-3372330454
- Langage dominant
- PHP
- Étoiles
- 185
- Forks
- 33
- Merge moyen
- 20 h 40 min
- PR mergées (30 j)
- 7
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de phpstan/phpstan-webmozart-assert
-
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
phpstan/phpstan-webmozart-assert#187 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 32/100
phpstan/phpstan-webmozart-assert#180 · 5 commentaires ·
-
False positive: Call to inArray() with different object instances will always evaluate to trueOuvertebug
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
phpstan/phpstan-webmozart-assert#142 · 17 commentaires ·
-
Support the new methods in 1.4Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 38/100
phpstan/phpstan-webmozart-assert#6 · 3 commentaires · 2 réactions ·
Toutes les issues de phpstan/phpstan-webmozart-assert
Issues similaires
-
bug needs grooming
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 63/100
phpstan/phpstan-phpunit#361 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
HE-Arc/le-panier-du-coin#49 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 2 jours
-
15.0
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100