Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
C25 | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
9 | |
100.00% |
1 / 1 |
setContent | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
generateCodeString | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
7 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Utils\Barcode |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Utils\Barcode; |
16 | |
17 | /** |
18 | * Code 25 class. |
19 | * |
20 | * @package phpOMS\Utils\Barcode |
21 | * @license OMS License 2.0 |
22 | * @link https://jingga.app |
23 | * @since 1.0.0 |
24 | * |
25 | * @SuppressWarnings(PHPMD.CamelCasePropertyName) |
26 | * @SuppressWarnings(PHPMD.CamelCaseVariableName) |
27 | */ |
28 | class C25 extends BarAbstract |
29 | { |
30 | /** |
31 | * Char array. |
32 | * |
33 | * @var string[] |
34 | * @since 1.0.0 |
35 | */ |
36 | protected static array $CODEARRAY = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']; |
37 | |
38 | /** |
39 | * Char weighted array. |
40 | * |
41 | * @var string[] |
42 | * @since 1.0.0 |
43 | */ |
44 | protected static array $CODEARRAY2 = [ |
45 | '3-1-1-1-3', '1-3-1-1-3', '3-3-1-1-1', '1-1-3-1-3', '3-1-3-1-1', |
46 | '1-3-3-1-1', '1-1-1-3-3', '3-1-1-3-1', '1-3-1-3-1', '1-1-3-3-1', |
47 | ]; |
48 | |
49 | /** |
50 | * Code start. |
51 | * |
52 | * @var string |
53 | * @since 1.0.0 |
54 | */ |
55 | protected static string $CODE_START = '1111'; |
56 | |
57 | /** |
58 | * Code end. |
59 | * |
60 | * @var string |
61 | * @since 1.0.0 |
62 | */ |
63 | protected static string $CODE_END = '311'; |
64 | |
65 | /** |
66 | * Set content to encrypt |
67 | * |
68 | * @param string $content Barcode content |
69 | * |
70 | * @return void |
71 | * |
72 | * @throws \InvalidArgumentException this exception is thrown if the content string is not supported |
73 | * |
74 | * @since 1.0.0 |
75 | */ |
76 | public function setContent(string $content) : void |
77 | { |
78 | if (!\ctype_digit($content)) { |
79 | throw new \InvalidArgumentException($content); |
80 | } |
81 | |
82 | parent::setContent($content); |
83 | } |
84 | |
85 | /** |
86 | * {@inheritdoc} |
87 | */ |
88 | protected function generateCodeString() : string |
89 | { |
90 | $codeString = ''; |
91 | $length = \strlen($this->content); |
92 | $arrayLength = \count(self::$CODEARRAY); |
93 | $temp = []; |
94 | |
95 | for ($posX = 1; $posX <= $length; ++$posX) { |
96 | for ($posY = 0; $posY < $arrayLength; ++$posY) { |
97 | if (\substr($this->content, ($posX - 1), 1) === self::$CODEARRAY[$posY]) { |
98 | $temp[$posX] = self::$CODEARRAY2[$posY]; |
99 | } |
100 | } |
101 | } |
102 | |
103 | for ($posX = 1; $posX <= $length; $posX += 2) { |
104 | if (isset($temp[$posX], $temp[($posX + 1)])) { |
105 | $temp1 = \explode('-', $temp[$posX]); |
106 | $temp2 = \explode('-', $temp[($posX + 1)]); |
107 | |
108 | $count = \count($temp1); |
109 | for ($posY = 0; $posY < $count; ++$posY) { |
110 | $codeString .= $temp1[$posY] . $temp2[$posY]; |
111 | } |
112 | } |
113 | } |
114 | |
115 | return $codeString; |
116 | } |
117 | } |