diff options
author | Joas Schilling <coding@schilljs.com> | 2018-07-26 13:19:51 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-07-26 13:20:50 +0300 |
commit | 7caaebb1bad6743d1f3d613ded88c6fd269f77b4 (patch) | |
tree | 19a91d011fdc69c6e62d249da4aa8f110456e79f /lib/Activity | |
parent | c1d4482d507e44929037b3495cccd63fa5ba0d38 (diff) |
PHP7 for OCA\Spreed\Activity
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Activity')
-rw-r--r-- | lib/Activity/Hooks.php | 7 | ||||
-rw-r--r-- | lib/Activity/Provider/Base.php | 16 | ||||
-rw-r--r-- | lib/Activity/Provider/Call.php | 15 | ||||
-rw-r--r-- | lib/Activity/Provider/Invitation.php | 5 | ||||
-rw-r--r-- | lib/Activity/Setting.php | 15 |
5 files changed, 30 insertions, 28 deletions
diff --git a/lib/Activity/Hooks.php b/lib/Activity/Hooks.php index 60b597bd3..7f48924e9 100644 --- a/lib/Activity/Hooks.php +++ b/lib/Activity/Hooks.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> * @@ -70,7 +71,7 @@ class Hooks { * @param Room $room * @return bool True if activity was generated, false otherwise */ - public function generateCallActivity(Room $room) { + public function generateCallActivity(Room $room): bool { $activeSince = $room->getActiveSince(); if (!$activeSince instanceof \DateTime || $room->hasSessionsInCall()) { return false; @@ -78,9 +79,9 @@ class Hooks { $duration = $this->timeFactory->getTime() - $activeSince->getTimestamp(); $participants = $room->getParticipants($activeSince->getTimestamp()); - $userIds = array_map('strval', array_keys($participants['users'])); + $userIds = array_map('\strval', array_keys($participants['users'])); - if (empty($userIds) || (count($userIds) === 1 && $room->getActiveGuests() === 0)) { + if (empty($userIds) || (\count($userIds) === 1 && $room->getActiveGuests() === 0)) { // Single user pinged or guests only => no activity $room->resetActiveSince(); return false; diff --git a/lib/Activity/Provider/Base.php b/lib/Activity/Provider/Base.php index c76f1bb8e..aaa033c63 100644 --- a/lib/Activity/Provider/Base.php +++ b/lib/Activity/Provider/Base.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> * @@ -21,7 +22,6 @@ namespace OCA\Spreed\Activity\Provider; -use OCA\Spreed\Exceptions\RoomNotFoundException; use OCA\Spreed\Manager; use OCA\Spreed\Room; use OCP\Activity\IEvent; @@ -73,9 +73,9 @@ abstract class Base implements IProvider { * @return IEvent * @throws \InvalidArgumentException */ - public function preParse(IEvent $event) { + public function preParse(IEvent $event): IEvent { if ($event->getApp() !== 'spreed') { - throw new \InvalidArgumentException(); + throw new \InvalidArgumentException('Wrong app'); } if ($this->activityManager->getRequirePNG()) { @@ -93,7 +93,7 @@ abstract class Base implements IProvider { * @param array $parameters * @throws \InvalidArgumentException */ - protected function setSubjects(IEvent $event, $subject, array $parameters) { + protected function setSubjects(IEvent $event, string $subject, array $parameters) { $placeholders = $replacements = []; foreach ($parameters as $placeholder => $parameter) { $placeholders[] = '{' . $placeholder . '}'; @@ -109,7 +109,7 @@ abstract class Base implements IProvider { * @param Room $room * @return array */ - protected function getRoom(IL10N $l, Room $room) { + protected function getRoom(IL10N $l, Room $room): array { switch ($room->getType()) { case Room::ONE_TO_ONE_CALL: $stringType = 'one2one'; @@ -136,7 +136,7 @@ abstract class Base implements IProvider { * @param int $roomId * @return array */ - protected function getFormerRoom(IL10N $l, $roomId) { + protected function getFormerRoom(IL10N $l, int $roomId): array { return [ 'type' => 'call', 'id' => $roomId, @@ -149,7 +149,7 @@ abstract class Base implements IProvider { * @param string $uid * @return array */ - protected function getUser($uid) { + protected function getUser(string $uid): array { if (!isset($this->displayNames[$uid])) { $this->displayNames[$uid] = $this->getDisplayName($uid); } @@ -165,7 +165,7 @@ abstract class Base implements IProvider { * @param string $uid * @return string */ - protected function getDisplayName($uid) { + protected function getDisplayName(string $uid): string { $user = $this->userManager->get($uid); if ($user instanceof IUser) { return $user->getDisplayName(); diff --git a/lib/Activity/Provider/Call.php b/lib/Activity/Provider/Call.php index 81134bfff..28beed342 100644 --- a/lib/Activity/Provider/Call.php +++ b/lib/Activity/Provider/Call.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> * @@ -21,8 +22,6 @@ namespace OCA\Spreed\Activity\Provider; -use OCA\Spreed\Exceptions\RoomNotFoundException; -use OCA\Spreed\Room; use OCP\Activity\IEvent; use OCP\IL10N; @@ -36,7 +35,7 @@ class Call extends Base { * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parse($language, IEvent $event, IEvent $previousEvent = null) { + public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { $event = parent::preParse($event); if ($event->getSubject() === 'call') { @@ -51,17 +50,17 @@ class Call extends Base { // } $result = $this->parseCall($event, $l); - $result['subject'] .= ' ' . $this->getDuration($l, $parameters['duration']); + $result['subject'] .= ' ' . $this->getDuration($l, (int) $parameters['duration']); // $result['params']['call'] = $roomParameter; $this->setSubjects($event, $result['subject'], $result['params']); } else { - throw new \InvalidArgumentException(); + throw new \InvalidArgumentException('Wrong subject'); } return $event; } - protected function getDuration(IL10N $l, $seconds) { + protected function getDuration(IL10N $l, int $seconds): string { $hours = floor($seconds / 3600); $seconds %= 3600; $minutes = floor($seconds / 60); @@ -76,7 +75,7 @@ class Call extends Base { return $l->t('(Duration %s)', $duration); } - protected function parseCall(IEvent $event, IL10N $l) { + protected function parseCall(IEvent $event, IL10N $l): array { $parameters = $event->getSubjectParameters(); $currentUser = array_search($this->activityManager->getCurrentUserId(), $parameters['users'], true); @@ -86,7 +85,7 @@ class Call extends Base { unset($parameters['users'][$currentUser]); sort($parameters['users']); - $numUsers = count($parameters['users']); + $numUsers = \count($parameters['users']); $displayedUsers = $numUsers; switch ($numUsers) { case 0: diff --git a/lib/Activity/Provider/Invitation.php b/lib/Activity/Provider/Invitation.php index 3f045496e..744df6c71 100644 --- a/lib/Activity/Provider/Invitation.php +++ b/lib/Activity/Provider/Invitation.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> * @@ -34,7 +35,7 @@ class Invitation extends Base { * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parse($language, IEvent $event, IEvent $previousEvent = null) { + public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { $event = parent::preParse($event); if ($event->getSubject() === 'invitation') { @@ -53,7 +54,7 @@ class Invitation extends Base { 'call' => $roomParameter, ]); } else { - throw new \InvalidArgumentException(); + throw new \InvalidArgumentException('Wrong subject'); } return $event; diff --git a/lib/Activity/Setting.php b/lib/Activity/Setting.php index 4845a25d0..e79d37346 100644 --- a/lib/Activity/Setting.php +++ b/lib/Activity/Setting.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> * @@ -41,7 +42,7 @@ class Setting implements ISetting { * @return string Lowercase a-z and underscore only identifier * @since 11.0.0 */ - public function getIdentifier() { + public function getIdentifier(): string { return 'spreed'; } @@ -49,7 +50,7 @@ class Setting implements ISetting { * @return string A translated string * @since 11.0.0 */ - public function getName() { + public function getName(): string { return $this->l->t('You were invited to a <strong>talk</strong> room or had a <strong>call</strong>'); } @@ -59,7 +60,7 @@ class Setting implements ISetting { * priority values. It is required to return a value between 0 and 100. * @since 11.0.0 */ - public function getPriority() { + public function getPriority(): int { return 51; } @@ -67,7 +68,7 @@ class Setting implements ISetting { * @return bool True when the option can be changed for the stream * @since 11.0.0 */ - public function canChangeStream() { + public function canChangeStream(): bool { return true; } @@ -75,7 +76,7 @@ class Setting implements ISetting { * @return bool True when the option can be changed for the stream * @since 11.0.0 */ - public function isDefaultEnabledStream() { + public function isDefaultEnabledStream(): bool { return true; } @@ -83,7 +84,7 @@ class Setting implements ISetting { * @return bool True when the option can be changed for the mail * @since 11.0.0 */ - public function canChangeMail() { + public function canChangeMail(): bool { return true; } @@ -91,7 +92,7 @@ class Setting implements ISetting { * @return bool True when the option can be changed for the stream * @since 11.0.0 */ - public function isDefaultEnabledMail() { + public function isDefaultEnabledMail(): bool { return false; } } |