Skip to content

[TASK] Configure the target PHP version for PHPStan #1216

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

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

oliverklee
Copy link
Contributor

This will help avoid it suggesting things that are only possile in later PHP versions.

Fixes #1214

This will help avoid it suggesting things that are only
possile in later PHP versions.

Fixes #1214
@oliverklee oliverklee added the developer-specific Issues that only affect maintainers, contributors, and people submitting PRs label Mar 25, 2025
@oliverklee oliverklee requested a review from JakeQZ March 25, 2025 09:21
@oliverklee oliverklee self-assigned this Mar 25, 2025
@coveralls
Copy link

Coverage Status

coverage: 52.048%. remained the same
when pulling 52deb82 on task/configure-phpstan-php-version
into 734c72e on main.

@JakeQZ JakeQZ merged commit ece5633 into main Mar 25, 2025
21 checks passed
@JakeQZ JakeQZ deleted the task/configure-phpstan-php-version branch March 25, 2025 16:10
@JakeQZ
Copy link
Contributor

JakeQZ commented Mar 28, 2025

This isn't working as well as it should. With PHP 8.3 on the server, it's picking up that int<0, max> and int<1, max> are not compatible:

  Line   src/Position/Position.php (in context of class                               
         Sabberworm\CSS\Tests\Unit\Position\Fixtures\ConcretePosition)                
 ------ ----------------------------------------------------------------------------- 
  62     Parameter #1 $lineNumber (int<1, max>|null) of method                        
         Sabberworm\CSS\Tests\Unit\Position\Fixtures\ConcretePosition::setPosition()  
         should be contravariant with parameter $lineNumber (int<0, max>|null)        
         of method Sabberworm\CSS\Position\Positionable::setPosition()                
         🪪  method.childParameterType                                                

But with PHP 7.4 on Windows, this error is not found. In both cases, PHPStan version is 2.1.2. Context is #1221 (where I will now correct the Positionable::setPosition DocBlock to int<1, max>|null for $lineNumber).

Oddly, this doesn't invlove a native declaration, but a DocBlock annotation, which should be independent of PHP version (target or runtime).

Also, the error Parameters should have "Sabberworm\\CSS\\CSSList\\CSSListItem\|array" types as the only types passed to this method has not gone away with this change. Native union types require PHP 8.0.

This change involved no changes to the baseline. Whereas the equivalent change to Emogrifier did.

I wonder if PHPStan is even picking up the setting at all. A difference between the config files is that the parameters section of the one here begins with a parallel setting, whereas the one in Emogrifier begins with the phpVersion setting.

@JakeQZ
Copy link
Contributor

JakeQZ commented Mar 28, 2025

This isn't working as well as it should. With PHP 8.3 on the server, it's picking up that int<0, max> and int<1, max> are not compatible:

Scrub that. Just ran it again with PHP 7.4, and it picked up the error. Maybe I didn't run the full set of tests before finally committing (I was playing around with nullability to check that if I'd got it wrong it would be picked up).

Also, the error Parameters should have "Sabberworm\\CSS\\CSSList\\CSSListItem\|array" types as the only types passed to this method has not gone away with this change. Native union types require PHP 8.0.

This change involved no changes to the baseline. Whereas the equivalent change to Emogrifier did.

I wonder if PHPStan is even picking up the setting at all. A difference between the config files is that the parameters section of the one here begins with a parallel setting, whereas the one in Emogrifier begins with the phpVersion setting.

This is still a bit of a mystery, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-specific Issues that only affect maintainers, contributors, and people submitting PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define minimum target PHP version for PHPStan?
3 participants