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

ControlStructures/AssignmentInCondition: prevent fatal error during live coding #1624

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Sep 28, 2023

Fixes:

Fatal error: Uncaught TypeError: SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff::processCondition(): Argument #3 ($parenthesisCloser) must be of type int, null given, called in path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php on line 56 and defined in path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php:59
Stack trace:
#0 path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php(56): SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff->processCondition(Object(PHP_CodeSniffer\Files\LocalFile), 100, NULL, 'if')
#1 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Files\File.php(509): SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 99)
#2 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Files\LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Runner.php(632): PHP_CodeSniffer\Files\LocalFile->process()
#4 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Runner.php(438): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
#5 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Runner.php(116): PHP_CodeSniffer\Runner->run()
#6 D:\000_GitHub\PHPCS\PHP_CodeSniffer\bin\phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#7 {main}
  thrown in path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php on line 59

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 28, 2023

The build failure, IMO, is incorrect.

Linting and the coding standards are being run over the test fixtures, while those should be able to contain horribly bad code and parse errors just to ensure that the actual sniff handles this correctly.

In my opinion, the test fixtures should be excluded from linting and the PHPCS check, though I'm open to hearing other suggestions on how to get round this.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 28, 2023

Oh and the PHPStan error is also incorrect. Not sure where it is basing the information off, but those keys can easily not be set. Adding treatPhpDocTypesAsCertain: false to the configuration might fix this ?

…ive coding

```
Fatal error: Uncaught TypeError: SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff::processCondition(): Argument slevomat#3 ($parenthesisCloser) must be of type int, null given, called in path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php on line 56 and defined in path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php:59
Stack trace:
#0 path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php(56): SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff->processCondition(Object(PHP_CodeSniffer\Files\LocalFile), 100, NULL, 'if')
slevomat#1 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Files\File.php(509): SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 99)
slevomat#2 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Files\LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
slevomat#3 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Runner.php(632): PHP_CodeSniffer\Files\LocalFile->process()
slevomat#4 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Runner.php(438): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
slevomat#5 D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Runner.php(116): PHP_CodeSniffer\Runner->run()
slevomat#6 D:\000_GitHub\PHPCS\PHP_CodeSniffer\bin\phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
slevomat#7 {main}
  thrown in path\to\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff.php on line 59
```
@kukulich kukulich force-pushed the feature/assignmentincondition-bug-fix-fatal-error branch from 3034fc5 to b62b3f6 Compare October 5, 2023 15:49
@kukulich kukulich merged commit e741174 into slevomat:master Oct 5, 2023
35 checks passed
@jrfnl jrfnl deleted the feature/assignmentincondition-bug-fix-fatal-error branch October 5, 2023 15:54
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.

2 participants