1 | <?php namespace Anomaly\Streams\Platform\Model; |
||
14 | class EloquentCollection extends Collection |
||
15 | { |
||
16 | |||
17 | use Hookable; |
||
18 | |||
19 | /** |
||
20 | * Return the item IDs. |
||
21 | * |
||
22 | * @return array |
||
23 | */ |
||
24 | public function ids() |
||
28 | |||
29 | /** |
||
30 | * Return a collection of decorated items. |
||
31 | * |
||
32 | * @return static |
||
33 | */ |
||
34 | public function decorated() |
||
35 | { |
||
36 | $items = []; |
||
37 | |||
38 | /* @var Decorator $decorator */ |
||
39 | $decorator = app(Decorator::class); |
||
40 | |||
41 | foreach ($this->items as $item) { |
||
42 | $items[] = $decorator->decorate($item); |
||
43 | } |
||
44 | |||
45 | return self::make($items); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Return undecorated items. |
||
50 | * |
||
51 | * @return static|$this |
||
52 | */ |
||
53 | public function undecorated() |
||
54 | { |
||
55 | return $this->undecorate(); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Pad to the specified size with a value. |
||
60 | * |
||
61 | * @param $size |
||
62 | * @param null $value |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function pad($size, $value = null) |
||
81 | |||
82 | /** |
||
83 | * Find a model by key. |
||
84 | * |
||
85 | * @param $key |
||
86 | * @param $value |
||
87 | * @return EloquentModel |
||
88 | */ |
||
89 | public function findBy($key, $value) |
||
90 | { |
||
91 | return $this->undecorated()->first( |
||
92 | function ($entry) use ($key, $value) { |
||
93 | return $entry->{$key} === $value; |
||
94 | } |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Find a model by key. |
||
100 | * |
||
101 | * @param $key |
||
102 | * @param $value |
||
103 | * @return static|$this |
||
104 | */ |
||
105 | public function filterBy($key, $value) |
||
106 | { |
||
107 | /* @var Decorator $decorator */ |
||
108 | $decorator = app(Decorator::class); |
||
109 | |||
110 | return $this->filter( |
||
111 | function ($entry) use ($key, $value, $decorator) { |
||
112 | return $decorator->undecorate($entry)->{$key} === $value; |
||
113 | } |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * An alias for slice. |
||
119 | * |
||
120 | * @param $offset |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function skip($offset) |
||
127 | |||
128 | /** |
||
129 | * Return undecorated items. |
||
130 | * |
||
131 | * @return static|$this |
||
132 | */ |
||
133 | public function undecorate() |
||
137 | |||
138 | /** |
||
139 | * Map to get. |
||
140 | * |
||
141 | * @param $name |
||
142 | * @return mixed |
||
143 | */ |
||
144 | public function __get($name) |
||
145 | { |
||
146 | if ($this->hasHook($name)) { |
||
147 | return $this->call($name, []); |
||
148 | } |
||
149 | |||
150 | if ($this->has($name)) { |
||
151 | return $this->get($name); |
||
152 | } |
||
153 | |||
154 | return call_user_func([$this, camel_case($name)]); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * Map to get. |
||
159 | * |
||
160 | * @param string $method |
||
161 | * @param array $parameters |
||
162 | */ |
||
163 | public function __call($method, $parameters) |
||
175 | } |
||
176 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.