AdultReleaseContext::fromRelease()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
namespace App\Services\AdultProcessing;
4
5
/**
6
 * Value object containing release information for adult movie processing.
7
 */
8
class AdultReleaseContext
9
{
10
    public function __construct(
11
        public readonly int $releaseId,
12
        public readonly string $searchName,
13
        public readonly string $cleanTitle,
14
        public readonly ?string $guid = null,
15
    ) {}
16
17
    /**
18
     * Create from a Release model array/object.
19
     */
20
    public static function fromRelease(array|object $release, string $cleanTitle): self
21
    {
22
        $data = is_array($release) ? $release : (array) $release;
0 ignored issues
show
introduced by
The condition is_array($release) is always true.
Loading history...
23
24
        return new self(
25
            releaseId: (int) ($data['id'] ?? 0),
26
            searchName: $data['searchname'] ?? '',
27
            cleanTitle: $cleanTitle,
28
            guid: $data['guid'] ?? null,
29
        );
30
    }
31
32
    /**
33
     * Create from a movie title string.
34
     */
35
    public static function fromTitle(string $title): self
36
    {
37
        return new self(
38
            releaseId: 0,
39
            searchName: $title,
40
            cleanTitle: $title,
41
            guid: null,
42
        );
43
    }
44
}
45
46