Variant::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Storage\Processor;
18
19
/**
20
 * Manipulation
21
 */
22
class Variant implements VariantInterface
23
{
24
    protected string $name = '';
25
    /**
26
     * @var array<string, mixed>
27
     */
28
    protected array $operations = [];
29
    protected string $path = '';
30
    protected string $url = '';
31
32
    /**
33
     * @return array<string, mixed>
34
     */
35
    public function toArray(): array
36
    {
37
        return [
38
            'name' => $this->name,
39
            'operations' => $this->operations,
40
            'path' => $this->path,
41
            'url' => $this->url,
42
        ];
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function name(): string
49
    {
50
        return $this->name;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function path(): string
57
    {
58
        return $this->path;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function hasOperations(): bool
65
    {
66
        return count($this->operations) > 0;
67
    }
68
69
    /**
70
     * @param string $url Path
71
     * @return self
72
     */
73
    public function withUrl(string $url): self
74
    {
75
        $that = clone $this;
76
        $that->url = $url;
77
78
        return $that;
79
    }
80
81
    /**
82
     * @param string $path Path
83
     * @return self
84
     */
85
    public function withPath(string $path): self
86
    {
87
        $that = clone $this;
88
        $that->path = $path;
89
90
        return $that;
91
    }
92
}
93