Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1dc68c6
Update to PHPStan 2
Alkarex Sep 14, 2025
f6c4630
Remove PHPStan for older PHP
Alkarex Sep 14, 2025
de1d46f
It is sufficient to run PHPStan with one supported PHP version
Alkarex Sep 14, 2025
6d38ebc
It would be sufficient to run PHPStan with one supported PHP version
Alkarex Sep 14, 2025
37fe471
Remove magic_quotes_gpc
Alkarex Sep 14, 2025
f0ea604
Extracted PHPUnit fix to another PR
Alkarex Sep 15, 2025
41497dd
Fix PHPStan accordingly (will have to be changed back again)
Alkarex Sep 15, 2025
926dd9c
Add PHPStan extension to paths as recommended
Alkarex Sep 15, 2025
15f585e
Merge branch 'master' into pr/Alkarex/939
Alkarex Sep 15, 2025
7a24764
Put back memory-limit
Alkarex Sep 22, 2025
c7b53e1
Update .github/workflows/ci.yml
Alkarex Sep 22, 2025
f1b4405
Revert type check
Alkarex Sep 22, 2025
d87732a
Merge branch 'master' into phpstan-phpversion
Alkarex Sep 29, 2025
ab3ec58
Merge branch 'master' into phpstan-phpversion
Alkarex Sep 30, 2025
2239ea6
Merge branch 'master' into phpstan-phpversion
Alkarex Oct 2, 2025
d1802f4
Merge branch 'master' into phpstan-phpversion
Alkarex Nov 25, 2025
a554484
Fix PHPStan
Alkarex Nov 25, 2025
4baa958
Merge branch 'master' into phpstan-phpversion
Alkarex Jan 18, 2026
0513979
Merge remote-tracking branch 'upstream/master' into pr/Alkarex/939
Alkarex Feb 24, 2026
cb24b9b
Merge master into PHPStan 2 branch (local)
jgalea Oct 19, 2026
3436762
Merge remote-tracking branch 'origin/master' into rc/pr939-merge
jgalea Nov 10, 2026
a6c2597
Fix PHPStan 2 after merging master
jgalea Nov 10, 2026
642b542
Upgrade to PHPStan 2
Alkarex Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ jobs:
coverage: none
tools: none

- name: Remove PHPStan for incompatible PHP versions
if: ${{ matrix.php < '8.0' }}
run: composer remove --dev phpstan/phpstan phpstan/phpstan-phpunit

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: "Install Composer dependencies"
Expand All @@ -81,7 +85,9 @@ jobs:
- name: Run unit tests
run: composer test

# It would be sufficient to run PHPStan with one supported PHP version
- name: Run static analysis
if: ${{ matrix.php >= '8.0' }}
run: composer phpstan -- --error-format=github

test-compiled:
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"donatj/mock-webserver": "^2.7",
"friendsofphp/php-cs-fixer": "^2.19 || ^3.8",
"mf2/mf2": "^0.5.0",
"phpstan/phpstan": "~1.12.2",
"phpunit/phpunit": "^8 || ^9 || ^10",
"phpstan/phpstan": "~2.3.5",
"phpstan/phpstan-phpunit": "~2.1.2",
"phpunit/phpunit": "^8 || ^9",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/simple-cache": "^1 || ^2 || ^3"
Expand Down Expand Up @@ -69,7 +70,7 @@
"coverage": "phpunit --coverage-html=.phpunit.cache/code-coverage",
"cs": "php-cs-fixer fix --verbose --dry-run --diff",
"fix": "php-cs-fixer fix --verbose --diff",
"phpstan": "phpstan analyze --memory-limit 512M",
"phpstan": "phpstan analyse --memory-limit 512M",
"test": "phpunit"
}
}
59 changes: 12 additions & 47 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
parameters:
phpVersion:
min: 70400 # PHP 7.4
max: 80599 # PHP 8.5

level: 8

paths:
Expand All @@ -7,54 +11,15 @@ parameters:
- tests/
- utils/

ignoreErrors:
# Ignore that only one const exists atm
-
message: "#^Strict comparison using \\!\\=\\= between 'GET' and 'GET' will always evaluate to false\\.$#"
count: 1
path: src/HTTP/Psr18Client.php

# Not used since https://github.com/simplepie/simplepie/commit/b2eb0134d53921e75f0fa70b1cf901ed82b988b1 but cannot be removed due to BC.
- '(Constructor of class SimplePie\\Enclosure has an unused parameter \$javascript\.)'

# Testing legacy dynamic property usage.
- '(Access to an undefined property SimplePie.IRI::\$nonexistent_prop\.)'

