| Total Complexity | 5 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class StartsWithMimeType extends IsBase64 |
||
| 8 | { |
||
| 9 | use ValidatesBase64; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * The mime type to validate. |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $mimeType; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * StartsWithMimeType constructor. |
||
| 20 | * |
||
| 21 | * @param string $mimeType |
||
| 22 | */ |
||
| 23 | public function __construct(string $mimeType) |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Determine if the validation rule passes. |
||
| 30 | * |
||
| 31 | * @param string $attribute |
||
| 32 | * @param mixed $value |
||
| 33 | * @return bool |
||
| 34 | */ |
||
| 35 | public function passes($attribute, $value) |
||
| 36 | { |
||
| 37 | if (! $this->isBase64($value)) { |
||
| 38 | return false; |
||
| 39 | } |
||
| 40 | |||
| 41 | return $this->startsWithMimeType($value); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Checks if base64 is image. |
||
| 46 | * |
||
| 47 | * @param string $value |
||
| 48 | * @return bool |
||
| 49 | */ |
||
| 50 | protected function startsWithMimeType(string $value): bool |
||
| 51 | { |
||
| 52 | $mimeType = $this->getMimeType($value); |
||
| 53 | |||
| 54 | $exploded = explode('/', $mimeType); |
||
| 55 | |||
| 56 | return ($exploded[0] == $this->mimeType); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get the validation error message. |
||
| 61 | * |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | public function message(): string |
||
| 67 | } |
||
| 68 | } |
||
| 69 |