Skip to content
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"psalm:dev": "@psalm",
"psalm:update-baseline": "psalm --threads=1 --update-baseline",
"rector:check": "rector --dry-run --clear-cache",
"rector:fix": "rector",
"rector:fix": "rector && php-cs-fixer fix",
"test:unit": "phpunit -c tests/Unit/phpunit.xml --colors=always --fail-on-warning --fail-on-risky --display-deprecations --display-phpunit-deprecations",
"test:integration": "cd tests/Integration && ./run.sh"
},
Expand Down
2 changes: 1 addition & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function register(IRegistrationContext $context): void {

#[\Override]
public function boot(IBootContext $context): void {
$context->injectFn(\Closure::fromCallable([$this, 'registerApp']));
$context->injectFn($this->registerApp(...));
}

public function registerApp(IManager $notificationManager): void {
Expand Down
6 changes: 3 additions & 3 deletions lib/BackgroundJob/GenerateUserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class GenerateUserSettings extends TimedJob {
public function __construct(
ITimeFactory $time,
private IDBConnection $connection,
private IUserManager $userManager,
private SettingsMapper $settingsMapper,
private readonly IDBConnection $connection,
private readonly IUserManager $userManager,
private readonly SettingsMapper $settingsMapper,
) {
parent::__construct($time);

Expand Down
4 changes: 2 additions & 2 deletions lib/BackgroundJob/SendNotificationMails.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class SendNotificationMails extends TimedJob {
public function __construct(
ITimeFactory $timeFactory,
private MailNotifications $mailNotifications,
private bool $isCLI,
private readonly MailNotifications $mailNotifications,
private readonly bool $isCLI,
) {
parent::__construct($timeFactory);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/PushController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function registerDevice(string $pushTokenHash, string $devicePublicKey, s
return new DataResponse([
'publicKey' => $key->getPublic(),
'deviceIdentifier' => $deviceIdentifier,
'signature' => base64_encode($signature),
'signature' => base64_encode((string)$signature),
], $created ? Http::STATUS_CREATED : Http::STATUS_OK);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ protected function notificationFromRow(array $row): INotification {
->setUser($row['user'])
->setDateTime($dateTime)
->setObject($row['object_type'], $row['object_id'])
->setSubject($row['subject'], (array)json_decode($row['subject_parameters'], true));
->setSubject($row['subject'], (array)json_decode((string)$row['subject_parameters'], true));

if ($row['message'] !== '' && $row['message'] !== null) {
$notification->setMessage($row['message'], (array)json_decode($row['message_parameters'], true));
$notification->setMessage($row['message'], (array)json_decode((string)$row['message_parameters'], true));
}
if ($row['link'] !== '' && $row['link'] !== null) {
$notification->setLink($row['link']);
Expand All @@ -347,7 +347,7 @@ protected function notificationFromRow(array $row): INotification {
$notification->setIcon($row['icon']);
}

$actions = (array)json_decode($row['actions'], true);
$actions = (array)json_decode((string)$row['actions'], true);
foreach ($actions as $actionData) {
$action = $notification->createAction();
$action->setLabel($actionData['label'])
Expand Down
2 changes: 1 addition & 1 deletion lib/Listener/UserCreatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class UserCreatedListener implements IEventListener {
public function __construct(
private SettingsMapper $settingsMapper,
private readonly SettingsMapper $settingsMapper,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class UserDeletedListener implements IEventListener {
public function __construct(
private Handler $handler,
private SettingsMapper $settingsMapper,
private readonly Handler $handler,
private readonly SettingsMapper $settingsMapper,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Notifier/AdminNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public function prepare(INotification $notification, string $languageCode): INot
}
}

$path1 = rtrim($file1->getPath(), '/');
$path1 = rtrim((string)$file1->getPath(), '/');
if (str_starts_with($path1, '/' . $notification->getUser() . '/files/')) {
// Remove /user/files/...
[,,, $path1] = explode('/', $path1, 4);
}
$path2 = rtrim($file2->getPath(), '/');
$path2 = rtrim((string)$file2->getPath(), '/');
if (str_starts_with($path2, '/' . $notification->getUser() . '/files/')) {
// Remove /user/files/...
[,,, $path2] = explode('/', $path2, 4);
Expand Down
20 changes: 10 additions & 10 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function filterWebPushDeviceList(array $devices, string $app): array {
}

$devices = array_values(array_filter($devices, function ($device) use ($app) {
$appTypes = explode(',', $device['app_types']);
$appTypes = explode(',', (string)$device['app_types']);
return $device['activated'] && (\in_array($app, $appTypes)
|| (\in_array('all', $appTypes) && !\in_array('-' . $app, $appTypes)));
}));
Expand Down Expand Up @@ -364,7 +364,7 @@ public function pushToDevice(int $id, INotification $notification): void {
$notification = $this->notificationManager->prepare($notification, $language);
} catch (AlreadyProcessedException|IncompleteParsedNotificationException|\InvalidArgumentException $e) {
// FIXME remove \InvalidArgumentException in Nextcloud 39
$this->printInfo('Error when preparing notification for push: ' . get_class($e));
$this->printInfo('Error when preparing notification for push: ' . $e::class);
return;
} finally {
$this->notificationManager->setPreparingPushNotification(false);
Expand Down Expand Up @@ -442,8 +442,8 @@ public function proxyPushToDevice(int $id, IUser $user, array $devices, INotific

$userKey = $this->keyManager->getKey($user);

$this->printInfo('Private user key size: ' . strlen($userKey->getPrivate()));
$this->printInfo('Public user key size: ' . strlen($userKey->getPublic()));
$this->printInfo('Private user key size: ' . strlen((string)$userKey->getPrivate()));
$this->printInfo('Public user key size: ' . strlen((string)$userKey->getPublic()));

$this->printInfo('');
$this->printInfo('Found ' . count($devices) . ' devices registered for push notifications');
Expand Down Expand Up @@ -623,7 +623,7 @@ public function proxyPushDeleteToDevice(string $userId, IUser $user, array $devi
foreach ($devices as $device) {
$device['token'] = (int)$device['token'];
try {
$proxyServer = rtrim($device['proxyserver'], '/');
$proxyServer = rtrim((string)$device['proxyserver'], '/');
if (!isset($this->payloadsToSend[$proxyServer])) {
$this->payloadsToSend[$proxyServer] = [];
}
Expand Down Expand Up @@ -964,7 +964,7 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific
$priority = $ret['urgency'];
$type = $ret['type'];

$this->printInfo('Device public key size: ' . strlen($device['devicepublickey']));
$this->printInfo('Device public key size: ' . strlen((string)$device['devicepublickey']));
$this->printInfo('Data to encrypt is: ' . json_encode($data));

$padding = $this->appConfig->getAppValueString('push_encryption_padding', 'PKCS1') === 'OAEP' ? OPENSSL_PKCS1_OAEP_PADDING : OPENSSL_PKCS1_PADDING;
Expand All @@ -980,8 +980,8 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific
} else {
$this->printInfo('<error>Failed to signed encrypted push subject</error>');
}
$base64EncryptedSubject = base64_encode($encryptedSubject);
$base64Signature = base64_encode($signature);
$base64EncryptedSubject = base64_encode((string)$encryptedSubject);
$base64Signature = base64_encode((string)$signature);

return [
'deviceIdentifier' => $device['deviceidentifier'],
Expand Down Expand Up @@ -1014,8 +1014,8 @@ protected function encryptAndSignDelete(Key $userKey, array $device, ?array $ids
}

openssl_sign($encryptedSubject, $signature, $userKey->getPrivate(), OPENSSL_ALGO_SHA512);
$base64EncryptedSubject = base64_encode($encryptedSubject);
$base64Signature = base64_encode($signature);
$base64EncryptedSubject = base64_encode((string)$encryptedSubject);
$base64Signature = base64_encode((string)$signature);

return [
'remaining' => $remainingIds,
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function hasTalkDesktop(string $userId, int $maxAge = 0): bool {

$result = $query->executeQuery();
while ($row = $result->fetch()) {
if (preg_match('/ \(Talk Desktop Client - [A-Za-z ]+\)$/', $row['name'])) {
if (preg_match('/ \(Talk Desktop Client - [A-Za-z ]+\)$/', (string)$row['name'])) {
$result->closeCursor();
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Settings/AdminSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

class AdminSection implements IIconSection {
public function __construct(
private IURLGenerator $url,
private IL10N $l,
private readonly IURLGenerator $url,
private readonly IL10N $l,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Settings/SetupWarningOnRateLimitReached.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

class SetupWarningOnRateLimitReached implements ISetupCheck {
public function __construct(
private IAppConfig $appConfig,
private ITimeFactory $timeFactory,
private IL10N $l,
private readonly IAppConfig $appConfig,
private readonly ITimeFactory $timeFactory,
private readonly IL10N $l,
) {
}

Expand Down
11 changes: 10 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

use Nextcloud\Rector\Set\NextcloudSets;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withPaths([
Expand All @@ -16,5 +18,12 @@
__DIR__ . '/tests/Integration',
__DIR__ . '/tests/Unit',
])
->withPhpSets(php81: true)
->withSkipPath(__DIR__ . '/lib/autoload')
->withSkipPath(__DIR__ . '/lib/Vendor')
->withSkipPath(__DIR__ . '/tests/Integration/vendor')
->withPhpSets(php82: true)
->withSets([
PHPUnitSetList::PHPUNIT_110,
NextcloudSets::NEXTCLOUD_34,
])
->withTypeCoverageLevel(0);
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function runOcc($args = [], $env = []) {
'maintenance:mode',
], true);

$args = array_map(fn ($arg) => escapeshellarg($arg), $args);
$args = array_map(escapeshellarg(...), $args);
$args[] = '--no-ansi';
$argString = implode(' ', $args);

Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function validateResponseAndSignature(string $verify): void {
Assert::assertNotEmpty($response['signature'], 'Signature should not be empty');

if ($verify === 'verify') {
$result = openssl_verify($response['deviceIdentifier'], base64_decode($response['signature']), $response['publicKey'], OPENSSL_ALGO_SHA512);
$result = openssl_verify($response['deviceIdentifier'], base64_decode((string)$response['signature']), $response['publicKey'], OPENSSL_ALGO_SHA512);
Assert::assertEquals(true, $result, 'Failed to verify the signature');
} else {
/**
Expand Down Expand Up @@ -320,8 +320,8 @@ protected function generateWebPushKeys(): void {
]);
$details = openssl_pkey_get_details($key);
// Build uncompressed public key: 0x04 || x || y (65 bytes)
$x = str_pad($details['ec']['x'], 32, "\0", STR_PAD_LEFT);
$y = str_pad($details['ec']['y'], 32, "\0", STR_PAD_LEFT);
$x = str_pad((string)$details['ec']['x'], 32, "\0", STR_PAD_LEFT);
$y = str_pad((string)$details['ec']['y'], 32, "\0", STR_PAD_LEFT);
$uncompressed = "\x04" . $x . $y;
$this->webPushPublicKey = rtrim(strtr(base64_encode($uncompressed), '+/', '-_'), '=');

Expand Down
3 changes: 3 additions & 0 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac">
<file src="lib/Controller/PushController.php">
<RedundantCast>
<code><![CDATA[(string)$signature]]></code>
</RedundantCast>
<UndefinedClass>
<code><![CDATA[$this->identityProof]]></code>
<code><![CDATA[$this->tokenProvider]]></code>
Expand Down
10 changes: 8 additions & 2 deletions vendor-bin/rector/composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"config": {
"platform": {
"php": "8.1"
"php": "8.2"
},
"sort-packages": true
},
"require-dev": {
"nextcloud/rector": "^0.5",
"nextcloud/rector": "^0.5.1",
"rector/rector": "^2.4"
},
"autoload": {
"psr-4": {
"OCP\\": "vendor-bin/nextcloud-ocp/vendor/nextcloud/ocp/OCP/",
"NCU\\": "vendor-bin/nextcloud-ocp/vendor/nextcloud/ocp/NCU/"
}
}
}
14 changes: 7 additions & 7 deletions vendor-bin/rector/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading