Group::push()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Terranet\Administrator\Collection;
4
5
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Terranet\Administrator\Collection\Mutable as MutableCollection;
7
use Terranet\Administrator\Field\Traits\HandlesVisibility;
8
use Terranet\Administrator\Traits\Collection\ElementContainer;
9
10
/**
11
 * Class Group.
12
 *
13
 * @method merge(array $elements)
14
 * @method insert($element, $position)
15
 * @method except(string|array $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
    use HandlesVisibility;
24
25
    /**
26
     * @var MutableCollection
27
     */
28
    protected $elements;
29
30
    /**
31
     * Group constructor.
32
     *
33
     * @param $id
34
     */
35 15
    public function __construct($id)
36
    {
37 15
        parent::__construct($id);
38
39 15
        $this->elements = new MutableCollection([]);
40 15
    }
41
42
    /**
43
     * @param $method
44
     * @param $args
45
     *
46
     * @throws \Exception
47
     *
48
     * @return mixed
49
     */
50 7
    public function __call($method, $args)
51
    {
52 7
        if (method_exists($this->elements, $method)) {
53 7
            $this->elements = \call_user_func_array([$this->elements, $method], $args);
54
55 7
            return $this;
56
        }
57
58
        throw new \Exception(sprintf('Unknwon method "%s"', $method));
59
    }
60
61
    /**
62
     * @param Model $model
63
     *
64
     * @return Group
65
     */
66
    public function setModel(Model $model)
67
    {
68
        $this->elements->each->setModel($model);
69
70
        return $this;
71
    }
72
73
    /**
74
     * Push an.
75
     *
76
     * @param $element
77
     *
78
     * @return $this
79
     */
80 12
    public function push($element)
81
    {
82 12
        $this->elements->push($element);
83
84 12
        return $this;
85
    }
86
87
    /**
88
     * Find element by ID.
89
     *
90
     * @param $id
91
     *
92
     * @throws \Terranet\Administrator\Exception
93
     *
94
     * @return mixed
95
     */
96 1
    public function find($id)
97
    {
98 1
        return $this->elements->find($id);
99
    }
100
101
    /**
102
     * @return Mutable
103
     */
104 11
    public function elements()
105
    {
106 11
        return $this->elements;
107
    }
108
}
109