-
message: '(^Strict comparison using === between string and false will always evaluate to false\.$)'
count: 1
path: src/HTTP/Parser.php
# Only occurs on PHP ≥ 8.0
reportUnmatched: false

-
message: '(^Strict comparison using === between string and false will always evaluate to false\.$)'
count: 1
path: src/IRI.php
# Only occurs on PHP ≥ 8.0
reportUnmatched: false

-
message: '(^Parameter #1 \$exception of method PHPUnit\\Framework\\TestCase::expectException\(\) expects class-string<Throwable>, string given\.$)'

count: 3
path: tests/Unit/Cache/Psr16Test.php
# Only occurs on PHP ≤ 7.4
reportUnmatched: false

-
message: '(^Parameter \$parser of method SimplePie\\Parser::(tag_open|cdata|tag_close)\(\) has invalid type XMLParser\.$)'

count: 3
path: src/Parser.php
# Only occurs on PHP ≤ 7.4
reportUnmatched: false
excludePaths:
analyseAndScan:
- .git/*?
- build/*?
- vendor/*

# PHPStan stubs bug https://github.com/phpstan/phpstan/issues/8629
-
message: '(^Access to an undefined property XMLReader::\$\w+\.$)'
# Only occurs on PHP ≥ 8.2
reportUnmatched: false
treatPhpDocTypesAsCertain: false # TODO: Fix

includes:
- utils/PHPStan/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
1 change: 1 addition & 0 deletions src/Cache/Psr16.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function get_data(string $key, $default = null)
*/
public function set_data(string $key, array $value, ?int $ttl = null): bool
{
// @phpstan-ignore argument.type (mixed is not supported by PHP < 8.0, used by psr/simple-cache >= 2)
return $this->cache->set($key, $value, $ttl);
}

