Passed
Push — master ( 179943...1193c4 )
by Darko
09:13
created

TvProcessingResult::notFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Services\TvProcessing;
4
5
/**
6
 * Result object returned by TV processing operations.
7
 */
8
class TvProcessingResult
9
{
10
    public const STATUS_MATCHED = 'matched';
11
    public const STATUS_NOT_FOUND = 'not_found';
12
    public const STATUS_PARSE_FAILED = 'parse_failed';
13
    public const STATUS_SKIPPED = 'skipped';
14
    public const STATUS_PENDING = 'pending';
15
16
    public function __construct(
17
        public readonly string $status,
18
        public readonly ?int $videoId = null,
19
        public readonly ?int $episodeId = null,
20
        public readonly ?string $providerName = null,
21
        public readonly array $debug = [],
22
    ) {}
23
24
    /**
25
     * Create a successful match result.
26
     */
27
    public static function matched(int $videoId, int $episodeId, string $providerName, array $debug = []): self
28
    {
29
        return new self(
30
            status: self::STATUS_MATCHED,
31
            videoId: $videoId,
32
            episodeId: $episodeId,
33
            providerName: $providerName,
34
            debug: $debug,
35
        );
36
    }
37
38
    /**
39
     * Create a not found result.
40
     */
41
    public static function notFound(?string $providerName = null, array $debug = []): self
42
    {
43
        return new self(
44
            status: self::STATUS_NOT_FOUND,
45
            providerName: $providerName,
46
            debug: $debug,
47
        );
48
    }
49
50
    /**
51
     * Create a parse failed result.
52
     */
53
    public static function parseFailed(array $debug = []): self
54
    {
55
        return new self(
56
            status: self::STATUS_PARSE_FAILED,
57
            debug: $debug,
58
        );
59
    }
60
61
    /**
62
     * Create a skipped result.
63
     */
64
    public static function skipped(string $reason = '', ?string $providerName = null): self
65
    {
66
        return new self(
67
            status: self::STATUS_SKIPPED,
68
            providerName: $providerName,
69
            debug: ['reason' => $reason],
70
        );
71
    }
72
73
    /**
74
     * Create a pending result (release still needs processing).
75
     */
76
    public static function pending(): self
77
    {
78
        return new self(status: self::STATUS_PENDING);
79
    }
80
81
    /**
82
     * Check if the result is a successful match.
83
     */
84
    public function isMatched(): bool
85
    {
86
        return $this->status === self::STATUS_MATCHED;
87
    }
88
89
    /**
90
     * Check if processing should continue to the next provider.
91
     */
92
    public function shouldContinueProcessing(): bool
93
    {
94
        return ! $this->isMatched();
95
    }
96
}
97
98