Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(apps): Use constructor property promotion when possible #48790

Merged
merged 2 commits into from
Oct 22, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 3 additions & 5 deletions apps/cloud_federation_api/lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
*/
class Config {

/** @var ICloudFederationProviderManager */
private $cloudFederationProviderManager;

public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) {
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
public function __construct(
private ICloudFederationProviderManager $cloudFederationProviderManager,
) {
}

/**
Expand Down
10 changes: 4 additions & 6 deletions apps/comments/lib/Search/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class Result extends BaseResult {
* @deprecated 20.0.0
*/
public $authorId;
/**
* @deprecated 20.0.0
*/
public string $authorName;
/**
* @deprecated 20.0.0
*/
Expand All @@ -45,7 +41,10 @@ class Result extends BaseResult {
public function __construct(
string $search,
IComment $comment,
string $authorName,
/**
* @deprecated 20.0.0
*/
public string $authorName,
string $path,
) {
parent::__construct(
Expand All @@ -56,7 +55,6 @@ public function __construct(

$this->comment = $this->getRelevantMessagePart($comment->getMessage(), $search);
$this->authorId = $comment->getActorId();
$this->authorName = $authorName;
$this->fileName = basename($path);
$this->path = $this->getVisiblePath($path);
}
Expand Down
17 changes: 4 additions & 13 deletions apps/dav/lib/AppInfo/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@
*/
class PluginManager {

/**
* @var ServerContainer
*/
private $container;

/**
* @var IAppManager
*/
private $appManager;

/**
* App plugins
*
Expand Down Expand Up @@ -74,9 +64,10 @@ class PluginManager {
* @param ServerContainer $container server container for resolving plugin classes
* @param IAppManager $appManager app manager to loading apps and their info
*/
public function __construct(ServerContainer $container, IAppManager $appManager) {
$this->container = $container;
$this->appManager = $appManager;
public function __construct(
private ServerContainer $container,
private IAppManager $appManager,
) {
}

/**
Expand Down
12 changes: 4 additions & 8 deletions apps/dav/lib/Avatars/AvatarHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@

class AvatarHome implements ICollection {

/** @var array */
private $principalInfo;
/** @var IAvatarManager */
private $avatarManager;

/**
* AvatarHome constructor.
*
* @param array $principalInfo
* @param IAvatarManager $avatarManager
*/
public function __construct($principalInfo, IAvatarManager $avatarManager) {
$this->principalInfo = $principalInfo;
$this->avatarManager = $avatarManager;
public function __construct(
private $principalInfo,
private IAvatarManager $avatarManager,
) {
}

public function createFile($name, $data = null) {
Expand Down
19 changes: 6 additions & 13 deletions apps/dav/lib/Avatars/AvatarNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
use Sabre\DAV\File;

class AvatarNode extends File {
private $ext;
private $size;
private $avatar;

/**
* AvatarNode constructor.
*
* @param integer $size
* @param string $ext
* @param IAvatar $avatar
*/
public function __construct($size, $ext, $avatar) {
$this->size = $size;
$this->ext = $ext;
$this->avatar = $avatar;
public function __construct(
private $size,
private $ext,
private $avatar,
) {
}

/**
Expand Down Expand Up @@ -72,10 +69,6 @@ public function getETag() {
}

public function getLastModified() {
$timestamp = $this->avatar->getFile($this->size)->getMTime();
if (!empty($timestamp)) {
return (int)$timestamp;
}
return $timestamp;
return $this->avatar->getFile($this->size)->getMTime();
}
}
27 changes: 7 additions & 20 deletions apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,20 @@
*/
class BuildReminderIndexBackgroundJob extends QueuedJob {

/** @var IDBConnection */
private $db;

/** @var ReminderService */
private $reminderService;

private LoggerInterface $logger;

/** @var IJobList */
private $jobList;

/** @var ITimeFactory */
private $timeFactory;

/**
* BuildReminderIndexBackgroundJob constructor.
*/
public function __construct(IDBConnection $db,
ReminderService $reminderService,
LoggerInterface $logger,
IJobList $jobList,
ITimeFactory $timeFactory) {
public function __construct(
private IDBConnection $db,
private ReminderService $reminderService,
private LoggerInterface $logger,
private IJobList $jobList,
ITimeFactory $timeFactory,
) {
parent::__construct($timeFactory);
$this->db = $db;
$this->reminderService = $reminderService;
$this->logger = $logger;
$this->jobList = $jobList;
$this->timeFactory = $timeFactory;
}

Expand Down
10 changes: 4 additions & 6 deletions apps/dav/lib/BackgroundJob/CalendarRetentionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
use OCP\BackgroundJob\TimedJob;

class CalendarRetentionJob extends TimedJob {
/** @var RetentionService */
private $service;

public function __construct(ITimeFactory $time,
RetentionService $service) {
public function __construct(
ITimeFactory $time,
private RetentionService $service,
) {
parent::__construct($time);
$this->service = $service;

// Run four times a day
$this->setInterval(6 * 60 * 60);
Expand Down
9 changes: 4 additions & 5 deletions apps/dav/lib/BackgroundJob/CleanupDirectLinksJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
use OCP\BackgroundJob\TimedJob;

class CleanupDirectLinksJob extends TimedJob {
/** @var DirectMapper */
private $mapper;

public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) {
public function __construct(
ITimeFactory $timeFactory,
private DirectMapper $mapper,
) {
parent::__construct($timeFactory);
$this->mapper = $mapper;

// Run once a day at off-peak time
$this->setInterval(24 * 60 * 60);
Expand Down
9 changes: 4 additions & 5 deletions apps/dav/lib/BackgroundJob/CleanupInvitationTokenJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@

class CleanupInvitationTokenJob extends TimedJob {

/** @var IDBConnection */
private $db;

public function __construct(IDBConnection $db, ITimeFactory $time) {
public function __construct(
private IDBConnection $db,
ITimeFactory $time,
) {
parent::__construct($time);
$this->db = $db;

// Run once a day at off-peak time
$this->setInterval(24 * 60 * 60);
Expand Down
19 changes: 7 additions & 12 deletions apps/dav/lib/BackgroundJob/EventReminderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace OCA\DAV\BackgroundJob;

use OC\User\NoUserException;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException;
use OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException;
use OCA\DAV\CalDAV\Reminder\ReminderService;
Expand All @@ -17,18 +18,12 @@

class EventReminderJob extends TimedJob {

/** @var ReminderService */
private $reminderService;

/** @var IConfig */
private $config;

public function __construct(ITimeFactory $time,
ReminderService $reminderService,
IConfig $config) {
public function __construct(
ITimeFactory $time,
private ReminderService $reminderService,
private IConfig $config,
) {
parent::__construct($time);
$this->reminderService = $reminderService;
$this->config = $config;

// Run every 5 minutes
$this->setInterval(5 * 60);
Expand All @@ -38,7 +33,7 @@ public function __construct(ITimeFactory $time,
/**
* @throws ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
* @throws \OC\User\NoUserException
* @throws NoUserException
*/
public function run($argument):void {
if ($this->config->getAppValue('dav', 'sendEventReminders', 'yes') !== 'yes') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@

class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {

/** @var BirthdayService */
private $birthdayService;

/** @var IConfig */
private $config;

public function __construct(ITimeFactory $time,
BirthdayService $birthdayService,
IConfig $config) {
public function __construct(
ITimeFactory $time,
private BirthdayService $birthdayService,
private IConfig $config,
) {
parent::__construct($time);

$this->birthdayService = $birthdayService;
$this->config = $config;
}

public function run($argument) {
Expand Down
17 changes: 7 additions & 10 deletions apps/dav/lib/BackgroundJob/PruneOutdatedSyncTokensJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@

class PruneOutdatedSyncTokensJob extends TimedJob {

private IConfig $config;
private LoggerInterface $logger;
private CardDavBackend $cardDavBackend;
private CalDavBackend $calDavBackend;

public function __construct(ITimeFactory $timeFactory, CalDavBackend $calDavBackend, CardDavBackend $cardDavBackend, IConfig $config, LoggerInterface $logger) {
public function __construct(
ITimeFactory $timeFactory,
private CalDavBackend $calDavBackend,
private CardDavBackend $cardDavBackend,
private IConfig $config,
private LoggerInterface $logger,
) {
parent::__construct($timeFactory);
$this->calDavBackend = $calDavBackend;
$this->cardDavBackend = $cardDavBackend;
$this->config = $config;
$this->logger = $logger;
$this->setInterval(60 * 60 * 24); // One day
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
}
Expand Down
16 changes: 5 additions & 11 deletions apps/dav/lib/BackgroundJob/RegisterRegenerateBirthdayCalendars.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,19 @@

class RegisterRegenerateBirthdayCalendars extends QueuedJob {

/** @var IUserManager */
private $userManager;

/** @var IJobList */
private $jobList;

/**
* RegisterRegenerateBirthdayCalendars constructor.
*
* @param ITimeFactory $time
* @param IUserManager $userManager
* @param IJobList $jobList
*/
public function __construct(ITimeFactory $time,
IUserManager $userManager,
IJobList $jobList) {
public function __construct(
ITimeFactory $time,
private IUserManager $userManager,
private IJobList $jobList,
) {
parent::__construct($time);
$this->userManager = $userManager;
$this->jobList = $jobList;
}

/**
Expand Down
14 changes: 6 additions & 8 deletions apps/dav/lib/BackgroundJob/UploadCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
use Psr\Log\LoggerInterface;

class UploadCleanup extends TimedJob {
private IRootFolder $rootFolder;
private IJobList $jobList;
private LoggerInterface $logger;

public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList, LoggerInterface $logger) {
public function __construct(
ITimeFactory $time,
private IRootFolder $rootFolder,
private IJobList $jobList,
private LoggerInterface $logger,
) {
parent::__construct($time);
$this->rootFolder = $rootFolder;
$this->jobList = $jobList;
$this->logger = $logger;

// Run once a day
$this->setInterval(60 * 60 * 24);
Expand Down
9 changes: 2 additions & 7 deletions apps/dav/lib/BulkUpload/BulkUploadPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@
use Sabre\HTTP\ResponseInterface;

class BulkUploadPlugin extends ServerPlugin {
private Folder $userFolder;
private LoggerInterface $logger;

public function __construct(
Folder $userFolder,
LoggerInterface $logger,
private Folder $userFolder,
private LoggerInterface $logger,
) {
$this->userFolder = $userFolder;
$this->logger = $logger;
}

/**
Expand Down
Loading
Loading