1 | <?php |
||||||
2 | |||||||
3 | namespace Raystech\StarterKit\Traits; |
||||||
4 | |||||||
5 | use Illuminate\Database\Eloquent\Builder; |
||||||
6 | use Illuminate\Database\Eloquent\Collection; |
||||||
7 | use Illuminate\Database\Eloquent\Model; |
||||||
8 | use Illuminate\Database\Eloquent\Relations\MorphMany; |
||||||
9 | use Illuminate\Database\Query\JoinClause; |
||||||
10 | |||||||
11 | trait HasMeta |
||||||
12 | { |
||||||
13 | protected $metaData = NULL; |
||||||
14 | |||||||
15 | protected function newMeta($meta, $extra = array()) |
||||||
0 ignored issues
–
show
|
|||||||
16 | { |
||||||
17 | // dd(__class__); |
||||||
18 | // dd($meta); |
||||||
19 | $metaModel = new $this->meta_model(); |
||||||
0 ignored issues
–
show
The property
meta_model does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
20 | |||||||
21 | if($this->meta_global == true) { |
||||||
0 ignored issues
–
show
The property
meta_global does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
22 | $metaModel->model_type = __class__; |
||||||
23 | } |
||||||
24 | $metaModel->{$this->meta_key_name} = $meta[$this->meta_key_name]; |
||||||
0 ignored issues
–
show
The property
meta_key_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
25 | $metaModel->{$this->meta_value_name} = $meta[$this->meta_value_name]; |
||||||
0 ignored issues
–
show
The property
meta_value_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
26 | $metaModel->{$this->meta_foreign_key} = $this->{$this->meta_primary_key}; |
||||||
0 ignored issues
–
show
The property
meta_primary_key does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() The property
meta_foreign_key does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
27 | |||||||
28 | // if(!empty($extra)) { |
||||||
29 | // foreach($extra as $key => $value) { |
||||||
30 | |||||||
31 | // } |
||||||
32 | // } |
||||||
33 | return $metaModel; |
||||||
34 | } |
||||||
35 | |||||||
36 | |||||||
37 | /** |
||||||
38 | * Get the data associated with this model |
||||||
39 | * |
||||||
40 | * @return hasOne |
||||||
0 ignored issues
–
show
The type
Raystech\StarterKit\Traits\hasOne 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
41 | */ |
||||||
42 | public function meta() |
||||||
43 | { |
||||||
44 | // return $this->morphMany($this->meta_model, $this->meta_foreign_key, $this->primaryKey); |
||||||
45 | |||||||
46 | return $this->hasMany($this->meta_model, $this->meta_foreign_key, $this->primaryKey); |
||||||
0 ignored issues
–
show
The property
primaryKey does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() It seems like
hasMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The property
meta_model does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() The property
meta_foreign_key does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
47 | } |
||||||
48 | |||||||
49 | /** |
||||||
50 | * Dynamically retrieve attributes on the model. |
||||||
51 | * |
||||||
52 | * @param string $key |
||||||
53 | * @return mixed |
||||||
54 | */ |
||||||
55 | public function __get($key) |
||||||
56 | { |
||||||
57 | $value = $this->getAttribute($key); |
||||||
0 ignored issues
–
show
It seems like
getAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
58 | |||||||
59 | if (is_null($value)) { |
||||||
60 | try { |
||||||
61 | if(isset($this->getMeta()->$key)) { |
||||||
62 | $value = $this->getMeta()->$key->{$this->meta_value_name}; |
||||||
0 ignored issues
–
show
The property
meta_value_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
63 | } else { |
||||||
64 | $value = NULL; |
||||||
65 | } |
||||||
66 | } catch (Exception $e) { |
||||||
0 ignored issues
–
show
|
|||||||
67 | $value = NULL; |
||||||
68 | } |
||||||
69 | } |
||||||
70 | |||||||
71 | return $value; |
||||||
72 | } |
||||||
73 | |||||||
74 | /** |
||||||
75 | * Dynamically set attributes on the model. |
||||||
76 | * |
||||||
77 | * @param string $key |
||||||
78 | * @param mixed $value |
||||||
79 | * @return void |
||||||
80 | */ |
||||||
81 | public function __set($key, $value) |
||||||
82 | { |
||||||
83 | if (array_key_exists($key, $this->getAttributes())) { |
||||||
0 ignored issues
–
show
It seems like
getAttributes() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
84 | $this->setAttribute($key, $value); |
||||||
0 ignored issues
–
show
It seems like
setAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
85 | return; |
||||||
86 | } |
||||||
87 | |||||||
88 | try { |
||||||
89 | if (isset($this->getMeta()->$key)) { |
||||||
90 | $this->getMeta()->$key->{$this->meta_value_name} = $value; |
||||||
0 ignored issues
–
show
The property
meta_value_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
91 | return; |
||||||
92 | } |
||||||
93 | } catch (Exception $e) { } |
||||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||||||
94 | |||||||
95 | if(\Config::get('database.default') === 'sqlite') { |
||||||
96 | $columns = \DB::select('PRAGMA table_info('.$this->table.')'); |
||||||
0 ignored issues
–
show
The property
table does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
97 | |||||||
98 | foreach ($columns as $column) { |
||||||
99 | if ($column->name === $key) { |
||||||
100 | $this->setAttribute($key, $value); |
||||||
101 | return; |
||||||
102 | } |
||||||
103 | } |
||||||
104 | } else { |
||||||
105 | $columns = \DB::getSchemaBuilder()->getColumnListing($this->getTable()); |
||||||
0 ignored issues
–
show
It seems like
getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
106 | |||||||
107 | // $columns = \DB::select('DESCRIBE '.$this->table); |
||||||
108 | |||||||
109 | // dd($columns); |
||||||
110 | foreach ($columns as $column) { |
||||||
111 | if ($column === $key) { |
||||||
112 | $this->setAttribute($key, $value); |
||||||
113 | return; |
||||||
114 | } |
||||||
115 | } |
||||||
116 | } |
||||||
117 | $this->getMeta()->$key = $this->newMeta(array($this->meta_key_name => $key, $this->meta_value_name => $value)); |
||||||
0 ignored issues
–
show
The property
meta_key_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
118 | } |
||||||
119 | |||||||
120 | |||||||
121 | public function __isset($key) |
||||||
122 | { |
||||||
123 | if ((isset($this->attributes[$key]) |
||||||
0 ignored issues
–
show
The property
attributes does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
124 | || isset($this->relations[$key])) |
||||||
0 ignored issues
–
show
The property
relations does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
125 | || ($this->hasGetMutator($key) && ! is_null($this->getAttributeValue($key)))) { |
||||||
0 ignored issues
–
show
It seems like
getAttributeValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
hasGetMutator() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
126 | return true; |
||||||
127 | } |
||||||
128 | return isset($this->getMeta()->$key->{$this->meta_value_name}); |
||||||
0 ignored issues
–
show
The property
meta_value_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
129 | } |
||||||
130 | |||||||
131 | public function push() |
||||||
132 | { |
||||||
133 | return parent::push() && $this->deleteMeta() && $this->saveMeta(); |
||||||
134 | } |
||||||
135 | |||||||
136 | public function save(array $options = array()) |
||||||
0 ignored issues
–
show
The parameter
$options is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
137 | { |
||||||
138 | return parent::save() && $this->deleteMeta() && $this->saveMeta(); |
||||||
139 | } |
||||||
140 | |||||||
141 | /** |
||||||
142 | * Get the data associated with this model in a usable format |
||||||
143 | * |
||||||
144 | * @return array |
||||||
145 | */ |
||||||
146 | protected function getMeta() |
||||||
147 | { |
||||||
148 | if (is_null($this->metaData)) { |
||||||
149 | $primaryKey = $this->primaryKey; |
||||||
0 ignored issues
–
show
The property
primaryKey does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
150 | |||||||
151 | if (is_null($this->primaryKey)) { |
||||||
152 | // If nothing has been set and there is no ID then there will be no data |
||||||
153 | $this->metaData = (object)[]; |
||||||
154 | } else { |
||||||
155 | $meta = $this->meta; |
||||||
0 ignored issues
–
show
The property
meta does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
156 | |||||||
157 | $niceDataArray = array(); |
||||||
158 | |||||||
159 | foreach ($meta as $data) { |
||||||
160 | $niceDataArray[$data->{$this->meta_key_name}] = $data; |
||||||
0 ignored issues
–
show
The property
meta_key_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
161 | } |
||||||
162 | |||||||
163 | $this->metaData = (object)$niceDataArray; |
||||||
164 | } |
||||||
165 | } |
||||||
166 | return $this->metaData; |
||||||
167 | } |
||||||
168 | |||||||
169 | protected function saveMeta() |
||||||
170 | { |
||||||
171 | $primaryKey = $this->primaryKey; |
||||||
0 ignored issues
–
show
The property
primaryKey does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
172 | foreach ((array)$this->getMeta() as $data) { |
||||||
173 | |||||||
174 | if (is_null($data->{$this->meta_foreign_key})) { |
||||||
0 ignored issues
–
show
The property
meta_foreign_key does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
175 | $data->{$this->meta_foreign_key} = $this->$primaryKey; |
||||||
176 | } |
||||||
177 | |||||||
178 | if(!is_null($data->{$this->meta_value_name})) { |
||||||
0 ignored issues
–
show
The property
meta_value_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
179 | $data->save(); |
||||||
180 | } |
||||||
181 | } |
||||||
182 | |||||||
183 | return true; |
||||||
184 | } |
||||||
185 | |||||||
186 | protected function deleteMeta() |
||||||
187 | { |
||||||
188 | foreach ((array)$this->getMeta() as $data) { |
||||||
189 | if(is_null($data->{$this->meta_value_name})) { |
||||||
0 ignored issues
–
show
The property
meta_value_name does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
190 | $dataID = $this->meta_primary_key; |
||||||
0 ignored issues
–
show
The property
meta_primary_key does not exist on Raystech\StarterKit\Traits\HasMeta . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
191 | $data->destroy($data->$dataID); |
||||||
192 | } |
||||||
193 | } |
||||||
194 | |||||||
195 | return true; |
||||||
196 | } |
||||||
197 | |||||||
198 | |||||||
199 | |||||||
200 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.