Passed
Push — fix/slim ( 590b9b...bb7246 )
by Ben
08:37 queued 41s
created

AbstractMediaFieldRule::normalizePayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Thinktomorrow\Chief\Fields\ValidationRules;
4
5
use Symfony\Component\HttpFoundation\File\File;
6
use Illuminate\Validation\Concerns\ValidatesAttributes;
7
use Thinktomorrow\Chief\Media\Application\ChecksExistingAssets;
8
9
abstract class AbstractMediaFieldRule
10
{
11
    use ChecksExistingAssets;
12
13
    use ValidatesAttributes;
0 ignored issues
show
introduced by
The trait Illuminate\Validation\Concerns\ValidatesAttributes requires some properties which are not provided by Thinktomorrow\Chief\Fiel...\AbstractMediaFieldRule: $data, $container, $currentRule, $implicitAttributes
Loading history...
14
    use ValidatesExistingAssetAttributes;
0 ignored issues
show
introduced by
The trait Thinktomorrow\Chief\Fiel...ExistingAssetAttributes requires some properties which are not provided by Thinktomorrow\Chief\Fiel...\AbstractMediaFieldRule: $media, $size
Loading history...
15
16
    protected function normalizePayloadIncludingExistingMedia($value): array
17
    {
18
        return $this->normalizePayload($value, false);
19
    }
20
21
    protected function normalizePayload(array $values, $excludeExistingMedia = true): array
0 ignored issues
show
Unused Code introduced by
The parameter $excludeExistingMedia 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

21
    protected function normalizePayload(array $values, /** @scrutinizer ignore-unused */ $excludeExistingMedia = true): array

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...
22
    {
23
//        if($excludeExistingMedia) {
24
//            foreach($values as $key => $value) {
25
//                if($this->looksLikeAnAssetId($key) && $key == $value) {
26
//                    unset($values[$key]);
27
//                }
28
//            }
29
//        }
30
31
        return $values;
32
    }
33
34
    /**
35
     * Default getSize method
36
     *
37
     * Override the default getSize from ValidatesAttributes to avoid calls to a hasRule method
38
     * For media fields this is not needed anyways.
39
     *
40
     * @param $attribute
41
     * @param $value
42
     * @return bool|false|float|int
43
     */
44
    protected function getSize($attribute, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $attribute 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

44
    protected function getSize(/** @scrutinizer ignore-unused */ $attribute, $value)

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...
45
    {
46
        if ($value instanceof File) {
47
            return $value->getSize() / 1024;
48
        }
49
50
        return mb_strlen($value);
51
    }
52
}
53