Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions lib/Command/SendEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,11 @@ public function execute(InputInterface $input, OutputInterface $output): int {
do {
$users = $this->mqHandler->getAllUsers(self::BATCH_SIZE);
$batchCount = \count($users);
if ($batchCount === 0) {
// queue is empty
break;
}

$this->sendBatch($users, $output);
if ($progress !== null) {
$progress->advance($batchCount);
if ($batchCount > 0) {
$this->sendBatch($users, $output);
if ($progress !== null) {
$progress->advance($batchCount);
}
Comment on lines +84 to +88

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.

}
} while ($batchCount > 0);

Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/OCSEndPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class OCSEndPoint {
protected $objectId;

/** @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.)


/** @var bool */
protected $loadPreviews;
Expand Down
2 changes: 2 additions & 0 deletions lib/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function getNotificationTypes(IL10N $l) {
* @return bool
*/
public function send(IEvent $event) {
// @phpstan-ignore identical.alwaysFalse
if ($event->getAffectedUser() === '' || $event->getAffectedUser() === null) {
return false;
}
Expand Down Expand Up @@ -137,6 +138,7 @@ public function send(IEvent $event) {
* @return bool
*/
public function storeMail(IEvent $event, $latestSendTime) {
// @phpstan-ignore identical.alwaysFalse
if ($event->getAffectedUser() === '' || $event->getAffectedUser() === null) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions lib/DataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public function createCollection() {
* @return array List of Parameters
*/
public function parseParameters($parameterString) {
// @phpstan-ignore function.alreadyNarrowedType
if (!\is_string($parameterString)) {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ protected function shareNotificationForOriginalOwners($currentOwner, $subject, $
*/
$this->view->chroot('/' . $currentOwner . '/files');
$mount = $this->view->getMount($path);
// @phpstan-ignore instanceof.alwaysTrue
if (!($mount instanceof IMountPoint)) {
return;
}
Expand Down Expand Up @@ -742,6 +743,7 @@ protected function addNotificationsForUser($user, $subject, $subjectParams, $fil
$event->setAuthor($agentAuthor);
}

// @phpstan-ignore identical.alwaysFalse
if ($event->getAuthor() === null) {
$event->setAuthor($this->currentUser);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/PlainTextParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function parseMessage($message) {
* @return string
*/
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.

return \preg_replace_callback('/<collection>(.*?)<\/collection>/', function ($match) {
$parameterList = \explode('><', $match[1]);
$parameterListLength = \sizeof($parameterList);
Expand Down
1 change: 1 addition & 0 deletions lib/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function getNotificationTypes($user, $method) {
* Returns a "username => i:batchtime" Map for method = email
*/
public function filterUsersBySetting($users, $method, $type) {
// @phpstan-ignore function.alreadyNarrowedType
if (empty($users) || !\is_array($users)) {
return [];
}
Expand Down
20 changes: 4 additions & 16 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,18 @@ parameters:
- %currentWorkingDirectory%/../../lib/base.php
ignoreErrors:
-
message: '#Variable \$this might not be defined.#'
rawMessage: 'Variable $this might not be defined.'
path: appinfo/routes.php
count: 1
-
message: '#Comparison operation ">" between int<1, max> and 0 is always true.#'
path: lib/Command/SendEmails.php
count: 1
-
message: '#Strict comparison using === between non-empty-string and null will always evaluate to false.#'
path: lib/Data.php
count: 2
-
message: '#Method OCP\\DB\\QueryBuilder\\IExpressionBuilder::orX\(\) invoked with 2 parameters, 0-1 required.#'
rawMessage: 'Method OCP\DB\QueryBuilder\IExpressionBuilder::orX() invoked with 2 parameters, 0-1 required.'
path: lib/Data.php
count: 3
-
message: '#Call to method getSharedFrom\(\) on an unknown class OC\\Files\\Storage\\Shared.#'
path: lib/FilesHooks.php
count: 1
-
message: '#PHPDoc tag @var for variable \$storage contains unknown class OC\\Files\\Storage\\Shared.#'
rawMessage: 'Call to method getSharedFrom() on an unknown class OC\Files\Storage\Shared.'
path: lib/FilesHooks.php
count: 1
-
message: '#Strict comparison using === between string and null will always evaluate to false.#'
rawMessage: 'PHPDoc tag @var for variable $storage contains unknown class OC\Files\Storage\Shared.'
path: lib/FilesHooks.php
count: 1
2 changes: 1 addition & 1 deletion vendor-bin/phan/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"phan/phan": "^5.4"
"phan/phan": "^5.5"
}
}
2 changes: 1 addition & 1 deletion vendor-bin/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"phpstan/phpstan": "^1.10"
"phpstan/phpstan": "^2.2"
}
}