Expand Down
1 change: 1 addition & 0 deletions src/Enclosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class Enclosure
* @param Rating[]|null $ratings
* @param Restriction[]|null $restrictions
* @param string[]|null $thumbnails
* @phpstan-ignore constructor.unusedParameter
*/
public function __construct(
?string $link = null,
Expand Down
14 changes: 11 additions & 3 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ final public static function fromResponse(Response $response): self
/**
* @param array<string, string> $headers
* @param array<int, mixed> $curl_options
* @return \CurlHandle
* @return resource
*/
private static function curlInit(
string $url,
Expand All @@ -656,6 +656,9 @@ private static function curlInit(
bool $setAcceptEncoding = true
) {
$fp = curl_init();
if ($fp === false) {
throw new \SimplePie\Exception('Could not initialize cURL');
}

$headers2 = [];
foreach ($headers as $key => $value) {
Expand Down Expand Up @@ -683,8 +686,13 @@ private static function curlInit(
curl_setopt($fp, CURLOPT_FAILONERROR, true);
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
// curl_setopt($fp, CURLOPT_REFERER, \SimplePie\Misc::url_remove_credentials($url)); // FreshRSS removed
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
// $referer = \SimplePie\Misc::url_remove_credentials($url);
// if ($referer !== '') {
// curl_setopt($fp, CURLOPT_REFERER, $referer); // FreshRSS removed
// }
if ($useragent !== '') {
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
}
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
foreach ($curl_options as $curl_param => $curl_value) {
curl_setopt($fp, $curl_param, $curl_value);
Expand Down
1 change: 0 additions & 1 deletion src/HTTP/FileClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function __construct(Registry $registry, array $options = [])
*/
public function request(string $method, string $url, array $headers = []): Response
{
// @phpstan-ignore-next-line Enforce PHPDoc type.
if ($method !== self::METHOD_GET) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #1 ($method) only supports method "%s".',
Expand Down
9 changes: 9 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,27 @@ public function parse(string &$data, string $encoding, string $url = '')
// Strip BOM:
// UTF-32 Big Endian BOM
if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") {
/** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */
$data = substr($data, 4);
}
// UTF-32 Little Endian BOM
elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") {
/** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */
$data = substr($data, 4);
}
// UTF-16 Big Endian BOM
elseif (substr($data, 0, 2) === "\xFE\xFF") {
/** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */
$data = substr($data, 2);
}
// UTF-16 Little Endian BOM
elseif (substr($data, 0, 2) === "\xFF\xFE") {
/** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */
$data = substr($data, 2);
}
// UTF-8 BOM
elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") {
/** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */
$data = substr($data, 3);
}

Expand All @@ -121,6 +126,7 @@ public function parse(string &$data, string $encoding, string $url = '')
if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false) {
$declaration = $this->registry->create(DeclarationParser::class, [substr($data, 5, $pos - 5)]);
if ($declaration->parse()) {
/** @phpstan-ignore parameterByRef.type (for PHP < 8.0) */
$data = substr($data, $pos + 2);
$data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . "\n" .
self::set_doctype($data);
Expand Down Expand Up @@ -289,6 +295,7 @@ public function get_data()
* @param XMLParser|resource|null $parser
* @param array<string, string> $attributes
* @return void
* @phpstan-ignore class.notFound (XMLParser requires PHP >= 8.0)
*/
public function tag_open($parser, string $tag, array $attributes)
{
Expand Down Expand Up @@ -345,6 +352,7 @@ public function tag_open($parser, string $tag, array $attributes)
/**
* @param XMLParser|resource|null $parser
* @return void
* @phpstan-ignore class.notFound (XMLParser requires PHP >= 8.0)
*/
public function cdata($parser, string $cdata)
{
Expand All @@ -358,6 +366,7 @@ public function cdata($parser, string $cdata)
/**
* @param XMLParser|resource|null $parser
* @return void
* @phpstan-ignore class.notFound (XMLParser requires PHP >= 8.0)
*/
public function tag_close($parser, string $tag)
{
Expand Down
1 change: 1 addition & 0 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public function &create($type, array $parameters = [])
$instance->set_registry($this);
} elseif (method_exists($instance, 'set_registry')) {
trigger_error(sprintf('Using the method "set_registry()" without implementing "%s" is deprecated since SimplePie 1.8.0, implement "%s" in "%s".', RegistryAware::class, RegistryAware::class, $class), \E_USER_DEPRECATED);
// @phpstan-ignore method.nonObject
$instance->set_registry($this);
}

Expand Down
1 change: 0 additions & 1 deletion src/Sanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public function pass_cache_data(bool $enable_cache = true, string $cache_locatio
$this->cache_location = $cache_location;
}

// @phpstan-ignore-next-line Enforce PHPDoc type.
if (!is_string($cache_name_function) && !$cache_name_function instanceof NameFilter) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #3 ($cache_name_function) must be of type %s',
Expand Down
5 changes: 1 addition & 4 deletions src/SimplePie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,6 @@ protected function fetch_data(&$cache)
$cache = new BaseDataCache($cache);
}

// @phpstan-ignore-next-line Enforce PHPDoc type.
if ($cache !== false && !$cache instanceof DataCache) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #1 ($cache) must be of type %s|false',
Expand Down Expand Up @@ -2112,7 +2111,7 @@ protected function fetch_data(&$cache)
// Set raw_data to false here too, to signify that the cache
// is still valid.
$this->raw_data = false;
if (isset($file)) { // FreshRSS
if (isset($file)) { // FreshRSS // @phpstan-ignore isset.variable
$old_cache_control = $this->data['headers']['cache-control'] ?? '';
$old_max_age = \SimplePie\HTTP\Utils::get_http_max_age($this->data['headers']);

Expand Down Expand Up @@ -3622,8 +3621,6 @@ public static function merge_items(array $urls, int $start = 0, int $end = 0, in
foreach ($urls as $arg) {
if ($arg instanceof SimplePie) {
$items = array_merge($items, $arg->get_items(0, $limit));

// @phpstan-ignore-next-line Enforce PHPDoc type.
} else {
trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/SimplePieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public function testMicroformatItems(string $path, string $feedTitle, array $tit

self::assertSame($feedTitle, $feed->get_title());
$items = $feed->get_items();
// @phpstan-ignore phpunit.assertCount
self::assertSame(count($titles), count($items), 'Number of items does not match');
foreach (array_map(null, $titles, $items) as $i => [$expectedTitle, $item]) {
assert($item !== null); // For PHPStan
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function testClassExists(): void

public function testFileExtendsResponse(): void
{
// @phpstan-ignore staticMethod.alreadyNarrowedType
self::assertInstanceOf(Response::class, new FileMock(''));
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/HTTP/Psr18ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testRequestReturnsResponse(): void
$this->createMock(UriFactoryInterface::class)
);

// @phpstan-ignore staticMethod.alreadyNarrowedType
self::assertInstanceOf(Response::class, $client->request(Client::METHOD_GET, 'https://example.com/feed.xml'));
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/HTTP/Psr7ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Psr7ResponseTest extends TestCase
{
public function testPsr7ResponseExtendsResponse(): void
{
// @phpstan-ignore staticMethod.alreadyNarrowedType
self::assertInstanceOf(Response::class, new Psr7Response($this->createMock(ResponseInterface::class), '', ''));
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/IRITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ function ($errno, $errstr): bool {
E_USER_NOTICE
);

// @phpstan-ignore property.notFound (we want to test that it fails)
$should_fail = $iri->nonexistent_prop;
}

Expand Down
Loading