Skip to content

Conversation

@mlutonsky
Copy link

Hi and thanks for this awesome phpstan extensions!

This PR fixes bug, when non-semver tag was detected as the latest released tag, causing internal PHPStan error (due to uncaught \Version\Exception\InvalidVersionString exception when parsing version string) as:

 -- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
     Error                                                                                                                                                                                                   
 -- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
     Internal error: Version string 'testing.0.0' is not valid and cannot be parsed while analysing file <phpfile.php>
                                                                                                                                                                                                             
     Run PHPStan with -v option and post the stack trace to:                                                                                                                                                 
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml                                                                                                                                  
                                                                                                                                                                                                             
 -- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

This fix handles the exception, resulting in standard PHPStan error.

... and fixes some tiny codestyle issues.

Thanks.
Cheers!

Copilot AI review requested due to automatic review settings December 5, 2025 17:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where non-semver git tags (e.g., 'testing') cause PHPStan internal errors by introducing proper exception handling. When an invalid version string is encountered, it now throws a custom InvalidTagException that is caught and converted to a standard PHPStan error message instead of propagating as an uncaught InvalidVersionString exception.

Key changes:

  • Introduced InvalidTagException for handling invalid git tags that cannot be parsed as semantic versions
  • Enhanced ReferenceVersionFinder::nextVersion() to track the original version string and wrap parsing failures in InvalidTagException
  • Updated TodoByVersionRule to catch and handle InvalidTagException alongside existing LatestTagNotFoundException

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/utils/InvalidTagException.php New exception class for invalid tag parsing errors
src/utils/ReferenceVersionFinder.php Added $originalVersionString parameter to track the original tag value through recursive calls, and wraps version parsing failures in InvalidTagException
src/TodoByVersionRule.php Added catch block for InvalidTagException to display user-friendly error messages; also includes minor code style improvements for consistent spacing around concatenation operators
tests/TodoByVersionRuleTestingTagFetchterTest.php New test verifying that invalid tags produce appropriate error messages instead of internal errors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

1 participant