Total Complexity | 6 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 68.18% |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
15 | trait HasAcceptsMediaTrait |
||
16 | { |
||
17 | /** @var callable */ |
||
18 | public $acceptsMedia; |
||
19 | |||
20 | 13 | protected function initHasAcceptsMedia() |
|
21 | { |
||
22 | 13 | if (method_exists($this, 'getValidator')) { |
|
23 | 13 | $this->initHasAcceptsMediaWithValidation(); |
|
24 | |||
25 | 13 | return; |
|
26 | } |
||
27 | $this->initHasAcceptsMediaEmpty(); |
||
28 | } |
||
29 | |||
30 | 13 | protected function initHasAcceptsMediaWithValidation() |
|
31 | { |
||
32 | $this->acceptsMedia(function ($file) { |
||
33 | 2 | $validator = $this->getValidator(); |
|
34 | 2 | $constraint = $this->getConstraint(); |
|
35 | |||
36 | 2 | $violations = $validator->validate($file, $constraint); |
|
37 | 2 | if ($violations->count() < 1) { |
|
38 | 2 | return true; |
|
39 | } |
||
40 | |||
41 | return $violations; |
||
42 | 13 | }); |
|
43 | 13 | } |
|
44 | |||
45 | protected function initHasAcceptsMediaEmpty() |
||
49 | }); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param callable $acceptsFile |
||
54 | * |
||
55 | * @return HasAcceptsMediaTrait |
||
56 | */ |
||
57 | 13 | public function acceptsMedia(callable $acceptsFile): self |
|
62 | } |
||
63 | } |
||
64 |