| Conditions | 6 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function validate($value, Constraint $constraint) |
||
| 22 | { |
||
| 23 | if (!$constraint instanceof Format) { |
||
| 24 | throw new UnexpectedTypeException($constraint, Format::class); |
||
| 25 | } |
||
| 26 | |||
| 27 | if (!$value || !$value->type || !$this->types->hasDefinition($value->type)) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | |||
| 31 | $mimeTypes = $this->types->definition($value->type)->mimeTypes(); |
||
| 32 | |||
| 33 | if (!in_array($value->mimeType, $mimeTypes)) { |
||
| 34 | $this->context |
||
| 35 | ->buildViolation($constraint->message) |
||
| 36 | ->atPath($constraint->propertyPath) |
||
| 37 | ->setInvalidValue($value->mimeType) |
||
| 38 | ->addViolation() |
||
| 39 | ; |
||
| 43 |