Completed
Push — master ( ad6b4f...e57368 )
by Terzi
05:01 queued 10s
created

Media::fromCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Terranet\Administrator\Field;
4
5
use Terranet\Administrator\Architect;
6
use Terranet\Administrator\Services\MediaLibraryProvider;
7
8
class Media extends Field
9
{
10
    /** @var string */
11
    protected $collection = 'default';
12
13
    /** @var string */
14
    protected $conversion = '';
15
16
    /** @var int */
17
    protected $perPage = 10;
18
19
    /**
20
     * @param string $collection
21
     * @return $this
22
     */
23
    public function fromCollection(string $collection)
24
    {
25
        $this->collection = $collection;
26
27
        return $this;
28
    }
29
30
    /**
31
     * @param string $conversion
32
     *
33
     * @return self
34
     */
35
    public function convertedTo(string $conversion): self
36
    {
37
        $this->conversion = $conversion;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @return array
44
     */
45
    protected function onIndex(): array
46
    {
47
        return [
48
            'count' => MediaLibraryProvider::forModel($this->model)->count($this->collection),
49
            'module' => Architect::resourceByEntity($this->model) ?: app('scaffold.module'),
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

49
            'module' => Architect::resourceByEntity($this->model) ?: /** @scrutinizer ignore-call */ app('scaffold.module'),
Loading history...
50
        ];
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    protected function onView(): array
57
    {
58
        return [
59
            'collection' => $this->collection,
60
            'conversion' => $this->conversion,
61
        ];
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    protected function onEdit(): array
68
    {
69
        return [];
70
    }
71
}
72