Completed
Push — master ( 670c0a...062b68 )
by Terzi
04:34
created

Group::isGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Terranet\Administrator\Collection;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Terranet\Administrator\Collection\Mutable as MutableCollection;
7
use Terranet\Administrator\Columns\Element;
8
use Terranet\Administrator\Traits\Collection\ElementContainer;
9
10
/**
11
 * Class Group.
12
 *
13
 * @method merge(array $elements)
14
 * @method insert(Element $element, $position)
15
 * @method withoug(string $id)
16
 * @method update(string $id, \Closure $callback)
17
 * @method updateMany(array $ids)
18
 * @method move(string $id, $position)
19
 * @method map(callable $callback)
20
 */
21
class Group extends ElementContainer
22
{
23
    /**
24
     * @var MutableCollection
25
     */
26
    protected $elements;
27
28
    /**
29
     * Group constructor.
30
     *
31
     * @param $id
32
     */
33
    public function __construct($id)
34
    {
35
        parent::__construct($id);
36
37
        $this->elements = new MutableCollection([]);
38
    }
39
40
    /**
41
     * @param $method
42
     * @param $args
43
     *
44
     * @throws \Exception
45
     *
46
     * @return mixed
47
     */
48
    public function __call($method, $args)
49
    {
50
        if (method_exists($this->elements, $method)) {
51
            $this->elements = call_user_func_array([$this->elements, $method], $args);
52
53
            return $this;
54
        }
55
56
        throw new \Exception(sprintf('Unknwon method "%s"', $method));
57
    }
58
59
    /**
60
     * @param Model $model
61
     */
62
    public function setModel(Model $model)
63
    {
64
        $this->elements->each->setModel($model);
0 ignored issues
show
Bug Best Practice introduced by
The property each does not exist on Terranet\Administrator\Collection\Mutable. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
66
        return $this;
67
    }
68
69
    /**
70
     * Push an.
71
     *
72
     * @param $element
73
     *
74
     * @return $this
75
     */
76
    public function push($element)
77
    {
78
        $this->elements->push($element);
79
80
        return $this;
81
    }
82
83
    /**
84
     * Find element by ID.
85
     *
86
     * @param $id
87
     *
88
     * @return mixed
89
     */
90
    public function find($id)
91
    {
92
        return $this->elements->find($id);
93
    }
94
95
    /**
96
     * @return Mutable
97
     */
98
    public function elements()
99
    {
100
        return $this->elements;
101
    }
102
}
103