TextBlock   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 64
ccs 0
cts 37
cp 0
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getBoxWidth() 0 3 1
A getBoxBorder() 0 3 1
A __construct() 0 7 1
A getText() 0 3 1
A box() 0 5 1
A getBoxHeight() 0 3 1
A spacing() 0 5 1
A getSpacing() 0 3 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\Command;
16
17
use PhpAidc\LabelPrinter\Command\Concerns\Invertible;
18
use PhpAidc\LabelPrinter\Contract\Command;
19
use PhpAidc\LabelPrinter\Command\Concerns\Alignable;
20
use PhpAidc\LabelPrinter\Command\Concerns\Rotatable;
21
use PhpAidc\LabelPrinter\Command\Concerns\FontAware;
22
use PhpAidc\LabelPrinter\Command\Concerns\Magnifiable;
23
use PhpAidc\LabelPrinter\Command\Concerns\ImageFallback;
24
use PhpAidc\LabelPrinter\Command\Concerns\PositionAware;
25
26
final class TextBlock implements Command
27
{
28
    use Alignable;
29
    use Rotatable;
30
    use FontAware;
31
    use Magnifiable;
32
    use Invertible;
33
    use PositionAware;
34
    use ImageFallback;
35
36
    /** @var string */
37
    private $text;
38
39
    /** @var int|null */
40
    private $spacing;
41
42
    private $box = ['width' => null, 'height' => null, 'border' => 0];
43
44
    public function __construct(int $x, int $y, string $text, string $font, float $size = null)
45
    {
46
        $this->x = $x;
47
        $this->y = $y;
48
        $this->text = $text;
49
        $this->fontName = $font;
50
        $this->fontSize = $size;
51
    }
52
53
    public function box(int $width, int $height, int $border = 0)
54
    {
55
        $this->box = \compact('width', 'height', 'border');
56
57
        return $this;
58
    }
59
60
    public function spacing(int $dots)
61
    {
62
        $this->spacing = $dots;
63
64
        return $this;
65
    }
66
67
    public function getBoxBorder(): int
68
    {
69
        return $this->box['border'];
70
    }
71
72
    public function getBoxWidth(): ?int
73
    {
74
        return $this->box['width'];
75
    }
76
77
    public function getBoxHeight(): ?int
78
    {
79
        return $this->box['height'];
80
    }
81
82
    public function getText(): string
83
    {
84
        return $this->text;
85
    }
86
87
    public function getSpacing(): ?int
88
    {
89
        return $this->spacing;
90
    }
91
}
92