-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Increase type safety #87
Draft
jtojnar
wants to merge
12
commits into
j0k3r:master
Choose a base branch
from
jtojnar:more-stricter
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
af19fe7
to
b23a226
Compare
This was referenced Mar 16, 2024
Merged
Breaking BC for Readability 3.0.
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`.
PHP 7.4 supports property type hints. - `getInnerText` actually accepts `DOMNode`, not `DOMElement`, since it can be e.g. `DOMText`. Really, we just need the `textContent` property. - Since we now use property type hints, we can drop the `no_null_property_initialization` PHP-CS-Fixer rule.
It is more specific then DOMElement. This allows us to get rid of the assertions in tests.
Will make it easier to statically analyze with PHPStan. This is a BC break.
Nothing affecting correctness, just stuff making it easier for PHPStan to reason about the code. Remove `$errcontext` argument in `set_error_handler` since it is removed in PHP 8.
It would fail for e.g. `<div> <p>foo</p> </div>`. mozilla/readability uses children for the tag lookup, which return only elements. PHP does not have children property so b580cf2 mistakenly used `childNodes` instead, but that can return any node type. Let’s filter the children ourselves. Also add comments from mozilla/readability’s `_hasSingleTagInsideElement`.
Converting `hasSingleTagInsideElement` into a type-safe getter will allow PHPStan to know the type of `newNode` is `DOMElement`.
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.
This will allow us to use flexible heredocs in test, as well as typed properties and other goodies.
https://www.php.net/releases/7_3_0.php
https://www.php.net/releases/7_4_0.php