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

Increase type safety #87

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

Increase type safety #87

wants to merge 12 commits into from

Commits on Mar 18, 2024

  1. Remove deprecated debug property

    Breaking BC for Readability 3.0.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    6f6cff0 View commit details
    Browse the repository at this point in the history
  2. Fix missing return value in grabArticle

    Not sure if this is expected but at least it works the same as before.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    dfa7cb0 View commit details
    Browse the repository at this point in the history
  3. Use helpers for content score manipulation

    `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`.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    c83d337 View commit details
    Browse the repository at this point in the history
  4. Use PHP type hints instead of PHPDoc

    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.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    7a2ae65 View commit details
    Browse the repository at this point in the history
  5. Use JSLikeHTMLElement in type hints

    It is more specific then DOMElement.
    
    This allows us to get rid of the assertions in tests.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    1acfc6f View commit details
    Browse the repository at this point in the history
  6. JSLikeHTMLElement: Get rid of magic properties

    Will make it easier to statically analyze with PHPStan.
    
    This is a BC break.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    e9c9dbc View commit details
    Browse the repository at this point in the history
  7. Enable strict_types

    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    b9fdf04 View commit details
    Browse the repository at this point in the history
  8. Raise PHPStan to level 4

    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.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    a12629e View commit details
    Browse the repository at this point in the history
  9. JSHtml

    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    d2d7dcd View commit details
    Browse the repository at this point in the history
  10. Fix hasSingleTagInsideElement method

    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`.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    273a95a View commit details
    Browse the repository at this point in the history
  11. Raise PHPStan version to 5

    Converting `hasSingleTagInsideElement` into a type-safe getter
    will allow PHPStan to know the type of `newNode` is `DOMElement`.
    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    ccdd166 View commit details
    Browse the repository at this point in the history
  12. fixup! JSHtml

    jtojnar committed Mar 18, 2024
    Configuration menu
    Copy the full SHA
    8cbb8a8 View commit details
    Browse the repository at this point in the history