Barcode   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 0
dl 0
loc 80
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A type() 0 4 1
A ais() 0 4 1
A buffer() 0 4 1
A hasAI() 0 4 1
A ai() 0 4 1
A raw() 0 4 1
A fnc1Prefix() 0 4 1
A normalized() 0 5 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
}