Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
77.78% |
7 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Pad | |
77.78% |
7 / 9 |
|
0.00% |
0 / 2 |
5.27 | |
0.00% |
0 / 1 |
| always | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| number | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
3.04 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Satag\AmicronEntityBundle\Util; |
| 6 | |
| 7 | class Pad |
| 8 | { |
| 9 | public static function always(?string $string, int $length): ?string |
| 10 | { |
| 11 | // Manche Strings müssen immer mit Lerzeichen gefüllt werden, z.B. Steuersatz |
| 12 | if ($string === null) { |
| 13 | return null; |
| 14 | } |
| 15 | |
| 16 | return str_pad(trim($string), $length, ' ', \STR_PAD_LEFT); |
| 17 | } |
| 18 | |
| 19 | public static function number(?string $number, int $length): ?string |
| 20 | { |
| 21 | // Amicron stellt Nummern Leerzeichen voran, damit Firebird richtig sortiert. Wenn ein anderes Zeichen enthalten ist, muss getrimmt werden. |
| 22 | if ($number === null) { |
| 23 | return null; |
| 24 | } |
| 25 | $number = trim($number); |
| 26 | if (ctype_digit($number)) { |
| 27 | return str_pad(trim($number), $length, ' ', \STR_PAD_LEFT); |
| 28 | } |
| 29 | |
| 30 | return $number; |
| 31 | } |
| 32 | } |