Barcode::type()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\GS1Parser;
6
7
final class Barcode
8
{
9
    public const TYPE_GS1_DATAMATRIX = 'gs1_datamatrix';
10
    public const TYPE_GS1_QRCODE = 'gs1_qrcode';
11
    public const TYPE_EAN = 'ean';
12
    public const TYPE_GS1_128 = 'gs1_128';
13
    public const TYPE_UNKNOWN = 'unknown';
14
15
    /**
16
     * @var string
17
     */
18
    private $content;
19
    /**
20
     * @var string
21
     */
22
    private $type;
23
    /**
24
     * @var array
25
     */
26
    private $ais;
27
    /**
28
     * @var array
29
     */
30
    private $buffer;
31
    /**
32
     * @var string | null
33
     */
34
    private $fnc1Prefix;
35
36 1
    public function __construct(string $content, string $type, array $ais, array $buffer, string $fnc1Prefix)
37
    {
38 1
        $this->content = $content;
39 1
        $this->type = $type;
40 1
        $this->ais = $ais;
41 1
        $this->buffer = $buffer;
42 1
        $this->fnc1Prefix = $fnc1Prefix;
43 1
    }
44
45
46 1
    public function type(): string
47
    {
48 1
        return $this->type;
49
    }
50
51 1
    public function ais(): array
52
    {
53 1
        return $this->ais;
54
    }
55
56 1
    public function buffer(): array
57
    {
58 1
        return $this->buffer;
59
    }
60
61 1
    public function hasAI(string $code): bool
62
    {
63 1
        return array_key_exists($code, $this->ais);
64
    }
65
66 1
    public function ai(string $code): string
67
    {
68 1
        return $this->ais[$code] ?? '';
69
    }
70
71 1
    public function raw(): string
72
    {
73 1
        return $this->content;
74
    }
75
76 1
    public function fnc1Prefix(): string
77
    {
78 1
        return $this->fnc1Prefix;
79
    }
80
81 1
    public function normalized(): string
82
    {
83 1
        $prefixLength = strlen($this->fnc1Prefix);
84 1
        return substr($this->content, $prefixLength);
85
    }
86
}