Skip to content

test: bump phpstan to v2#1263

Draft
phil-davis wants to merge 1 commit into
masterfrom
bump-phpstan-v2
Draft

test: bump phpstan to v2#1263
phil-davis wants to merge 1 commit into
masterfrom
bump-phpstan-v2

Conversation

@phil-davis

@phil-davis phil-davis commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

PHPstan is updated from v1 to v2. v2 is the current version supported on PHP 8.

The format of ignored errors in phpstan.neon is changed to use the new rawMessage format. Previously the messages had to be encoded as regex strings. For oridnary text messages, the rawMessage form is much simpler.

Some ignored messages were moved into the code as phpstan-ignore comment lines. This associates the ignored message directly with the exact place in the code that generates the message. That will be helpful if/when code refactoring is being done to "fix" the code that generates the phpstan message.

The PHP unit tests were emitting some PHP deprecation messages. Code has been minimally refactored to avoid these.

There are no real production run-time fixes to make here. The purpose of this PR is to demonstrate the type of minimal changes that can be needed when updating from PHPstan v1 to v2. No rush to review or merge this.

PHPstan is updated from v1 to v2. v2 is the current version
supported on PHP 8.

The format of ignored errors in phpstan.neon is changed to use the
new rawMessage format. Previously the messages had to be encoded
as regex strings. For oridnary text messages, the rawMessage form
is much simpler.

Some ignored messages were moved into the code as phpstan-ignore
comment lines. This associates the ignored message directly with
the exact place in the code that generates the message. That will
be helpful if/when code refactoring is being done to "fix" the
code that generates the phpstan message.

The PHP unit tests were emitting some PHP deprecation messages.
Code has been minimally refactored to avoid these.

Signed-off-by: Phillip Davis <phil@jankaritech.com>
Comment on lines +84 to +88
if ($batchCount > 0) {
$this->sendBatch($users, $output);
if ($progress !== null) {
$progress->advance($batchCount);
}

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.

phpstan reported that $batchCount was always greater than 0 when evaluated at the while below.
That was true, because the (only) way out of this loop was the early break above.

I have refactored this loop so that while ($batchCount > 0) is actually the place where the decision to exit the loop is made.


/** @var string */
protected $user;
protected $user = '';

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.

There were potential ways to access $user when it was still null.
It is supposed to be a string, so set it to the empty string at instantiation.

(Some day we could really declare all the types, and enable strict_types, etc.)

Comment thread lib/PlainTextParser.php
*/
protected function parseCollections($message) {
// @phpstan-ignore nullCoalesce.variable
$message = $message ?? '';

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.

The unit tests managed to call down to here with $message null.
That reported:

PHPUnit 9.6.35 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.32
Configuration: ./phpunit.xml
Warning:       No code coverage driver available

...............................................................  63 / 398 ( 15%)
............................................................... 126 / 398 ( 31%)
............................................................... 189 / 398 ( 47%)
............................................................... 252 / 398 ( 63%)
............................................................... 315 / 398 ( 79%)
......PHP Deprecated:  preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/phil/git/owncloud/core/apps-external/activity/lib/PlainTextParser.php on line 56
PHP Deprecated:  preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/phil/git/owncloud/core/apps-external/activity/lib/PlainTextParser.php on line 56
PHP Deprecated:  preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/phil/git/owncloud/core/apps-external/activity/lib/PlainTextParser.php on line 56
PHP Deprecated:  preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/phil/git/owncloud/core/apps-external/activity/lib/PlainTextParser.php on line 56
......................................................... 378 / 398 ( 94%)
....................                                            398 / 398 (100%)

Time: 00:03.787, Memory: 40.00 MB

OK (398 tests, 1213 assertions)

$message is supposed to be a string. But we don't explicitly declare that.
So if it is passed as null, then set it to the empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant