Conditions | 7 |
Paths | 10 |
Total Lines | 21 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
40 | protected static function validBase64(string $value, string $message = ''): void |
||
41 | { |
||
42 | $result = true; |
||
43 | |||
44 | if (filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => self::$base64_regex]]) === false) { |
||
45 | $result = false; |
||
46 | } elseif (strlen($value) % 4 !== 0) { |
||
47 | $result = false; |
||
48 | } else { |
||
49 | $decoded = base64_decode($value, true); |
||
50 | if (empty($decoded)) { // Invalid _or_ empty string |
||
51 | $result = false; |
||
52 | } elseif (base64_encode($decoded) !== $value) { |
||
53 | $result = false; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | if ($result === false) { |
||
58 | throw new InvalidArgumentException(sprintf( |
||
59 | $message ?: '\'%s\' is not a valid Base64 encoded string', |
||
60 | $value, |
||
61 | )); |
||
65 |