| Total Complexity | 8 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 7 | class FileFieldDimensionsRule extends AbstractMediaFieldRule |
||
| 8 | { |
||
| 9 | public function validate($attribute, $value, $params, $validator): bool |
||
| 10 | { |
||
| 11 | $value = $this->normalizePayload($value); |
||
| 12 | |||
| 13 | foreach([MediaRequest::NEW, MediaRequest::REPLACE] as $type) { |
||
| 14 | foreach($value[$type] as $file) { |
||
| 15 | if($file && false !== $this->validateDimensions($attribute, $file, $params)) { |
||
| 16 | return true; |
||
| 17 | } |
||
| 18 | } |
||
| 19 | } |
||
| 20 | |||
| 21 | $validator->setCustomMessages([ |
||
| 22 | 'filefield_dimensions' => 'De :attribute heeft niet de juiste afmetingen: ' . implode(', ', $params), |
||
| 23 | ]); |
||
| 24 | |||
| 25 | if(!isset($validator->customAttributes[$attribute])) { |
||
| 26 | $validator->addCustomAttributes([ |
||
| 27 | $attribute => 'afbeelding', |
||
| 28 | ]); |
||
| 29 | } |
||
| 30 | |||
| 31 | |||
| 32 | return false; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function validateDimensions($attribute, $value, $parameters) |
||
| 42 | } |
||
| 43 | } |
||
| 44 |