Label   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 32
c 3
b 0
f 0
dl 0
loc 129
ccs 36
cts 42
cp 0.8571
rs 10
wmc 19

16 Methods

Rating   Name   Duplication   Size   Complexity  
A direction() 0 5 1
A getHeight() 0 3 1
A getDirection() 0 3 1
A getWidth() 0 3 1
A getCharset() 0 3 1
A add() 0 5 1
A when() 0 5 1
A for() 0 5 1
A getCopies() 0 3 1
A charset() 0 5 1
A erase() 0 5 1
A __construct() 0 7 4
A create() 0 3 1
A getIterator() 0 3 1
A getMedia() 0 3 1
A copies() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of PhpAidc LabelPrinter package.
5
 *
6
 * © Appwilio (https://appwilio.com)
7
 * © JhaoDa (https://github.com/jhaoda)
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace PhpAidc\LabelPrinter\Label;
16
17
use PhpAidc\LabelPrinter\Enum\Unit;
18
use PhpAidc\LabelPrinter\Enum\Charset;
19
use PhpAidc\LabelPrinter\Enum\Direction;
20
use PhpAidc\LabelPrinter\Contract\Command;
21
use PhpAidc\LabelPrinter\Contract\Condition;
22
use PhpAidc\LabelPrinter\Contract\Media as MediaContract;
23
use PhpAidc\LabelPrinter\Contract\Label as LabelContract;
24
25
final class Label implements LabelContract
26
{
27
    /** @var int */
28
    private $copies = 1;
29
30
    /** @var Charset|null */
31
    private $charset;
32
33
    /** @var Direction|null */
34
    private $direction;
35
36
    /** @var Media */
37
    private $media;
38
39
    /** @var Command[]|Condition[] */
40
    private $statements = [];
41
42 7
    public static function create(?Unit $unit = null, ?float $width = null, ?float $height = null): self
43
    {
44 7
        return new self($unit, $width, $height);
45
    }
46
47 10
    public function __construct(?Unit $unit = null, ?float $width = null, ?float $height = null)
48
    {
49 10
        if ($unit === null && ($width !== null || $height !== null)) {
50 1
            throw new \InvalidArgumentException();
51
        }
52
53 9
        $this->media = new Media($unit, $width, $height);
54 9
    }
55
56 7
    public function add(Command $command)
57
    {
58 7
        $this->statements[] = $command;
59
60 7
        return $this;
61
    }
62
63 1
    public function charset(Charset $value)
64
    {
65 1
        $this->charset = $value;
66
67 1
        return $this;
68
    }
69
70 2
    public function copies(int $copies)
71
    {
72 2
        $this->copies = $copies;
73
74 2
        return $this;
75
    }
76
77 1
    public function direction(Direction $value)
78
    {
79 1
        $this->direction = $value;
80
81 1
        return $this;
82
    }
83
84 1
    public function getCharset(): ?Charset
85
    {
86 1
        return $this->charset;
87
    }
88
89 6
    public function getCopies(): int
90
    {
91 6
        return $this->copies;
92
    }
93
94 1
    public function getDirection(): ?Direction
95
    {
96 1
        return $this->direction;
97
    }
98
99
    public function getMedia(): MediaContract
100
    {
101
        return $this->media;
102
    }
103
104
    public function getWidth(): ?float
105
    {
106
        return $this->media['width'] ?? null;
107
    }
108
109
    public function getHeight(): ?float
110
    {
111
        return $this->media['height'] ?? null;
112
    }
113
114 2
    public function erase()
115
    {
116 2
        $this->statements = [];
117
118 2
        return $this;
119
    }
120
121
    /**
122
     * Apply the callback if the languages match.
123
     *
124
     * @param  string    $language
125
     * @param  callable  $callback
126
     *
127
     * @return $this
128
     */
129 1
    public function for(string $language, callable $callback)
130
    {
131 1
        $this->statements[] = new LanguageCondition($language, $callback);
132
133 1
        return $this;
134
    }
135
136
    /**
137
     * Apply the callback if the value is truthy.
138
     *
139
     * @param  mixed     $value
140
     * @param  callable  $callback
141
     *
142
     * @return $this
143
     */
144 2
    public function when($value, callable $callback)
145
    {
146 2
        $this->statements[] = new BooleanCondition($value, $callback);
147
148 2
        return $this;
149
    }
150
151 6
    public function getIterator()
152
    {
153 6
        return new \ArrayIterator($this->statements);
154
    }
155
}
156