Completed
Push — master ( 4434b2...6b8e46 )
by Yaro
02:04
created

File   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 65
Duplicated Lines 32.31 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 17.65%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 5
dl 21
loc 65
ccs 6
cts 34
cp 0.1765
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A shouldSkip() 0 6 1
B value() 21 21 7
A getListValue() 0 7 1
A getEditFormValue() 0 9 2
A getCreateFormValue() 0 6 1

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;
4
5
use Illuminate\Http\Request;
6
use Yaro\Jarboe\Table\Fields\Traits\Nullable;
7
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
8
use Yaro\Jarboe\Table\Fields\Traits\Storage;
9
10
class File extends AbstractField
11
{
12
    use Storage;
13
    use Nullable;
14
    use Placeholder;
15
16 30
    public function __construct()
17
    {
18 30
        $this->disk = config('filesystems.default');
19 30
    }
20
21 2
    public function shouldSkip(Request $request)
22
    {
23 2
        $files = $request->file($this->name());
24
25 2
        return !$files;
26
    }
27
28 View Code Duplication
    public function value(Request $request)
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...
29
    {
30
        $files = $request->file($this->name());
31
        if (!$files) {
32
            $defaultValue = $this->isMultiple() ? [] : '';
33
            return $this->isNullable() ? null : $defaultValue;
34
        }
35
36
        $files = is_array($files) ? $files : [$files];
37
        $paths = [];
38
        foreach ($files as $file) {
39
            $filename = $file->hashName();
40
            $paths[] = $this->storeFile($file, $filename, $request);
41
        }
42
43
        if (!$this->isMultiple()) {
44
            return array_pop($paths);
45
        }
46
47
        return $paths;
48
    }
49
50
    public function getListValue($model)
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...
51
    {
52
        return view('jarboe::crud.fields.file.list', [
53
            'model' => $model,
54
            'field' => $this,
55
        ])->render();
56
    }
57
58
    public function getEditFormValue($model)
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...
59
    {
60
        $template = $this->isReadonly() ? 'readonly' : 'edit';
61
62
        return view('jarboe::crud.fields.file.'. $template, [
63
            'model' => $model,
64
            'field' => $this,
65
        ])->render();
66
    }
67
68
    public function getCreateFormValue()
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...
69
    {
70
        return view('jarboe::crud.fields.file.create', [
71
            'field' => $this,
72
        ])->render();
73
    }
74
}
75