RepeaterFile::getPaths()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 14
rs 10
1
<?php
2
3
namespace Yaro\Jarboe\Table\Fields\Adapters;
4
5
use Illuminate\Http\Request;
6
use Yaro\Jarboe\Table\Fields\File;
7
8
class RepeaterFile
9
{
10
    /**
11
     * @var File
12
     */
13
    private $field;
14
15
    public function __construct(File $field)
16
    {
17
        $this->field = $field;
18
    }
19
20
    public function __call($method, $parameters)
21
    {
22
        return $this->field->$method(...$parameters);
23
    }
24
25
    public function getPaths($model): array
26
    {
27
        if (is_null($model)) {
28
            return [];
29
        }
30
31
        $filepath = $this->getAttribute($model);
0 ignored issues
show
Bug introduced by
The method getAttribute() does not exist on Yaro\Jarboe\Table\Fields\Adapters\RepeaterFile. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

31
        /** @scrutinizer ignore-call */ 
32
        $filepath = $this->getAttribute($model);
Loading history...
32
        // FIXME: mb change structure for storing files data?
33
        $filepath = $this->sanitizeRepeaterValue($filepath);
34
        if (!$filepath) {
35
            return [];
36
        }
37
38
        return is_array($filepath) ? $filepath : [$filepath];
39
    }
40
41
    private function sanitizeRepeaterValue($filepath)
42
    {
43
        if (is_array($filepath) && isset($filepath['paths']) && is_array($filepath['paths'])) {
44
            $filepath = $filepath['paths'];
45
        }
46
47
        return $filepath;
48
    }
49
}
50