diff options
author | Kate <26026535+provokateurin@users.noreply.github.com> | 2024-10-22 12:47:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-22 12:47:45 +0200 |
commit | 070adc1131fcd5476e4a93ebf28be6f409c5a992 (patch) | |
tree | 1e8e2238a22d544c370f1ac804426ed675c5eacf /apps/files_trashbin | |
parent | 582af10e0be1b22ebde0429b756f62107d8e8083 (diff) | |
parent | e8426996f59ab6dbf0c94adee8f410cbd572b11a (diff) | |
download | nextcloud-server-070adc1131fcd5476e4a93ebf28be6f409c5a992.tar.gz nextcloud-server-070adc1131fcd5476e4a93ebf28be6f409c5a992.zip |
Merge pull request #48790 from nextcloud/refactor/apps/constructor-property-promotion
Diffstat (limited to 'apps/files_trashbin')
19 files changed, 78 insertions, 195 deletions
diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php index b5980b27c0a..4e1c1b95fde 100644 --- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php +++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php @@ -17,23 +17,15 @@ use OCP\IUser; use OCP\IUserManager; class ExpireTrash extends TimedJob { - private IConfig $config; - private Expiration $expiration; - private IUserManager $userManager; - public function __construct( - IConfig $config, - IUserManager $userManager, - Expiration $expiration, + private IConfig $config, + private IUserManager $userManager, + private Expiration $expiration, ITimeFactory $time, ) { parent::__construct($time); // Run once per 30 minutes $this->setInterval(60 * 30); - - $this->config = $config; - $this->userManager = $userManager; - $this->expiration = $expiration; } /** diff --git a/apps/files_trashbin/lib/Command/Expire.php b/apps/files_trashbin/lib/Command/Expire.php index b31e540ee38..f526438600e 100644 --- a/apps/files_trashbin/lib/Command/Expire.php +++ b/apps/files_trashbin/lib/Command/Expire.php @@ -14,15 +14,11 @@ class Expire implements ICommand { use FileAccess; /** - * @var string - */ - private $user; - - /** * @param string $user */ - public function __construct($user) { - $this->user = $user; + public function __construct( + private $user, + ) { } public function handle() { diff --git a/apps/files_trashbin/lib/Command/ExpireTrash.php b/apps/files_trashbin/lib/Command/ExpireTrash.php index c27d74c0c26..37b35689666 100644 --- a/apps/files_trashbin/lib/Command/ExpireTrash.php +++ b/apps/files_trashbin/lib/Command/ExpireTrash.php @@ -21,25 +21,14 @@ use Symfony\Component\Console\Output\OutputInterface; class ExpireTrash extends Command { /** - * @var Expiration - */ - private $expiration; - - /** - * @var IUserManager - */ - private $userManager; - - /** * @param IUserManager|null $userManager * @param Expiration|null $expiration */ - public function __construct(?IUserManager $userManager = null, - ?Expiration $expiration = null) { + public function __construct( + private ?IUserManager $userManager = null, + private ?Expiration $expiration = null, + ) { parent::__construct(); - - $this->userManager = $userManager; - $this->expiration = $expiration; } protected function configure() { diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php index 81b59543a4e..cb4e7f97ecd 100644 --- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php +++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php @@ -32,17 +32,6 @@ class RestoreAllFiles extends Base { 'all' => self::SCOPE_ALL ]; - /** @var IUserManager */ - protected $userManager; - - /** @var IRootFolder */ - protected $rootFolder; - - /** @var \OCP\IDBConnection */ - protected $dbConnection; - - protected ITrashManager $trashManager; - /** @var IL10N */ protected $l10n; @@ -53,12 +42,14 @@ class RestoreAllFiles extends Base { * @param ITrashManager $trashManager * @param IFactory $l10nFactory */ - public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection, ITrashManager $trashManager, IFactory $l10nFactory) { + public function __construct( + protected IRootFolder $rootFolder, + protected IUserManager $userManager, + protected IDBConnection $dbConnection, + protected ITrashManager $trashManager, + IFactory $l10nFactory, + ) { parent::__construct(); - $this->userManager = $userManager; - $this->rootFolder = $rootFolder; - $this->dbConnection = $dbConnection; - $this->trashManager = $trashManager; $this->l10n = $l10nFactory->get('files_trashbin'); } diff --git a/apps/files_trashbin/lib/Command/Size.php b/apps/files_trashbin/lib/Command/Size.php index 60b1f0981fa..11699ce25ea 100644 --- a/apps/files_trashbin/lib/Command/Size.php +++ b/apps/files_trashbin/lib/Command/Size.php @@ -19,20 +19,12 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Size extends Base { - private $config; - private $userManager; - private $commandBus; - public function __construct( - IConfig $config, - IUserManager $userManager, - IBus $commandBus, + private IConfig $config, + private IUserManager $userManager, + private IBus $commandBus, ) { parent::__construct(); - - $this->config = $config; - $this->userManager = $userManager; - $this->commandBus = $commandBus; } protected function configure() { diff --git a/apps/files_trashbin/lib/Controller/PreviewController.php b/apps/files_trashbin/lib/Controller/PreviewController.php index 78d501b68d4..d376ce80fda 100644 --- a/apps/files_trashbin/lib/Controller/PreviewController.php +++ b/apps/files_trashbin/lib/Controller/PreviewController.php @@ -25,42 +25,17 @@ use OCP\IRequest; use OCP\IUserSession; class PreviewController extends Controller { - /** @var IRootFolder */ - private $rootFolder; - - /** @var ITrashManager */ - private $trashManager; - - /** @var IUserSession */ - private $userSession; - - /** @var IMimeTypeDetector */ - private $mimeTypeDetector; - - /** @var IPreview */ - private $previewManager; - - /** @var ITimeFactory */ - private $time; - public function __construct( string $appName, IRequest $request, - IRootFolder $rootFolder, - ITrashManager $trashManager, - IUserSession $userSession, - IMimeTypeDetector $mimeTypeDetector, - IPreview $previewManager, - ITimeFactory $time, + private IRootFolder $rootFolder, + private ITrashManager $trashManager, + private IUserSession $userSession, + private IMimeTypeDetector $mimeTypeDetector, + private IPreview $previewManager, + private ITimeFactory $time, ) { parent::__construct($appName, $request); - - $this->trashManager = $trashManager; - $this->rootFolder = $rootFolder; - $this->userSession = $userSession; - $this->mimeTypeDetector = $mimeTypeDetector; - $this->previewManager = $previewManager; - $this->time = $time; } /** diff --git a/apps/files_trashbin/lib/Events/MoveToTrashEvent.php b/apps/files_trashbin/lib/Events/MoveToTrashEvent.php index ff54c67e178..1596315dd20 100644 --- a/apps/files_trashbin/lib/Events/MoveToTrashEvent.php +++ b/apps/files_trashbin/lib/Events/MoveToTrashEvent.php @@ -21,12 +21,10 @@ class MoveToTrashEvent extends Event { /** @var bool */ private $moveToTrashBin; - /** @var Node */ - private $node; - - public function __construct(Node $node) { + public function __construct( + private Node $node, + ) { $this->moveToTrashBin = true; - $this->node = $node; } /** diff --git a/apps/files_trashbin/lib/Expiration.php b/apps/files_trashbin/lib/Expiration.php index 26826f63931..ed5d62aa294 100644 --- a/apps/files_trashbin/lib/Expiration.php +++ b/apps/files_trashbin/lib/Expiration.php @@ -15,9 +15,6 @@ class Expiration { public const DEFAULT_RETENTION_OBLIGATION = 30; public const NO_OBLIGATION = -1; - /** @var ITimeFactory */ - private $timeFactory; - /** @var string */ private $retentionObligation; @@ -30,8 +27,10 @@ class Expiration { /** @var bool */ private $canPurgeToSaveSpace; - public function __construct(IConfig $config, ITimeFactory $timeFactory) { - $this->timeFactory = $timeFactory; + public function __construct( + IConfig $config, + private ITimeFactory $timeFactory, + ) { $this->setRetentionObligation($config->getSystemValue('trashbin_retention_obligation', 'auto')); } diff --git a/apps/files_trashbin/lib/Listener/EventListener.php b/apps/files_trashbin/lib/Listener/EventListener.php index 7568524e853..63ecc9c81f7 100644 --- a/apps/files_trashbin/lib/Listener/EventListener.php +++ b/apps/files_trashbin/lib/Listener/EventListener.php @@ -19,10 +19,9 @@ use OCP\User\Events\BeforeUserDeletedEvent; /** @template-implements IEventListener<NodeWrittenEvent|BeforeUserDeletedEvent|BeforeFileSystemSetupEvent> */ class EventListener implements IEventListener { - private ?string $userId; - - public function __construct(?string $userId = null) { - $this->userId = $userId; + public function __construct( + private ?string $userId = null, + ) { } public function handle(Event $event): void { diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrash.php b/apps/files_trashbin/lib/Sabre/AbstractTrash.php index e46a7d5d638..343c8b6be6d 100644 --- a/apps/files_trashbin/lib/Sabre/AbstractTrash.php +++ b/apps/files_trashbin/lib/Sabre/AbstractTrash.php @@ -14,15 +14,10 @@ use OCP\Files\FileInfo; use OCP\IUser; abstract class AbstractTrash implements ITrash { - /** @var ITrashItem */ - protected $data; - - /** @var ITrashManager */ - protected $trashManager; - - public function __construct(ITrashManager $trashManager, ITrashItem $data) { - $this->trashManager = $trashManager; - $this->data = $data; + public function __construct( + protected ITrashManager $trashManager, + protected ITrashItem $data, + ) { } public function getFilename(): string { diff --git a/apps/files_trashbin/lib/Sabre/RootCollection.php b/apps/files_trashbin/lib/Sabre/RootCollection.php index 11c44266c3d..06b0ffbeba2 100644 --- a/apps/files_trashbin/lib/Sabre/RootCollection.php +++ b/apps/files_trashbin/lib/Sabre/RootCollection.php @@ -15,17 +15,12 @@ use Sabre\DAVACL\AbstractPrincipalCollection; use Sabre\DAVACL\PrincipalBackend; class RootCollection extends AbstractPrincipalCollection { - /** @var ITrashManager */ - private $trashManager; - public function __construct( - ITrashManager $trashManager, + private ITrashManager $trashManager, PrincipalBackend\BackendInterface $principalBackend, IConfig $config, ) { parent::__construct($principalBackend, 'principals/users'); - - $this->trashManager = $trashManager; $this->disableListing = !$config->getSystemValue('debug', false); } diff --git a/apps/files_trashbin/lib/Sabre/TrashHome.php b/apps/files_trashbin/lib/Sabre/TrashHome.php index 2c7fe749be5..fc291c76f17 100644 --- a/apps/files_trashbin/lib/Sabre/TrashHome.php +++ b/apps/files_trashbin/lib/Sabre/TrashHome.php @@ -15,23 +15,11 @@ use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; class TrashHome implements ICollection { - /** @var ITrashManager */ - private $trashManager; - - /** @var array */ - private $principalInfo; - - /** @var IUser */ - private $user; - public function __construct( - array $principalInfo, - ITrashManager $trashManager, - IUser $user, + private array $principalInfo, + private ITrashManager $trashManager, + private IUser $user, ) { - $this->principalInfo = $principalInfo; - $this->trashManager = $trashManager; - $this->user = $user; } public function delete() { diff --git a/apps/files_trashbin/lib/Sabre/TrashRoot.php b/apps/files_trashbin/lib/Sabre/TrashRoot.php index e2661ccdec7..d6a4f5cc67e 100644 --- a/apps/files_trashbin/lib/Sabre/TrashRoot.php +++ b/apps/files_trashbin/lib/Sabre/TrashRoot.php @@ -19,15 +19,10 @@ use Sabre\DAV\ICollection; class TrashRoot implements ICollection { - /** @var IUser */ - private $user; - - /** @var ITrashManager */ - private $trashManager; - - public function __construct(IUser $user, ITrashManager $trashManager) { - $this->user = $user; - $this->trashManager = $trashManager; + public function __construct( + private IUser $user, + private ITrashManager $trashManager, + ) { } public function delete() { diff --git a/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php b/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php index 83564d2a783..b2864e9a1c6 100644 --- a/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php +++ b/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php @@ -28,13 +28,9 @@ class TrashbinPlugin extends ServerPlugin { /** @var Server */ private $server; - /** @var IPreview */ - private $previewManager; - public function __construct( - IPreview $previewManager, + private IPreview $previewManager, ) { - $this->previewManager = $previewManager; } public function initialize(Server $server) { diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php index 5703f3be527..a1247eaed78 100644 --- a/apps/files_trashbin/lib/Storage.php +++ b/apps/files_trashbin/lib/Storage.php @@ -20,11 +20,6 @@ use Psr\Log\LoggerInterface; class Storage extends Wrapper { private string $mountPoint; - private IUserManager $userManager; - private LoggerInterface $logger; - private IEventDispatcher $eventDispatcher; - private IRootFolder $rootFolder; - private ITrashManager $trashManager; private bool $trashEnabled = true; /** @@ -33,18 +28,13 @@ class Storage extends Wrapper { */ public function __construct( $parameters, - ?ITrashManager $trashManager = null, - ?IUserManager $userManager = null, - ?LoggerInterface $logger = null, - ?IEventDispatcher $eventDispatcher = null, - ?IRootFolder $rootFolder = null, + private ?ITrashManager $trashManager = null, + private ?IUserManager $userManager = null, + private ?LoggerInterface $logger = null, + private ?IEventDispatcher $eventDispatcher = null, + private ?IRootFolder $rootFolder = null, ) { $this->mountPoint = $parameters['mountPoint']; - $this->trashManager = $trashManager; - $this->userManager = $userManager; - $this->logger = $logger; - $this->eventDispatcher = $eventDispatcher; - $this->rootFolder = $rootFolder; parent::__construct($parameters); } diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index f6e5a3830ad..f6791f78a38 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -14,6 +14,7 @@ use OC\Files\Filesystem; use OC\Files\Node\NonExistingFile; use OC\Files\Node\NonExistingFolder; use OC\Files\View; +use OC\User\NoUserException; use OC_User; use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\Command\Expire; @@ -67,7 +68,7 @@ class Trashbin implements IEventListener { * * @param string $filename * @return array - * @throws \OC\User\NoUserException + * @throws NoUserException */ public static function getUidAndFilename($filename) { $uid = Filesystem::getOwner($filename); diff --git a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php index b58efbb38a6..baff1ef6032 100644 --- a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php +++ b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php @@ -32,20 +32,11 @@ class TrashbinMigrator implements IMigrator, ISizeEstimationMigrator { protected const PATH_FILES_FOLDER = Application::APP_ID . '/files'; protected const PATH_LOCATIONS_FILE = Application::APP_ID . '/locations.json'; - protected IRootFolder $root; - - protected IDBConnection $dbc; - - protected IL10N $l10n; - public function __construct( - IRootFolder $rootFolder, - IDBConnection $dbc, - IL10N $l10n, + protected IRootFolder $root, + protected IDBConnection $dbc, + protected IL10N $l10n, ) { - $this->root = $rootFolder; - $this->dbc = $dbc; - $this->l10n = $l10n; } /** diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 0d56ecf0a71..ec01e16b16a 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -55,12 +55,12 @@ class StorageTest extends \Test\TestCase { private $user; /** - * @var \OC\Files\View + * @var View */ private $rootView; /** - * @var \OC\Files\View + * @var View */ private $userView; @@ -502,7 +502,7 @@ class StorageTest extends \Test\TestCase { */ public function testSingleStorageDeleteFileFail(): void { /** - * @var \OC\Files\Storage\Temporary | \PHPUnit\Framework\MockObject\MockObject $storage + * @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') ->setConstructorArgs([[]]) @@ -539,7 +539,7 @@ class StorageTest extends \Test\TestCase { */ public function testSingleStorageDeleteFolderFail(): void { /** - * @var \OC\Files\Storage\Temporary | \PHPUnit\Framework\MockObject\MockObject $storage + * @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */ $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') ->setConstructorArgs([[]]) diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php index 72aa9b280e8..ea9abedd144 100644 --- a/apps/files_trashbin/tests/TrashbinTest.php +++ b/apps/files_trashbin/tests/TrashbinTest.php @@ -18,6 +18,7 @@ use OCA\Files_Trashbin\Helper; use OCA\Files_Trashbin\Trashbin; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Constants; +use OCP\Files\FileInfo; use OCP\IConfig; use OCP\Share\IShare; @@ -41,7 +42,7 @@ class TrashbinTest extends \Test\TestCase { private static $trashBinStatus; /** - * @var \OC\Files\View + * @var View */ private $rootView; @@ -159,7 +160,7 @@ class TrashbinTest extends \Test\TestCase { */ public function testExpireOldFiles(): void { - /** @var \OCP\AppFramework\Utility\ITimeFactory $time */ + /** @var ITimeFactory $time */ $time = \OC::$server->query(ITimeFactory::class); $currentTime = $time->getTime(); $expireAt = $currentTime - 2 * 24 * 60 * 60; @@ -282,7 +283,7 @@ class TrashbinTest extends \Test\TestCase { /** * verify that the array contains the expected results * - * @param OCP\Files\FileInfo[] $result + * @param FileInfo[] $result * @param string[] $expected */ private function verifyArray($result, $expected) { @@ -303,7 +304,7 @@ class TrashbinTest extends \Test\TestCase { } /** - * @param OCP\Files\FileInfo[] $files + * @param FileInfo[] $files * @param string $trashRoot * @param integer $expireDate */ @@ -374,7 +375,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFile = $filesInTrash[0]; $this->assertTrue( @@ -407,7 +408,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFile = $filesInTrash[0]; $this->assertTrue( @@ -440,7 +441,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFolder = $filesInTrash[0]; $this->assertTrue( @@ -473,7 +474,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFile = $filesInTrash[0]; $this->assertTrue( @@ -507,7 +508,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFile = $filesInTrash[0]; // delete source folder @@ -543,7 +544,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFile = $filesInTrash[0]; // create another file @@ -584,7 +585,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFile = $filesInTrash[0]; // create another file @@ -638,7 +639,7 @@ class TrashbinTest extends \Test\TestCase { $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); - /** @var \OCP\Files\FileInfo */ + /** @var FileInfo */ $trashedFile = $filesInTrash[0]; // delete source folder @@ -689,7 +690,7 @@ class TrashbinTest extends \Test\TestCase { class TrashbinForTesting extends Trashbin { /** - * @param OCP\Files\FileInfo[] $files + * @param FileInfo[] $files * @param integer $limit */ public function dummyDeleteExpiredFiles($files) { @@ -698,7 +699,7 @@ class TrashbinForTesting extends Trashbin { } /** - * @param OCP\Files\FileInfo[] $files + * @param FileInfo[] $files * @param integer $availableSpace */ public function dummyDeleteFiles($files, $availableSpace) { |