FingerprintTextBlock::translate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 23
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 38
ccs 0
cts 29
cp 0
crap 6
rs 9.552
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\Language\Fingerprint;
16
17
use PhpAidc\LabelPrinter\Command\Bitmap;
18
use PhpAidc\LabelPrinter\Command\TextBlock;
19
use PhpAidc\LabelPrinter\Emulation\EmulateText;
20
use PhpAidc\LabelPrinter\Language\Fingerprint\Concerns\Font;
21
use PhpAidc\LabelPrinter\Language\Fingerprint\Concerns\Align;
22
use PhpAidc\LabelPrinter\Language\Fingerprint\Concerns\Invert;
23
use PhpAidc\LabelPrinter\Language\Fingerprint\Concerns\Rotate;
24
use PhpAidc\LabelPrinter\Language\Fingerprint\Concerns\Position;
25
26
final class FingerprintTextBlock
27
{
28
    use Font;
29
    use Align;
30
    use Rotate;
31
    use Position;
32
    use Invert;
33
    use EmulateText;
34
35
    public function translate(TextBlock $command): iterable
36
    {
37
        if ($command->shouldEmulate()) {
38
            $image = $this->emulate(
39
                $command,
40
                $command->getBoxWidth(),
41
                $command->getBoxHeight(),
42
                $command->getSpacing()
43
            );
44
45
            yield from (new FingerprintBitmap())->translate(
46
                new Bitmap($command->getX(), $command->getY(), $image)
47
            );
48
49
            return;
50
        }
51
52
        yield from $this->position($command);
53
54
        yield from $this->rotate($command);
55
        yield from $this->invert($command);
56
57
        yield from $this->align($command);
58
59
        yield from $this->font($command);
60
61
        yield \vsprintf('PX %d,%d,%d,"%s",0,%d', [
62
            $command->getBoxHeight(),
63
            $command->getBoxWidth(),
64
            $command->getBoxBorder(),
65
            $command->getText(),
66
            $command->getSpacing(),
67
        ]);
68
69
        // reset
70
        yield from $this->resetAlign($command);
71
        yield from $this->resetInvert($command);
72
        yield from $this->resetRotate($command);
73
    }
74
}
75