FingerprintTextLine::translate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 15
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 29
ccs 0
cts 19
cp 0
crap 6
rs 9.7666
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\TextLine;
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\Magnify;
25
use PhpAidc\LabelPrinter\Language\Fingerprint\Concerns\Position;
26
27
final class FingerprintTextLine
28
{
29
    use Font;
30
    use Align;
31
    use Invert;
32
    use Rotate;
33
    use Magnify;
34
    use Position;
35
    use EmulateText;
36
37
    public function translate(TextLine $command): iterable
38
    {
39
        if ($command->shouldEmulate()) {
40
            $image = $this->emulate($command, $command->getMaxWidth());
41
42
            yield from (new FingerprintBitmap())->translate(
43
                new Bitmap($command->getX(), $command->getY(), $image)
44
            );
45
46
            return;
47
        }
48
49
        yield from $this->position($command);
50
51
        yield from $this->rotate($command);
52
53
        yield from $this->invert($command);
54
55
        yield from $this->align($command);
56
57
        yield from $this->font($command);
58
59
        yield \sprintf('PT "%s"', $command->getText());
60
61
        // reset
62
        yield from $this->resetAlign($command);
63
        yield from $this->resetInvert($command);
64
        yield from $this->resetRotate($command);
65
        yield from $this->resetMagnify($command);
66
    }
67
}
68