Completed
Pull Request — master (#14)
by
unknown
15:13 queued 07:44
created

RepeaterFile::getPaths()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 4
nc 4
nop 1
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)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
21
    {
22
        return $this->field->$method(...$parameters);
23
    }
24
25 View Code Duplication
    public function getPaths($model): array
26
    {
27
        if (is_null($model)) {
28
            return [];
29
        }
30
31
        $filepath = $this->getAttribute($model);
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)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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