1 | <?php |
||
8 | class BaseAttribute |
||
9 | { |
||
10 | /** |
||
11 | * Attribute Type Constant. |
||
12 | */ |
||
13 | const ATTRIBUTE_TYPE = ''; |
||
14 | |||
15 | /** |
||
16 | * View Path for this Attribute Type |
||
17 | * Defaults to flare::admin.attributes which outputs |
||
18 | * a warning callout notifying the user that the field |
||
19 | * view does not yet exist. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $viewpath = 'flare::admin.attributes'; |
||
24 | |||
25 | /** |
||
26 | * Attribute. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $attribute; |
||
31 | |||
32 | /** |
||
33 | * Field. |
||
34 | * |
||
35 | * @var mixed |
||
36 | */ |
||
37 | protected $field; |
||
38 | |||
39 | /** |
||
40 | * Value. |
||
41 | * |
||
42 | * @var \Illuminate\Database\Eloquent\Model |
||
43 | */ |
||
44 | protected $value; |
||
45 | |||
46 | /** |
||
47 | * Eloquent Model. |
||
48 | * |
||
49 | * @var \Illuminate\Database\Eloquent\Model |
||
50 | */ |
||
51 | protected $model; |
||
52 | |||
53 | /** |
||
54 | * Model Manager. |
||
55 | * |
||
56 | * @var \LaravelFlare\Flare\Admin\Models\ModelAdmin |
||
57 | */ |
||
58 | protected $modelManager; |
||
59 | |||
60 | /** |
||
61 | * __construct. |
||
62 | * |
||
63 | * @param string $attribute |
||
64 | * @param string $field |
||
65 | * @param string $modelManager |
||
66 | */ |
||
67 | public function __construct($attribute, $field, $value, $modelManager = null) |
||
78 | |||
79 | /** |
||
80 | * Returns the View to Render as an HTMLString |
||
81 | * |
||
82 | * @param boolean $view |
||
83 | * |
||
84 | * @return /Illuminate/Support/String |
||
85 | */ |
||
86 | public function render($view = false) |
||
94 | |||
95 | /** |
||
96 | * Renders the Add (Create) Field View. |
||
97 | * |
||
98 | * @return \Illuminate\View\View |
||
99 | */ |
||
100 | public function renderAdd() |
||
104 | |||
105 | /** |
||
106 | * Renders the Edit (Update) Field View. |
||
107 | * |
||
108 | * @return \Illuminate\View\View |
||
109 | */ |
||
110 | public function renderEdit() |
||
114 | |||
115 | /** |
||
116 | * Renders the Clone (Update) Field View. |
||
117 | * |
||
118 | * @return \Illuminate\View\View |
||
119 | */ |
||
120 | public function renderClone() |
||
128 | |||
129 | /** |
||
130 | * Renders the Viewable Field View. |
||
131 | * |
||
132 | * @return \Illuminate\View\View |
||
133 | */ |
||
134 | public function renderView() |
||
138 | |||
139 | /** |
||
140 | * Getter for Attribute. |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getAttribute() |
||
148 | |||
149 | /** |
||
150 | * Getter for Field. |
||
151 | * |
||
152 | * @return mixed |
||
153 | */ |
||
154 | public function getField() |
||
160 | |||
161 | /** |
||
162 | * Returns the current value |
||
163 | * |
||
164 | * @return mixed |
||
165 | */ |
||
166 | public function getValue() |
||
178 | |||
179 | /** |
||
180 | * Returns the old or current value |
||
181 | * |
||
182 | * @return mixed |
||
183 | */ |
||
184 | public function getOldValue() |
||
188 | |||
189 | /** |
||
190 | * Gets Field Options if they are defined. |
||
191 | */ |
||
192 | public function getFieldOptions() |
||
208 | |||
209 | /** |
||
210 | * Accessor for Model. |
||
211 | * |
||
212 | * @var \Illuminate\Database\Eloquent\Model |
||
213 | */ |
||
214 | public function getModel() |
||
218 | |||
219 | /** |
||
220 | * Accessor for Model. |
||
221 | * |
||
222 | * @var \LaravelFlare\Flare\Admin\Models\ModelAdmin |
||
223 | */ |
||
224 | public function getModelManager() |
||
228 | |||
229 | /** |
||
230 | * Acessor for Attribute Type converted to Title Case. |
||
231 | * |
||
232 | * @return string |
||
233 | */ |
||
234 | public function getAttributeType() |
||
238 | |||
239 | /** |
||
240 | * Acessor for Attribute Title converted to Title Case with Spaces. |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | public function getAttributeTitle() |
||
248 | |||
249 | /** |
||
250 | * Returns all of the accessible data for the Attirbute View |
||
251 | * |
||
252 | * @return array |
||
253 | */ |
||
254 | protected function viewData() |
||
267 | } |
||
268 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.