Open thunderer opened 3 years ago
Hey @thunderer, can you reproduce the issue on https://psalm.dev ?
I think it's caused by array_map('preg_quote', $this->names);
. preg_quote()
may accept two arguments, but Psalm sees you're only passing a single array, so it must be assuming the second argument is mixed.
Replacing that with explicit lambda gets rid of that mixed:
diff --git a/src/Parser/WordpressParser.php b/src/Parser/WordpressParser.php
index 41b5f90..9eee024 100644
--- a/src/Parser/WordpressParser.php
+++ b/src/Parser/WordpressParser.php
@@ -72,7 +72,7 @@ public static function createFromNames(array $names)
public function parse($text)
{
$names = $this->names
- ? implode('|', array_map('preg_quote', $this->names))
+ ? implode('|', array_map(function($arg) { return preg_quote($arg, '/'); }, $this->names))
: RegexBuilderUtility::buildNameRegex();
$regex = str_replace('<NAMES>', $names, static::$shortcodeRegex);
preg_match_all($regex, $text, $matches, PREG_OFFSET_CAPTURE);
Note that you probably need that second parameter, otherwise slashes in $this->names
would cause regex compilation error.
@weirdan thanks, indeed that was the place. I had similar issues in other (closed-source) projects where I can't share code publicly, though. Can you answer my original questions?
(2 mixed, lines 13, 37)
) would help a lot,totallyTyped
and level 1
?can Psalm report such places?
Not to my knowledge.
should there be any unreported mixed placed with totallyTyped and level 1?
I think there shouldn't, but as far as I understand, from Psalm's point of view that wasn't really an error as the function had the default value for that parameter. I believe Psalm shouldn't increment mixed count in this use case - so in my opinion that's the bug.
How to find the exact places where Psalm
--stats
thinks the value ismixed
? I see exactly one file with99% (1 mixed)
, there are no other issues or suggestions with or without it. Should there be anymixed
places when there are no violations using maximum level1
andtotallyTyped
is turned on?For the reference, I'm talking about Shortcode library. There is one
mixed
place in WordpressParser I have trouble finding. Thanks in advance for your help.