-
Notifications
You must be signed in to change notification settings - Fork 15
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
Allow finding arrow function variables when arrow function is in file scope #347
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d45a394
Add test for arrow function in global scope
sirbrillig fe41708
Still look for arrow func when var scope is 0
sirbrillig 490606d
Remove duplicate call to findVariableScopeExceptArrowFunctions
sirbrillig f107315
Remove phpcs-import-detection depdendency since it is unused
sirbrillig f4748f1
Remove ImportDetection on phpcs config
sirbrillig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,63 @@ | ||
{ | ||
"name": "sirbrillig/phpcs-variable-analysis", | ||
"description": "A PHPCS sniff to detect problems with variables.", | ||
"type": "phpcodesniffer-standard", | ||
"keywords" : [ "phpcs", "static analysis" ], | ||
"license": "BSD-2-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Sam Graham", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Payton Swick", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support" : { | ||
"issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", | ||
"wiki" : "https://github.com/sirbrillig/phpcs-variable-analysis/wiki", | ||
"source": "https://github.com/sirbrillig/phpcs-variable-analysis" | ||
}, | ||
"config": { | ||
"sort-order": true, | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
}, | ||
"lock": false | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"VariableAnalysis\\": "VariableAnalysis/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"VariableAnalysis\\Tests\\": "Tests/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
"test": "./vendor/bin/phpunit --no-coverage", | ||
"coverage": "./vendor/bin/phpunit", | ||
"test-lte9": "./vendor/bin/phpunit -c phpunitlte9.xml.dist --no-coverage", | ||
"coverage-lte9": "./vendor/bin/phpunit -c phpunitlte9.xml.dist", | ||
"lint": "./vendor/bin/phpcs", | ||
"fix": "./vendor/bin/phpcbf", | ||
"phpstan": "./vendor/bin/phpstan analyse", | ||
"psalm": "./vendor/bin/psalm --no-cache", | ||
"static-analysis": "composer phpstan && composer psalm" | ||
}, | ||
"require" : { | ||
"php" : ">=5.4.0", | ||
"squizlabs/php_codesniffer": "^3.5.6" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3", | ||
"sirbrillig/phpcs-import-detection": "^1.1", | ||
"phpcsstandards/phpcsdevcs": "^1.1", | ||
"phpstan/phpstan": "^1.7", | ||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", | ||
"vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0" | ||
} | ||
"name": "sirbrillig/phpcs-variable-analysis", | ||
"description": "A PHPCS sniff to detect problems with variables.", | ||
"type": "phpcodesniffer-standard", | ||
"keywords": ["phpcs", "static analysis"], | ||
"license": "BSD-2-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Sam Graham", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Payton Swick", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", | ||
"wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki", | ||
"source": "https://github.com/sirbrillig/phpcs-variable-analysis" | ||
}, | ||
"config": { | ||
"sort-order": true, | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
}, | ||
"lock": false | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"VariableAnalysis\\": "VariableAnalysis/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"VariableAnalysis\\Tests\\": "Tests/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
"test": "./vendor/bin/phpunit --no-coverage", | ||
"coverage": "./vendor/bin/phpunit", | ||
"test-lte9": "./vendor/bin/phpunit -c phpunitlte9.xml.dist --no-coverage", | ||
"coverage-lte9": "./vendor/bin/phpunit -c phpunitlte9.xml.dist", | ||
"lint": "./vendor/bin/phpcs", | ||
"fix": "./vendor/bin/phpcbf", | ||
"phpstan": "./vendor/bin/phpstan analyse", | ||
"psalm": "./vendor/bin/psalm --no-cache", | ||
"static-analysis": "composer phpstan && composer psalm" | ||
}, | ||
"require": { | ||
"php": ">=5.4.0", | ||
"squizlabs/php_codesniffer": "^3.5.6" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3", | ||
"phpcsstandards/phpcsdevcs": "^1.1", | ||
"phpstan/phpstan": "^1.7", | ||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", | ||
"vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can
self::findVariableScopeExceptArrowFunctions()
returnfalse
? Would a check foris_int()
instead of!is_null()
be more stable ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can return false. It returns
null|int
. It has only 3 return statements:is_int()
).getStartOfTokenScope()
when it's not an integer or less than or equal to 0. Since that function can return null or 0 or a key from the token conditions stack, I think it is alwaysnull|int
, unless there's something I don't grok aboutconditions
(can the key of aconditions
array be false?).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair enough. I was mostly asking because the code within the condition seems to expect an
int
, while the condition doesn't actually strictly safeguard that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I think that
is_int()
is probably better for that reason, but I'm going to leave it for now since I already merged and I have to trust the types in the phpdoc, even if they're only enforced by static analysis tools.I checked, and if I change the return type of
findVariableScopeExceptArrowFunctions
toint|null|false
, I get this error:So everything should be safe. Hooray for strong types!