TsplInternalImage::translate()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 18
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 33
ccs 0
cts 26
cp 0
crap 30
rs 9.3554
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\InternalImage;
18
19
final class TsplInternalImage
20
{
21
    public function translate(InternalImage $command): iterable
22
    {
23
        if (\preg_match('~\.bmp$~i', $command->getName())) {
24
            $instruction = \vsprintf('PUTBMP %d,%d,"%s"', [
25
                $command->getX(),
26
                $command->getY(),
27
                $command->getName(),
28
            ]);
29
30
            if ($command->getBpp()) {
31
                $instruction .= ','.$command->getBpp();
32
            }
33
34
            if ($command->getContrast()) {
35
                $instruction .= ','.$command->getContrast();
36
            }
37
38
            yield $instruction;
39
40
            return;
41
        }
42
43
        if (\preg_match('~\.pcx$~i', $command->getName())) {
44
            yield \vsprintf('PUTPCX %d,%d,"%s"', [
45
                $command->getX(),
46
                $command->getY(),
47
                $command->getName(),
48
            ]);
49
50
            return;
51
        }
52
53
        throw new \InvalidArgumentException();
54
    }
55
}
56