Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Codebar | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
setContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
generateCodeString | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 |
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 | * Codebar 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 Codebar 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', '-', '$', ':', '/', '.', '+', 'A', 'B', 'C', 'D']; |
37 | |
38 | /** |
39 | * Char weighted array. |
40 | * |
41 | * @var string[] |
42 | * @since 1.0.0 |
43 | */ |
44 | protected static array $CODEARRAY2 = [ |
45 | '1111221', '1112112', '2211111', '1121121', '2111121', '1211112', '1211211', '1221111', '2112111', '1111122', |
46 | '1112211', '1122111', '2111212', '2121112', '2121211', '1121212', '1122121', '1212112', '1112122', '1112221', |
47 | ]; |
48 | |
49 | /** |
50 | * Code start. |
51 | * |
52 | * @var string |
53 | * @since 1.0.0 |
54 | */ |
55 | protected static string $CODE_START = '11221211'; |
56 | |
57 | /** |
58 | * Code end. |
59 | * |
60 | * @var string |
61 | * @since 1.0.0 |
62 | */ |
63 | protected static string $CODE_END = '1122121'; |
64 | |
65 | /** |
66 | * {@inheritdoc} |
67 | */ |
68 | public function setContent(string $content) : void |
69 | { |
70 | parent::setContent(\strtoupper($content)); |
71 | } |
72 | |
73 | /** |
74 | * {@inheritdoc} |
75 | */ |
76 | protected function generateCodeString() : string |
77 | { |
78 | $codeString = ''; |
79 | $length = \strlen($this->content); |
80 | $lenCodearr = \count(self::$CODEARRAY); |
81 | |
82 | for ($posX = 1; $posX <= $length; ++$posX) { |
83 | for ($posY = 0; $posY < $lenCodearr; ++$posY) { |
84 | if (\substr($this->content, ($posX - 1), 1) === self::$CODEARRAY[$posY]) { |
85 | $codeString .= self::$CODEARRAY2[$posY] . '1'; |
86 | } |
87 | } |
88 | } |
89 | |
90 | return $codeString; |
91 | } |
92 | } |