Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect CSS Selector error when valid HTML tag is being selected #2223

Open
Matt-PMCT opened this issue Sep 9, 2023 · 2 comments
Open

Comments

@Matt-PMCT
Copy link

Matt-PMCT commented Sep 9, 2023

When I have the Symfony Plugin enabled I am getting errors for valid $crawler->filter() calls in my unit tests.

For example, this code, which is virtually identical to the Symfony Documentation (https://symfony.com/doc/current/components/dom_crawler.html#node-traversing):
$crawler->filter('h3')
or
$crawler->filter('body')
Results in the IDE display an error stating " ':' expected " as seen in this picture:
image

If I disable the Symfony Plugin, PHPStorm generates no errors, so I believe the source of it is this plugin. The code and test runs properly, so this error appears to have something to do with this plugin.
The Crawler call is from this portion of Crawler.php:
image

@Matt-PMCT
Copy link
Author

Matt-PMCT commented Jan 7, 2024

Also, if I disable the plugin, the error goes away. I also could find no way to suppress or stop this.

After a bit of tinkering, I believe that what may be happening is that this plug-in is mistakenly classifying the variable as CSS. Then PHPpstorm says if this is CSS, then it must be proper CSS. I suspect this because if you change the string to be a proper CSS attribute with a colon and semi-colon, then PHPstorm is now happy:
image

but this is not CSS; it is a selector and should not have an error.

@mhujer
Copy link

mhujer commented Apr 25, 2024

Just came to report same issue. It does marks invalid both HTML selectors $crawler->filter('h1') and ID selectors: $crawler->filter('#payment'). (HTML class selectors are OK $crawler->filter('.payment')).

I guess that it is because of this workaround when the parameter of filter method is wrapped so it becomes a snippet of CSS. I understand that Phpstorm probably does not have a CSS selector language available, but maybe a small adjustment to the prefix/suffix would help. When I tried adding {} to my selector, e.g. $crawler->filter('h1 {}') it made the error go away, because it is now valid CSS snippet.

new MethodLanguageInjection(LANGUAGE_ID_CSS, "@media all { ", " }", CSS_SELECTOR_SIGNATURES),

btw. my sidebar in controller test looks like this these days (all are selector issues):
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants