Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
C39 | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
setContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
generateCodeString | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
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 39 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 C39 extends BarAbstract |
29 | { |
30 | /** |
31 | * Char weighted array. |
32 | * |
33 | * @var string[] |
34 | * @since 1.0.0 |
35 | */ |
36 | protected static array $CODEARRAY = [ |
37 | '0' => '111221211', '1' => '211211112', '2' => '112211112', '3' => '212211111', '4' => '111221112', |
38 | '5' => '211221111', '6' => '112221111', '7' => '111211212', '8' => '211211211', '9' => '112211211', |
39 | 'A' => '211112112', 'B' => '112112112', 'C' => '212112111', 'D' => '111122112', 'E' => '211122111', |
40 | 'F' => '112122111', 'G' => '111112212', 'H' => '211112211', 'I' => '112112211', 'J' => '111122211', |
41 | 'K' => '211111122', 'L' => '112111122', 'M' => '212111121', 'N' => '111121122', 'O' => '211121121', |
42 | 'P' => '112121121', 'Q' => '111111222', 'R' => '211111221', 'S' => '112111221', 'T' => '111121221', |
43 | 'U' => '221111112', 'V' => '122111112', 'W' => '222111111', 'X' => '121121112', 'Y' => '221121111', |
44 | 'Z' => '122121111', '-' => '121111212', '.' => '221111211', ' ' => '122111211', '$' => '121212111', |
45 | '/' => '121211121', '+' => '121112121', '%' => '111212121', '*' => '121121211', |
46 | ]; |
47 | |
48 | /** |
49 | * Code start. |
50 | * |
51 | * @var string |
52 | * @since 1.0.0 |
53 | */ |
54 | protected static string $CODE_START = '1211212111'; |
55 | |
56 | /** |
57 | * Code end. |
58 | * |
59 | * @var string |
60 | * @since 1.0.0 |
61 | */ |
62 | protected static string $CODE_END = '121121211'; |
63 | |
64 | /** |
65 | * {@inheritdoc} |
66 | */ |
67 | public function setContent(string $content) : void |
68 | { |
69 | parent::setContent(\strtoupper($content)); |
70 | } |
71 | |
72 | /** |
73 | * {@inheritdoc} |
74 | */ |
75 | protected function generateCodeString() : string |
76 | { |
77 | $codeString = ''; |
78 | $length = \strlen($this->content); |
79 | |
80 | for ($X = 1; $X <= $length; ++$X) { |
81 | $codeString .= self::$CODEARRAY[\substr($this->content, ($X - 1), 1)] . '1'; |
82 | } |
83 | |
84 | return $codeString; |
85 | } |
86 | } |