| Total Complexity | 8 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class IsBase64 implements Rule |
||
| 10 | { |
||
| 11 | use ValidatesBase64; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Determine if the validation rule passes. |
||
| 15 | * |
||
| 16 | * @param string $attribute |
||
| 17 | * @param mixed $value |
||
| 18 | * @return bool |
||
| 19 | */ |
||
| 20 | public function passes($attribute, $value) |
||
| 21 | { |
||
| 22 | $values = Arr::wrap($value); |
||
| 23 | |||
| 24 | foreach ($values as $value) { |
||
|
|
|||
| 25 | if (! $this->isBase64($value)) { |
||
| 26 | return false; |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | // All base64 strings are valid. Now we only need to verify if there |
||
| 31 | // where any base64 strings at all. |
||
| 32 | return count($values) > 0; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Determine if the given value is base64 encoded. |
||
| 37 | * |
||
| 38 | * @param mixed $value |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | protected function isBase64($value): bool |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Get the validation error message. |
||
| 62 | * |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | public function message(): string |
||
| 70 |