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

File::shouldSkip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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