-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Raise PHPStan to level 4 #93
Draft
jtojnar
wants to merge
18
commits into
j0k3r:master
Choose a base branch
from
jtojnar:phpstan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
Not sure if this is expected but at least it works the same as before.
`DOMAttr::$value` must be a `string`. Let’s add helpers for manipulating the `readability` attribute so that we do not have to keep casting it from and to `string` in order to appease `strict_types`.
To preserve BC, we are not using type hints for now.
It was replaced by ignoring `missingType.iterableValue` error identifier in PHPStan 1.12 but at the current analysis level, this is not really checked.
This is bad state so it should not be a breaking change.
Since we require PHP 7.4, contravariance in param types is supported, so we do not need to worry about subclasses that widen the param type. It will be only breaking in the unlikely case a subclass uses a type that contradicts the PHPDoc type annotation and does not not extend `DOMNode`. Also fix the type annotation since some invocations pass it a `DOMText`, an arbitrary sibling/child `DOMNode` or even `null`.
This allows developer to create their own own config file, e.g. for setting `editorUrl`: https://phpstan.org/user-guide/output-format#opening-file-in-an-editor
Because PHPStan does not currently analyze XPath expressions, we need to use a @var cast: https://phpstan.org/writing-php-code/phpdocs-basics#inline-%40var These are list of elements since asterisk wildcard only selects elements: https://www.w3.org/TR/1999/REC-xpath-19991116/#path-abbrev
We use `DOMDocument::registerNodeClass()` to make DOM methods return `JSLikeHTMLElement` instead of `DOMElement`. Unfortunately, it is not possible for PHPStan to detect that so we need to cast it ourselves: phpstan/phpstan#10748 We may want to deprecate it in the future just to get rid of this mess. Also add PHPStan stubs for DOM classes so that we do not need to cast everything. It is fine to do that globally as we only ever use DOM with `JSLikeHTMLElement` registered. This patch also allows us to get rid of the assertions in tests.
Nothing affecting correctness, just stuff making it easier for PHPStan to reason about the code.
We cannot use stubs since PHPStan already has them to override
The argument can only be `DOMElement`. Discovered by bleeding edge PHPStan.
`isset` does two things: it checks if the entity resulting from the chain of accessors is defined, and if it is not `null`. We know that the properties are always defined so we can just replace those `isset`s with `null` checks. This will allow us to reason about the code more clearly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.