This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Sco\Admin\Traits; |
||
4 | |||
5 | use Illuminate\Database\Eloquent\Model; |
||
6 | use InvalidArgumentException; |
||
7 | |||
8 | trait SelectOptionsFromModel |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $optionsLabelAttribute; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $optionsValueAttribute; |
||
19 | |||
20 | /** |
||
21 | * Get the options label attribute. |
||
22 | * |
||
23 | * @return string |
||
24 | */ |
||
25 | public function getOptionsLabelAttribute() |
||
26 | { |
||
27 | return $this->optionsLabelAttribute; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Set the options label attribute. |
||
32 | * |
||
33 | * @param string $value |
||
34 | * |
||
35 | * @return $this |
||
36 | */ |
||
37 | public function setOptionsLabelAttribute($value) |
||
38 | { |
||
39 | $this->optionsLabelAttribute = $value; |
||
40 | |||
41 | return $this; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Get the options value attribute. |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getOptionsValueAttribute() |
||
50 | { |
||
51 | return $this->optionsValueAttribute; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Set the options value attribute. |
||
56 | * |
||
57 | * @param string $value |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | public function setOptionsValueAttribute($value) |
||
62 | { |
||
63 | $this->optionsValueAttribute = $value; |
||
64 | |||
65 | return $this; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Get the options model. |
||
70 | * |
||
71 | * @return Model |
||
72 | */ |
||
73 | View Code Duplication | public function getOptionsModel() |
|
0 ignored issues
–
show
|
|||
74 | { |
||
75 | $model = $this->options; |
||
0 ignored issues
–
show
The property
options does not seem to exist. Did you mean optionsLabelAttribute ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
76 | |||
77 | if (is_string($model)) { |
||
78 | $model = app($model); |
||
79 | } |
||
80 | |||
81 | if (! ($model instanceof Model)) { |
||
82 | throw new InvalidArgumentException( |
||
83 | sprintf( |
||
84 | 'The %s element[%s] options class must be instanced of "%s".', |
||
85 | $this->getType(), |
||
0 ignored issues
–
show
It seems like
getType() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
86 | $this->getName(), |
||
0 ignored issues
–
show
It seems like
getName() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
87 | Model::class |
||
88 | ) |
||
89 | ); |
||
90 | } |
||
91 | |||
92 | return $model; |
||
93 | } |
||
94 | |||
95 | protected function isOptionsModel() |
||
96 | { |
||
97 | return is_string($this->options) || $this->options instanceof Model; |
||
0 ignored issues
–
show
The property
options does not seem to exist. Did you mean optionsLabelAttribute ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Get the options from model. |
||
102 | * |
||
103 | * @return \Illuminate\Support\Collection |
||
104 | */ |
||
105 | protected function getOptionsFromModel() |
||
106 | { |
||
107 | if (is_null(($label = $this->getOptionsLabelAttribute()))) { |
||
108 | throw new InvalidArgumentException( |
||
109 | sprintf( |
||
110 | 'The %s element[%s] options must set label attribute', |
||
111 | $this->getType(), |
||
0 ignored issues
–
show
It seems like
getType() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
112 | $this->getName() |
||
0 ignored issues
–
show
It seems like
getName() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
113 | ) |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | $model = $this->getOptionsModel(); |
||
118 | |||
119 | /** |
||
120 | * @var \Illuminate\Support\Collection $results |
||
121 | */ |
||
122 | $results = $model->get(); |
||
123 | |||
124 | $key = $this->getOptionsValueAttribute() ?: $model->getKeyName(); |
||
125 | |||
126 | return $results->pluck($label, $key); |
||
127 | } |
||
128 | } |
||
129 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.