Completed
Pull Request — master (#15)
by Yaro
08:09 queued 01:44
created

RepeaterFile   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 15
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 4 1
A getPaths() 15 15 4
A sanitizeRepeaterValue() 0 8 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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