Test Failed
Push — fix/media-validation ( 3351fe )
by Ben
09:34
created

FileFieldRequiredRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 22 5
1
<?php declare(strict_types=1);
2
3
namespace Thinktomorrow\Chief\Fields\ValidationRules;
4
5
use Thinktomorrow\Chief\Media\Application\MediaRequest;
6
7
class FileFieldRequiredRule extends AbstractMediaFieldRule
8
{
9
    public function validate($attribute, $value, $params, $validator): bool
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

9
    public function validate($attribute, $value, /** @scrutinizer ignore-unused */ $params, $validator): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
10
    {
11
        $value = $this->normalizePayload($value);
12
13
        foreach([MediaRequest::NEW, MediaRequest::REPLACE] as $type) {
14
            if(is_array($value[$type]) && !empty($value[$type])) {
15
                return true;
16
            }
17
        }
18
19
        $validator->setCustomMessages([
20
            'filefield_required' => 'De :attribute is verplicht.',
21
        ]);
22
23
        if(!isset($validator->customAttributes[$attribute])) {
24
            $validator->addCustomAttributes([
25
                $attribute => 'afbeelding',
26
            ]);
27
        }
28
29
30
        return false;
31
    }
32
}
33