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