Skip to content

Commit

Permalink
refactor: Use constructor property promotion where possible
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Oct 18, 2024
1 parent 599bc02 commit 2d25cfd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 23 deletions.
9 changes: 2 additions & 7 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\IScanner;
use OCP\Files\Storage\IConstructableStorage;
use OCP\Files\Storage\IStorage;

class ACLStorageWrapper extends Wrapper implements IConstructableStorage {
private ACLManager $aclManager;
Expand Down Expand Up @@ -176,10 +175,8 @@ public function writeStream(string $path, $stream, ?int $size = null): int {

/**
* @inheritDoc
* @param string $path
* @param ?IStorage $storage
*/
public function getCache($path = '', $storage = null): ICache {
public function getCache(string $path = '', ?\OCP\Files\Storage\IStorage $storage = null): ICache {
if (!$storage) {
$storage = $this;
}
Expand All @@ -202,10 +199,8 @@ public function getMetaData(string $path): ?array {

/**
* @inheritDoc
* @param string $path
* @param ?IStorage $storage
*/
public function getScanner($path = '', $storage = null): IScanner {
public function getScanner(string $path = '', ?\OCP\Files\Storage\IStorage $storage = null): IScanner {
if (!$storage) {
$storage = $this->storage;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Mount/GroupFolderStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public function getOwner(string $path): string|false {

/**
* @inheritDoc
* @param string $path
* @param ?IStorage $storage
*/
public function getCache($path = '', $storage = null): ICache {
public function getCache(string $path = '', ?\OCP\Files\Storage\IStorage $storage = null): ICache {
if ($this->cache) {
return $this->cache;
}
Expand Down
7 changes: 1 addition & 6 deletions lib/Mount/RootPermissionsMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Constants;
use OCP\Files\Cache\ICache;
use OCP\Files\Storage\IStorage;

/**
* Permissions mask that only masks the root of the storage
Expand Down Expand Up @@ -88,11 +87,7 @@ public function getMetaData(string $path): ?array {
return $data;
}

/**
* @param string $path
* @param ?IStorage $storage
*/
public function getCache($path = '', $storage = null): ICache {
public function getCache(string $path = '', ?\OCP\Files\Storage\IStorage $storage = null): ICache {
if (!$storage) {
$storage = $this;
}
Expand Down
7 changes: 2 additions & 5 deletions lib/Trash/GroupTrashItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@
use OCP\IUser;

class GroupTrashItem extends TrashItem {
private string $internalOriginalLocation;

public function __construct(
ITrashBackend $backend,
string $originalLocation,
private string $internalOriginalLocation,
int $deletedTime,
string $trashPath,
FileInfo $fileInfo,
IUser $user,
private string $mountPoint,
?IUser $deletedBy,
) {
$this->internalOriginalLocation = $originalLocation;
parent::__construct($backend, $this->mountPoint . '/' . $originalLocation, $deletedTime, $trashPath, $fileInfo, $user, $deletedBy);
parent::__construct($backend, $this->mountPoint . '/' . $this->internalOriginalLocation, $deletedTime, $trashPath, $fileInfo, $user, $deletedBy);
}

public function getInternalOriginalLocation(): string {
Expand Down
6 changes: 5 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;

return RectorConfig::configure()
->withPaths([
Expand All @@ -20,4 +21,7 @@
typeDeclarations: true,
)->withPhpSets(
php81: true,
);
)->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
'inline_public' => true,
'rename_property' => true,
]);
2 changes: 1 addition & 1 deletion tests/Folder/FolderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public function testQuotaDefaultValue(): void {
$this->config->expects($this->any())
->method('getSystemValueInt')
->with('groupfolders.quota.default', FileInfo::SPACE_UNLIMITED)
->willReturnCallback(function () use (&$exponent) {
->willReturnCallback(function () use (&$exponent): int {
return 1024 ** ($exponent++);
});

Expand Down

0 comments on commit 2d25cfd

Please sign in to comment.