Skip to content

Commit

Permalink
Increased PHPStan level from 5 to 6
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAotD committed Jan 2, 2025
1 parent e7e2fb8 commit b6fdd2a
Show file tree
Hide file tree
Showing 51 changed files with 413 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

trait IndexConfiguration
{
/**
* @return array<string, array<string, mixed>>
*/
protected function getIndexSettings(): array
{
return [
Expand Down Expand Up @@ -57,6 +60,9 @@ protected function getIndexSettings(): array
];
}

/**
* @return array<string, array<string, mixed>>
*/
protected function getIndexMappings(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Elastic\Elasticsearch\Client;
use Illuminate\Console\Command;

class CreateIndexCommand extends Command
final class CreateIndexCommand extends Command
{
use IndexConfiguration;

Expand Down
74 changes: 0 additions & 74 deletions src/app/DTO/Service/Anime/AnimeDTO.php

This file was deleted.

53 changes: 53 additions & 0 deletions src/app/DTO/Service/Anime/CreateAnimeDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace App\DTO\Service\Anime;

use App\Enums\Anime\StatusEnum;
use App\Enums\Anime\TypeEnum;
use Illuminate\Contracts\Support\Arrayable;

/**
* @template-implements Arrayable<string, mixed>
*/
final readonly class CreateAnimeDTO implements Arrayable
{
/**
* @param array<array{url: string}> $urls
* @param array<array{name: string}> $synonyms
* @param list<string> $voiceActing Array of voice acting ids
* @param list<string> $genres Array of genre ids
*/
public function __construct(
public string $title,
public int $year,
public array $urls,
public ?TypeEnum $type = TypeEnum::SHOW,
public ?StatusEnum $status = StatusEnum::ANNOUNCE,
public float $rating = 0.0,
public int $episodes = 0,
public ?string $image = null,
public array $synonyms = [],
public array $voiceActing = [],
public array $genres = [],
) {
}

/**
* Get the instance as an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
return [
'title' => $this->title,
'type' => $this->type,
'status' => $this->status,
'rating' => $this->rating,
'episodes' => $this->episodes,
'year' => $this->year,
];
}
}
74 changes: 74 additions & 0 deletions src/app/DTO/Service/Anime/UpdateAnimeDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace App\DTO\Service\Anime;

use App\DTO\Contracts\FromArray;
use App\Enums\Anime\StatusEnum;
use App\Enums\Anime\TypeEnum;
use Illuminate\Contracts\Support\Arrayable;

/**
* @template-implements Arrayable<string, mixed>
*/
final readonly class UpdateAnimeDTO implements FromArray, Arrayable
{
/**
* @param array<array{url: string}> $urls
* @param array<array{name: string}> $synonyms
* @param list<string> $voiceActing Array of voice acting ids
* @param list<string> $genres Array of genre ids
*/
public function __construct(
public ?string $title = null,
public ?TypeEnum $type = null,
public ?StatusEnum $status = StatusEnum::ANNOUNCE,
public ?float $rating = null,
public ?int $episodes = null,
public ?int $year = null,
public array $urls = [],
public ?string $image = null,
public array $synonyms = [],
public array $voiceActing = [],
public array $genres = [],
) {
}

/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): self
{
return new self(
title : $data['title'] ?? null,
type : TypeEnum::from($data['type'] ?? null),
status : StatusEnum::from($data['status'] ?? null),
rating : $data['rating'] ?? null,
episodes : $data['episodes'] ?? null,
year : isset($data['year']) ? (int) $data['year'] : null,
urls : $data['urls'] ?? [],
image : $data['image'] ?? null,
synonyms : $data['synonyms'] ?? [],
voiceActing: $data['voice_acting'] ?? [],
genres : $data['genres'] ?? [],
);
}

/**
* Get the instance as an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
return array_filter([
'title' => $this->title,
'type' => $this->type,
'status' => $this->status,
'rating' => $this->rating,
'episodes' => $this->episodes,
'year' => $this->year,
]);
}
}
19 changes: 14 additions & 5 deletions src/app/DTO/Service/Elasticsearch/Anime/AnimeFacetDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
use App\DTO\Contracts\FromArray;
use Illuminate\Contracts\Support\Arrayable;

/**
* @template-implements Arrayable<string, array<string, int>>
*/
final readonly class AnimeFacetDTO implements FromArray, Arrayable
{
/**
* @param array{min: int, max: int} $years
* @param array<string, int> $types
* @param array<string, int> $statuses
* @param array<string, int> $genres
* @param array<string, int> $voiceActing
*/
public function __construct(
public array $years,
public array $types,
Expand All @@ -23,15 +33,14 @@ public function __construct(
*/
public static function fromArray(array $data): self
{
$facets = [];
$aggregations = $data['aggregations'];
$facets = [];

$facets['years'] = [
'min' => (int) $aggregations['min_year']['value'],
'max' => (int) $aggregations['max_year']['value'],
'min' => (int) $data['min_year']['value'],
'max' => (int) $data['max_year']['value'],
];

foreach ($aggregations as $facet => $aggregation) {
foreach ($data as $facet => $aggregation) {
if (isset($aggregation['buckets'])) {
$facets[$facet] = array_reduce($aggregation['buckets'], function (array $accumulator, array $bucket) {
$accumulator[$bucket['key']] = $bucket['doc_count'];
Expand Down
3 changes: 3 additions & 0 deletions src/app/DTO/Service/Invitation/InvitationDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use App\Enums\Invitation\StatusEnum;
use Illuminate\Contracts\Support\Arrayable;

/**
* @template-implements Arrayable<string, mixed>
*/
final readonly class InvitationDTO implements Arrayable
{
public function __construct(
Expand Down
5 changes: 5 additions & 0 deletions src/app/DTO/Service/Scraper/ScrapedDataDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
*/
final readonly class ScrapedDataDTO implements Arrayable, FromArray
{
/**
* @param list<array{name: string}> $genres
* @param list<array{name: string}> $voiceActing
* @param list<array{name: string}> $synonyms
*/
public function __construct(
public string $url,
public string $title,
Expand Down
3 changes: 3 additions & 0 deletions src/app/DTO/Service/User/UserDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Contracts\Support\Arrayable;
use SensitiveParameter;

/**
* @template-implements Arrayable<string, mixed>
*/
final readonly class UserDTO implements Arrayable, FromArray
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/app/DTO/Service/UserAnimeList/UpdateAnimeInListDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use App\Models\User;
use Illuminate\Contracts\Support\Arrayable;

/**
* @template-implements Arrayable<string, mixed>
*/
final readonly class UpdateAnimeInListDTO implements Arrayable
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/app/Enums/Concerns/ProvideValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

trait ProvideValues
{
/**
* @return list<string>
*/
public static function values(): array
{
return array_map(static fn(UnitEnum $unitEnum) => $unitEnum->value, self::cases());
Expand Down
3 changes: 3 additions & 0 deletions src/app/Filters/ColumnFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

final readonly class ColumnFilter implements QueryFilterInterface
{
/**
* @param list<string> $columns
*/
public function __construct(private array $columns = ['*'])
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/Filters/QueryFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

interface QueryFilterInterface
{
/**
* @param Builder<Model> $builder
* @return Builder<Model>
*/
public function filter(Builder $builder, Closure $next): Builder;
}
3 changes: 3 additions & 0 deletions src/app/Filters/RelationFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

final readonly class RelationFilter implements QueryFilterInterface
{
/**
* @param list<string> $relations
*/
public function __construct(private array $relations = [])
{
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/Filters/WhereInFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

final readonly class WhereInFilter implements QueryFilterInterface
{
/**
* @param list<mixed> $values
*/
public function __construct(private string $column, private array $values)
{
}
Expand Down
Loading

0 comments on commit b6fdd2a

Please sign in to comment.