-
Notifications
You must be signed in to change notification settings - Fork 79
PHPStan Level 3 #385
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
PHPStan Level 3 #385
Conversation
@@ -625,6 +628,7 @@ public function getNamespaceDefinition() { | |||
$namespaceDefinition = null; | |||
} | |||
|
|||
/** @var NamespaceDefinition|null $namespaceDefinition */ | |||
return $namespaceDefinition; |
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.
we could add a runtime check for stuff like this or refactor but it's probably a risky move considering the number of similar changes needed across the whole code base.
b7cae20
to
ef0d29f
Compare
Rebased my changes on |
@@ -27,7 +27,6 @@ cache: | |||
- validation/frameworks | |||
|
|||
before_script: | |||
- if [[ $STATIC_ANALYSIS = true ]]; then composer require phpstan/phpstan --no-update; fi |
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.
required in --dev
now as PHPStan is a PHAR
* @return InterfaceMembers | ||
*/ | ||
private function parseInterfaceMembers($parentNode) : Node { | ||
private function parseInterfaceMembers($parentNode) : InterfaceMembers { |
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.
probably dozens of other places we can do this, but figure PHPStan will pick this up on level 4 or 5
Updated |
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.
Thanks for doing this and thanks for the review @TysonAndre. lgtm but I'll wait for the final ✔️ from @TysonAndre
And yeah, if we can get all the same stuff into github actions that exists in Travis, I would like to get rid of Travis. |
if ($expression instanceof Node) { | ||
$expression->parent = $scopedPropertyAccessExpression; | ||
$scopedPropertyAccessExpression->scopeResolutionQualifier = $expression; // TODO ensure always a Node | ||
|
||
// scopeResolutionQualifier does not accept `Node` but |
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.
LGTM overall for latest commits; they addressed review comments/nits.
In followup PRs, that should hopefully be addressed by making parameter types more precise as well, assuming that phpstan can narrow a mix of subclasses of Node and definite non-subclassess to just the expected subclasses Expression|QualifiedName
(haven't checked)
(Strict typing overall is useful so we don't accidentally write to an undeclared property, which would be a notice in 8.2 since the classes declared here aren't using #[\AllowDynamicProperties]
, though I don't need AllowDynamicProperties for my own use case)
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - After microsoft#385 is merged we can probably start running phpstan in GitHub Actions for a single php version and remove .travis.yml entirely (as a followup PR)
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After microsoft#385 is merged run_phpstan.sh can remove the separate install step (as a followup PR)
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After microsoft#385 is merged run_phpstan.sh can remove the separate install step (as a followup PR)
This should be rebased against Other than not being rebased, all of the changes here should be safe to release, though I'd rather release 0.1.2 first if you expect merging this to delay the process of publishing a release - 0.1.2 is getting rather large
Looks correct and the property is still declared on the subclasses. Double checking: This is confirmed by the fact that tests continue to pass, so CHILD_NAMES obviously still refers to properties that exist. |
9bcf16f
2d66556
to
9bcf16f
Compare
Updated and squashed |
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.
lgtm again; I confirmed locally that there are no new/missing changes in the rebase
Property declarations should say MissingToken now? |
b4ee294
to
0145399
Compare
seems like it: updated |
FTR I've created a PR on my repo against this branch for level 4: dantleech#1 although probably best to merge this first before reviewing. |
Added ReturnTypeWillChange Fix return type for Expression Add type hints for returned variables Add generic parameter for delimted list Fixing type hints Ignore co-variance error Remove TODO - it already must always be a Node Ignore error Add missing types Update phpstan to level 3 Add phpstan to dev reqs No need to install phpstan independently Do not override unary expression operand It seems to me that the operand can be any expression Added token to operand types -- should this be MissingToken? Include tokens in return types ExpressionStatement => EchoStatement It seems this is always an EchoStatement not an ExpressionStatement unaryExpressionOrHigher can return a ThrowExpression Remove overridden property Add Token to union Remove QualifiedName and rename local variable Remove unused import Add return types Remove trailing whitespace Add MissingToken type
0145399
to
937564f
Compare
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.
Not a maintainer, but familiar with this repo - I don't see any issues in the latest patch set. The changed types look accurate
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After microsoft#385 is merged run_phpstan.sh can remove the separate install step (as a followup PR) - Require a newer phpunit patch version in devDependencies Make it harder for contributors to have any inconsistencies with CI when running tests (e.g. php version support, fixed phpunit bugs, etc)
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After microsoft#385 is merged run_phpstan.sh can remove the separate install step (as a followup PR) - Require a newer phpunit patch version in devDependencies Make it harder for contributors to have any inconsistencies with CI when running tests (e.g. php version support, fixed phpunit bugs, etc)
appologetic ping cc @roblourens |
... |
Sorry @dantleech. Will take a look ASAP |
No pressure :) thanks. |
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After microsoft#385 is merged run_phpstan.sh can remove the separate install step (as a followup PR) - Require a newer phpunit patch version in devDependencies Make it harder for contributors to have any inconsistencies with CI when running tests (e.g. php version support, fixed phpunit bugs, etc)
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After microsoft#385 is merged run_phpstan.sh can remove the separate install step (as a followup PR) - Require a newer phpunit patch version in devDependencies Make it harder for contributors to have any inconsistencies with CI when running tests (e.g. php version support, fixed phpunit bugs, etc)
- Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After microsoft#385 is merged run_phpstan.sh can remove the separate install step (as a followup PR) - Require a newer phpunit patch version in devDependencies Make it harder for contributors to have any inconsistencies with CI when running tests (e.g. php version support, fixed phpunit bugs, etc)
👋 in Phpactor one of the most common types of error is accessing a member on NULL on TP parser nodes. So I thought I'd try and increase the type coverage.
This PR:
opeand
property on the children ofUnaryExpression
As a follow up question is it worth ditching Travis and adding PHPStan to the
main
GHA workflow?We should be able to get to PHPStan level 5 pretty easy (30 errors) but level 6 is 368 errors 😅