Potentially false-positive `Operations priority`
Simbiat opened this issue · comments
Subject | Details |
---|---|
Plugin | Php Inspections (EA Extended) |
Language level | PHP 8.3 |
Current behaviour
I have a complex if condition like this
if (
#Either href or imagesrcset or both need to be present. imagesrcset does not make sense in HTTP header
((!isset($link['href']) && !isset($link['imagesrcset'])) || ($type === 'header' && !isset($link['href']))) ||
#Either rel or itemprop can be set at a time. itemprop does not make sense in HTTP header
((!isset($link['rel']) && !isset($link['itemprop'])) || isset($link['rel'], $link['itemprop']) || ($type === 'header' && !isset($link['rel']))) ||
#Validate rel values
(isset($link['rel']) &&
#If strictRel is true, only support types from https://html.spec.whatwg.org/multipage/links.html#linkTypes and https://microformats.org/wiki/existing-rel-values#formats (types, that NEED to be supported by clients). Also includes webmention (https://www.w3.org/TR/2017/REC-webmention-20170112/)
($strictRel === true &&
(
#Check that rel is valid
preg_match('/^(?!$)(alternate( |$))?((appendix|author|canonical|chapter|child|contents|copyright|dns-prefetch|glossary|help|icon|apple-touch-icon|apple-touch-icon-precomposed|mask-icon|its-rules|license|manifest|me|modulepreload|next|pingback|preconnect|prefetch|preload|prerender|prev|previous|search|section|stylesheet|subsection|toc|transformation|up|first|last|index|home|top|webmention)( |$))*/i', $link['rel']) !== 1 ||
#If crossorigin or referrerpolicy is set, check that rel type is an external resource
(
(isset($link['crossorigin']) || isset($link['referrerpolicy'])) &&
preg_match('/^(alternate )?((dns-prefetch|icon|apple-touch-icon|apple-touch-icon-precomposed|mask-icon|manifest|modulepreload|pingback|preconnect|prefetch|preload|prerender|stylesheet)( |$))*/i', $link['rel']) !== 1
)
)
) ||
#If we are using "body", check that rel is body-ok one
($type === 'body' && preg_match('/^(alternate )?.*(dns-prefetch|modulepreload|pingback|preconnect|prefetch|preload|prerender|stylesheet).*$/i', $link['rel']) !== 1) ||
#imagesrcset and imagesizes are allowed only for preload with as=image
((isset($link['imagesrcset']) || isset($link['imagesizes'])) && (preg_match('/^(alternate )?.*preload.*$/i', $link['rel']) !== 1 || !isset($link['as']) || $link['as'] !== 'image')) ||
#sizes attribute should be set only if rel is icon of apple-touch-icon
(isset($link['sizes']) && preg_match('/^(alternate )?.*(icon|apple-touch-icon|apple-touch-icon-precomposed).*$/i', $link['rel']) !== 1) ||
#as is allowed only for preload
(isset($link['as']) && preg_match('/^(alternate )?.*(modulepreload|preload|prefetch).*$/i', $link['rel']) !== 1) ||
#color is allowed only for mask-icon
(isset($link['color']) && preg_match('/^(alternate )?.*mask-icon.*$/i', $link['rel']) !== 1)
) ||
#imagesrcset is an image candidate with width descriptor, we need imagesizes as well
(isset($link['imagesrcset']) && preg_match('/ \d+w(,|$)/', $link['imagesrcset']) === 1 && !isset($link['imagesizes'])) ||
#as is allowed to have limited set of values (as per https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content). Also check that crossorigin is set, if as=fetch
(isset($link['as']) && (preg_match('/^(document|object|embed|audio|font|image|script|worker|style|track|video|fetch)$/i', $link['as']) !== 1 || (preg_match('/^fetch$/i', $link['as']) === 1 && !isset($link['crossorigin']))))
) {
#Skip the element, since it does not confirm with the standard
continue;
}
Specific part of it is marked with [EA] Operations priority might differ from what you expect: please wrap needed with '(...)'.
I honestly do not see what it does not like here, since necessary parts are enclosed in parentheses already. Maybe I am just blind, but checking with ChatGPT, it suggests the same syntax. Not a good source of confirmation, but still. Possibly a false-positive. But if not, some help would be much appreciated.
Expected behaviour
No error for the if
Environment details
PhpStorm 2024.1
Build #PS-241.14494.237, built on March 27, 2024
Licensed to simbiat.ru / Dmitry Kustov
Subscription is active until May 11, 2024.
For non-commercial open source development only.
Runtime version: 17.0.10+8-b1207.12 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 5120M
Cores: 16
Registry:
debugger.new.tool.window.layout=true
run.processes.with.pty=TRUE
ide.experimental.ui=true
Non-Bundled Plugins:
com.jetbrains.space (241.14494.150)
com.intellij.ml.llm (241.14494.240)
com.kalessil.phpStorm.phpInspectionsEA (5.0.0.0)