Completed
Push — master ( a6d5b0...1121c7 )
by wen
12:56
created

Image   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getImagePathAttribute() 0 4 1
A setImagePathAttribute() 0 6 1
A parseRows() 0 15 3
1
<?php
2
3
namespace Sco\Admin\View;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Collection;
7
use Sco\Admin\Traits\StorageTrait;
8
9
class Image extends Table
10
{
11
    use StorageTrait;
12
13
    protected $type = 'image';
14
15
    protected $imagePathAttribute;
16
17
    public function getImagePathAttribute()
18
    {
19
        return $this->imagePathAttribute;
20
    }
21
22
    public function setImagePathAttribute($value)
23
    {
24
        $this->imagePathAttribute = $value;
25
26
        return $this;
27
    }
28
29
    protected function parseRows(Collection $rows)
30
    {
31
        if (is_null($pathKey = $this->getImagePathAttribute())) {
32
            throw new \InvalidArgumentException('Must set image attribute');
33
        }
34
35
        return $rows->map(function (Model $row) use ($pathKey) {
36
            if (!isset($row->$pathKey)) {
37
                throw new \InvalidArgumentException("Not Found '{$pathKey}' attribute");
38
            }
39
            $row->setAttribute('_primary', $row->getKey());
40
            $row->setAttribute('_url', $this->getFileUrl($row->$pathKey));
41
            return $row;
42
        });
43
    }
44
}
45