TsplBarcode   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 16
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A translate() 0 27 2
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\Tspl;
16
17
use PhpAidc\LabelPrinter\Command\Barcode;
18
19
final class TsplBarcode
20
{
21
    public function translate(Barcode $command): iterable
22
    {
23
        $instruction = \vsprintf('BARCODE %d,%d,"%s",%d', [
24
            $command->getX(),
25
            $command->getY(),
26
            $command->getType(),
27
            $command->getHeight(),
28
        ]);
29
30
        // human readable
31
        $instruction .= ','.(int) $command->isReadable();
32
33
        // rotation
34
        $instruction .= ','.$command->getRotation()->getDegrees();
35
36
        // width of narrow element
37
        $instruction .= ','.(int) $command->getRatio()['narrow'];
38
39
        // width of wide element
40
        $instruction .= ','.(int) $command->getRatio()['wide'];
41
42
        // alingment (Rongta RP 4xx/Atol BP4x  doesn't support alignment and prints void)
43
        if ($command->getAnchor()) {
44
            $instruction .= ','.$command->getAnchor()->getValue();
45
        }
46
47
        yield $instruction.\sprintf(',"%s"', $command->getData());
48
    }
49
}
50