Skip to content

Upgrade to PHPStan 2 (continues #939) - #1019

Open
jgalea wants to merge 25 commits into
simplepie:masterfrom
jgalea:phpstan-2
Open

jgalea wants to merge 25 commits into
simplepie:masterfrom
jgalea:phpstan-2

Conversation

@jgalea

@jgalea jgalea commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

This PR carries #939 (PHPStan 2, by @Alkarex) over to current master, as agreed in #939 (comment). His commits are kept as they are, with master merged in on top, so the history and authorship of #939 stay intact.

On top of the merge:

  • The conflict in tests/Integration/HTTP/ClientsTest.php takes master's side, since SimplePie: Avoid requesting local files using HTTP\Client #993/File,Psr18Client: Remove support for local files  #994 removed local file fetching. The staticMethod.alreadyNarrowedType ignore went with the old assertions.
  • phpVersion.min is now 70400, matching composer.json since Require PHP 7.4 or newer #1006. This also clears the IRI::parse_iri() error: on PHP 7.4 PREG_UNMATCHED_AS_NULL fills trailing unmatched groups, so the shape is always complete.
  • File::curlInit() (added after Upgrade to PHPStan 2 #939 was opened) was typed @return \CurlHandle, which PHPStan 2 rejects under a 7.4 to 8.5 range because it checks against the PHP 7 cURL signatures. It's now @return resource and throws if curl_init() returns false. CURLOPT_REFERER and CURLOPT_USERAGENT are skipped when empty: I checked that libcurl sends the same request either way (no User-Agent or Referer header).

PHPStan 2.1.56 reports no errors, both with and without mf2/mf2 installed (CI removes it on PHP 8.4+). The test suite gives the same results as master locally (PHP 8.5.11, PHPUnit 9.6), with the same failing test names on both.

Supersedes #939.

Alkarex and others added 22 commits September 14, 2025 16:27
PHPStan has improved a lot since version 1.12 used by SimplePie until now.
Take advantage of explicit PHPStan phpVersion range.
Define explicit range of minimum and maximum PHP version supported. Useful e.g. for function signatures, which have changed over time
https://phpstan.org/config-reference#phpversion
Do not run PHPStan for PHP < 7.4 but the tests are covered by phpVersion min, so it is actually enough to run PHPStan once on any supported PHP version.
Cannot support PHPUnit >= 10 at the same time as PHP 7.2.
# Conflicts:
#	tests/Integration/HTTP/ClientsTest.php
composer.json now requires PHP 7.4, so raise phpVersion.min to match.
That also clears the parse_iri() return type, since PHP 7.4 fills
trailing unmatched groups with PREG_UNMATCHED_AS_NULL.

curlInit() is analysed against the PHP 7 cURL signatures, so type it
as a resource and throw if curl_init() fails. Skip CURLOPT_REFERER and
CURLOPT_USERAGENT when empty, which sends the same request as setting
them to an empty string.
Comment thread composer.json Outdated
Comment on lines +36 to +37
"phpstan/phpstan": "~2.1.25",
"phpstan/phpstan-phpunit": "~2.0.7",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"phpstan/phpstan": "~2.1.25",
"phpstan/phpstan-phpunit": "~2.0.7",
"phpstan/phpstan": "~2.3.5",
"phpstan/phpstan-phpunit": "~2.1.2",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 36c181f, after merging current master. PHPStan 2.3.6 with phpstan-phpunit 2.1.2 reports no errors, with and without mf2 installed.

--fix-ignored now offers to replace the ignored phpunit.assertCount in SimplePieTest::testMicroformatItems() with assertCount(). I left it as is to keep this PR to the version bump.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have applied the assertCount() suggestion in my own branch. I think it is OK to fix it at the same time since it is related to the PHPStan upgrade, but up to maintainers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in f5b987b: testMicroformatItems() now uses assertCount() and the ignore is gone. PHPStan 2.3.6 reports no errors, and the suite shows the same failures as master.

Alkarex added a commit to FreshRSS/simplepie that referenced this pull request Nov 15, 2026
@Alkarex

Alkarex commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Alkarex added a commit to FreshRSS/FreshRSS that referenced this pull request Nov 19, 2026
Currently, SimplePie uses legacy DOMDocument parsing, which outputs potentially problematic HTML, not correctly sanitised.
This breaks the assumption that one can use something like `<div><!-- some HTML sanitized from SimplePie --></div>`.

```
--- Expected
+++ Actual
@@ @@
 '<ul>
-    <li><div></div></li>
+    <li><div>
     <li>Item</li>
-</ul>'
+</div></li></ul>'
```

When shown in a compliant Web browser, several tags will be wrongly closed, breaking the layout of the client.

This PR patches SimplePie to use the modern parser and code syntax, while maintaining a best-effort polyfill for legacy PHP versions < 8.4.

Depends on:

SimplePie: Upgrade to PHPStan 2
* FreshRSS/simplepie#97
* simplepie/simplepie#939
* simplepie/simplepie#1019

SimplePie: Use PHP 8.4+ \Dom classes and functions
* FreshRSS/simplepie#98
* simplepie/simplepie#1021

SimplePie: Add unit test for HTML5 sanitizing compliance
* simplepie/simplepie#1022

SimplePie: Remove obsolete xml_is_sane and XMLReader fallback
* simplepie/simplepie#1023

CssXPath: Add support for case insensitivity
* phpgt/CssXPath#256

fix #5201
fix #6830
fix #6831

~5% faster for HTML sanitising.
Remove SimpleXML. Remove XMLReader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants