Skip to content

Commit

Permalink
Merge pull request #131 from Kurozora/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kiritokatklian authored May 2, 2021
2 parents e13b949 + 6701afc commit 18be6a7
Show file tree
Hide file tree
Showing 125 changed files with 986 additions and 816 deletions.
8 changes: 4 additions & 4 deletions app/Enums/AnimeRelationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ final class AnimeRelationType extends Enum
*/
public static function getDescription($value): string
{
if ($value == self::SpinOff)
return 'Spin-Off';

return parent::getDescription($value);
return match ($value) {
self::SpinOff => 'Spin-Off',
default => parent::getDescription($value),
};
}
}
7 changes: 6 additions & 1 deletion app/Enums/AstrologicalSign.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ final class AstrologicalSign extends Enum
const Aquarius = 10;
const Pisces = 11;

protected static $signsEmoji = [
/**
* The emojis representing the astrological signs.
*
* @var array
*/
protected static array $signsEmoji = [
'♈️',
'♉️',
'♊️',
Expand Down
28 changes: 11 additions & 17 deletions app/Enums/DayOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ final class DayOfWeek extends Enum
* @param int $value
* @return string
*/
public static function abbreviated(int $value) {
switch ($value) {
case self::Sunday:
return 'SU';
case self::Monday:
return 'MO';
case self::Tuesday:
return 'TU';
case self::Wednesday:
return 'WE';
case self::Thursday:
return 'TH';
case self::Friday:
return 'FR';
case self::Saturday:
return 'SA';
}
public static function abbreviated(int $value): string
{
return match ($value) {
self::Monday => 'MO',
self::Tuesday => 'TU',
self::Wednesday => 'WE',
self::Thursday => 'TH',
self::Friday => 'FR',
self::Saturday => 'SA',
default => 'SU',
};
}
}
20 changes: 8 additions & 12 deletions app/Enums/FeedVoteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ final class FeedVoteType extends Enum
* @return FeedVoteType
*/
public function next(): FeedVoteType {
switch($this) {
case self::UnHeart():
return self::Heart();
default:
return self::UnHeart();
}
return match ($this) {
self::UnHeart() => self::Heart(),
default => self::UnHeart(),
};
}

/**
Expand All @@ -33,11 +31,9 @@ public function next(): FeedVoteType {
* @return FeedVoteType
*/
public function previous(): FeedVoteType {
switch($this) {
case self::Heart():
return self::UnHeart();
default:
return self::Heart();
}
return match ($this) {
self::Heart() => self::UnHeart(),
default => self::Heart(),
};
}
}
20 changes: 8 additions & 12 deletions app/Enums/ForumsVoteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ final class ForumsVoteType extends Enum
* @return ForumsVoteType
*/
public function next(): ForumsVoteType {
switch($this) {
case self::Dislike():
return self::Like();
default:
return self::Dislike();
}
return match ($this) {
self::Dislike() => self::Like(),
default => self::Dislike(),
};
}

/**
Expand All @@ -34,11 +32,9 @@ public function next(): ForumsVoteType {
* @return ForumsVoteType
*/
public function previous(): ForumsVoteType {
switch($this) {
case self::Like():
return self::Dislike();
default:
return self::Like();
}
return match ($this) {
self::Like() => self::Dislike(),
default => self::Like(),
};
}
}
22 changes: 12 additions & 10 deletions app/Enums/UserActivityStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ final class UserActivityStatus extends Enum
const SeenRecently = 1;
const Offline = 2;

/**
* Get the description for an enum value
*
* @param mixed $value
* @return string
*/
public static function getDescription($value): string
{
switch($value) {
case self::Online:
return 'Online';
case self::SeenRecently:
return 'Seen Recently';
case self::Offline:
return 'Offline';
}

return parent::getDescription($value);
return match ($value) {
self::Online => 'Online',
self::SeenRecently => 'Seen Recently',
self::Offline => 'Offline',
default => parent::getDescription($value),
};
}
}
11 changes: 6 additions & 5 deletions app/Enums/UserLibraryStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ final class UserLibraryStatus extends Enum
*/
static function getDescription($value): string
{
if ($value === self::OnHold)
return 'On-Hold';

return parent::getDescription($value);
return match ($value) {
self::OnHold => 'On-Hold',
default => parent::getDescription($value),
};
}

/**
* Returns an error displaying the valid library statuses
*
* @return string
*/
static function error() {
static function error(): string
{
return 'Pick a valid library status: ' .
implode(', ', self::getKeys())
;
Expand Down
27 changes: 13 additions & 14 deletions app/Enums/WatchStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class WatchStatus extends Enum
/**
* The bool value of one of the enum members.
*
* @var mixed
* @var ?bool
*/
public $boolValue;
public ?bool $boolValue;

/**
* Construct an Enum instance.
Expand All @@ -40,7 +40,8 @@ final class WatchStatus extends Enum
public function __construct($enumValue)
{
parent::__construct($enumValue);
$this->boolValue = static::getBoolValue($enumValue);

$this->boolValue = WatchStatus::getBoolValue($enumValue);
}

/**
Expand All @@ -49,25 +50,23 @@ public function __construct($enumValue)
* @param bool $bool The boolean value used to instantiate a WatchStatus instance.
* @return WatchStatus
*/
public static function fromBool(bool $bool = null): self
public static function fromBool(bool $bool): self
{
if ($bool == null)
return self::NotWatched();

return $bool ? self::Watched() : self::NotWatched();
}

/**
* Returns the bool or null value of one of the enum values.
*
* @param mixed $enumValue
* @return bool|null
* @param int $enumValue
* @return ?bool
*/
public static function getBoolValue($enumValue)
public static function getBoolValue(int $enumValue): ?bool
{
if ($enumValue === self::Disabled)
return null;

return $enumValue === self::Watched;
return match ($enumValue) {
self::Watched => true,
self::NotWatched => false,
default => null,
};
}
}
4 changes: 2 additions & 2 deletions app/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function __construct()
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
* @return Channel|Channel[]
*/
public function broadcastOn()
public function broadcastOn(): Channel|array
{
return new PrivateChannel('channel-name');
}
Expand Down
29 changes: 23 additions & 6 deletions app/Events/MALImportFinished.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,35 @@ class MALImportFinished
{
use Dispatchable, SerializesModels;

public $user;
public $results;
public $behavior;
/**
* The user whose MAL import has finished.
*
* @var User
*/
public User $user;

/**
* The results of the import.
*
* @var array
*/
public array $results;

/**
* The behavior of the import.
*
* @var string
*/
public string $behavior;

/**
* Create a new event instance.
*
* @param User $user
* @param $results
* @param $behavior
* @param array $results
* @param string $behavior
*/
public function __construct(User $user, $results, $behavior)
public function __construct(User $user, array $results, string $behavior)
{
$this->user = $user;
$this->results = $results;
Expand Down
6 changes: 3 additions & 3 deletions app/Helpers/AppleAuthKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ private function __construct() { }
/**
* Returns an array of (string) PEM public keys.
*
* @return string[]
* @return array
*/
static function get()
static function get(): array
{
return Cache::remember(self::KEYS_CACHE_KEY, self::CACHE_FOR_SECONDS, function() {
$jwk = json_decode(file_get_contents(self::KEYS_ENDPOINT_URL));
Expand All @@ -46,7 +46,7 @@ static function get()
*
* @return bool
*/
static function areCached()
static function areCached(): bool
{
return Cache::has(self::KEYS_CACHE_KEY);
}
Expand Down
34 changes: 22 additions & 12 deletions app/Helpers/CollectionLikeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class CollectionLikeChecker {
* @param $collection
* @return CollectionLikeChecker
*/
static function retrieve($userID, $collection) {
static function retrieve($userID, $collection): CollectionLikeChecker
{
// Get the type of collection
$collectionType = $collection->getQueueableClass();

Expand All @@ -39,7 +40,8 @@ static function retrieve($userID, $collection) {
*
* @return array
*/
protected function getCollectionIDs() {
protected function getCollectionIDs(): array
{
$IDs = [];

foreach($this->collection as $item)
Expand All @@ -65,10 +67,13 @@ protected function fetchData() {
* @param $item
* @return bool
*/
function hasLiked($item) {
foreach($this->queryData as $queryItem)
if ($queryItem->likeable_id == $item->id && $queryItem->type_id == 'LIKE')
function hasLiked($item): bool
{
foreach($this->queryData as $queryItem) {
if ($queryItem->likeable_id == $item->id && $queryItem->type_id == 'LIKE') {
return true;
}
}

return false;
}
Expand All @@ -79,10 +84,13 @@ function hasLiked($item) {
* @param $item
* @return bool
*/
function hasDisliked($item) {
foreach($this->queryData as $queryItem)
if ($queryItem->likeable_id == $item->id && $queryItem->type_id == 'DISLIKE')
function hasDisliked($item): bool
{
foreach($this->queryData as $queryItem) {
if ($queryItem->likeable_id == $item->id && $queryItem->type_id == 'DISLIKE') {
return true;
}
}

return false;
}
Expand All @@ -96,12 +104,14 @@ function hasDisliked($item) {
* @param $item
* @return int
*/
function getCurrentLikeAction($item) {
if ($this->hasLiked($item))
function getCurrentLikeAction($item): int
{
if ($this->hasLiked($item)) {
return 1;
else if ($this->hasDisliked($item))
} else if ($this->hasDisliked($item)) {
return -1;
else
} else {
return 0;
}
}
}
Loading

0 comments on commit 18be6a7

Please sign in to comment.