Complex classes like AttributeObserverTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AttributeObserverTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | trait AttributeObserverTrait |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * The ID of the attribute to create the values for. |
||
45 | * |
||
46 | * @var integer |
||
47 | */ |
||
48 | protected $attributeId; |
||
49 | |||
50 | /** |
||
51 | * The attribute code of the attribute to create the values for. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $attributeCode; |
||
56 | |||
57 | /** |
||
58 | * The backend type of the attribute to create the values for. |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | protected $backendType; |
||
63 | |||
64 | /** |
||
65 | * The attribute value in process. |
||
66 | * |
||
67 | * @var mixed |
||
68 | */ |
||
69 | protected $attributeValue; |
||
70 | |||
71 | /** |
||
72 | * The array with the column keys that has to be cleaned up when their values are empty. |
||
73 | * |
||
74 | * @var array |
||
75 | */ |
||
76 | protected $cleanUpEmptyColumnKeys; |
||
77 | |||
78 | /** |
||
79 | * The array with the default column values. |
||
80 | * |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $defaultColumnValues; |
||
84 | |||
85 | /** |
||
86 | * The attribute we're actually processing. |
||
87 | * |
||
88 | * @var array |
||
89 | */ |
||
90 | protected $attribute; |
||
91 | |||
92 | /** |
||
93 | * The entity's existing attribues. |
||
94 | * |
||
95 | * @var array |
||
96 | */ |
||
97 | protected $attributes; |
||
98 | |||
99 | /** |
||
100 | * The operation that has to be executed to update the attribute. |
||
101 | * |
||
102 | * @var string |
||
103 | */ |
||
104 | protected $operation; |
||
105 | |||
106 | /** |
||
107 | * The attribute code that has to be processed. |
||
108 | * |
||
109 | * @return string The attribute code |
||
110 | */ |
||
111 | 1 | public function getAttributeCode() |
|
112 | { |
||
113 | 1 | return $this->attributeCode; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * The attribute value that has to be processed. |
||
118 | * |
||
119 | * @return string The attribute value |
||
120 | */ |
||
121 | 1 | public function getAttributeValue() |
|
122 | { |
||
123 | 1 | return $this->attributeValue; |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * Get empty attribute value constant from global konfiguration |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | 7 | private function getEmptyAttributeValueConstant() |
|
132 | { |
||
133 | 7 | return $this->getSubject()->getConfiguration()->getConfiguration()->getEmptyAttributeValueConstant(); |
|
|
|||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Remove all the empty values from the row and return the cleared row. |
||
138 | * |
||
139 | * @return array The cleared row |
||
140 | */ |
||
141 | 7 | protected function clearRow() |
|
142 | { |
||
143 | |||
144 | // initialize the array with the column keys that has to be cleaned-up |
||
145 | 7 | $this->cleanUpEmptyColumnKeys = array(); |
|
146 | |||
147 | // query whether or not column names that has to be cleaned up have been configured |
||
148 | 7 | if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS)) { |
|
149 | // if yes, load the column names |
||
150 | $cleanUpEmptyColumns = $this->getSubject()->getCleanUpColumns(); |
||
151 | |||
152 | // translate the column names into column keys |
||
153 | foreach ($cleanUpEmptyColumns as $cleanUpEmptyColumn) { |
||
154 | if ($this->hasHeader($cleanUpEmptyColumn)) { |
||
155 | $this->cleanUpEmptyColumnKeys[$cleanUpEmptyColumn] = $this->getHeader($cleanUpEmptyColumn); |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 | // initialize the array with the default column values |
||
161 | 7 | $this->defaultColumnValues = array(); |
|
162 | |||
163 | // iterate over the default column values to figure out whether or not the column exists |
||
164 | 7 | $defaultColumnValues = $this->getSubject()->getDefaultColumnValues(); |
|
165 | |||
166 | // prepare the array with the default column values, BUT we only take |
||
167 | // care of default columns WITHOUT any value, because in only in this |
||
168 | // case the default EAV value from the DB should be used when a empty |
||
169 | // column value has been found to create a NEW attribute value |
||
170 | 7 | foreach ($defaultColumnValues as $columnName => $defaultColumnValue) { |
|
171 | if ($defaultColumnValue === '') { |
||
172 | $this->defaultColumnValues[$columnName] = $this->getHeader($columnName); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | 7 | $emptyValueDefinition = $this->getEmptyAttributeValueConstant(); |
|
177 | // load the header keys |
||
178 | 7 | $headers = in_array($emptyValueDefinition, $this->row, true) ? array_flip($this->getHeaders()) : []; |
|
179 | // remove all the empty values from the row, expected the columns has to be cleaned-up |
||
180 | 7 | foreach ($this->row as $key => $value) { |
|
181 | 7 | if ($value === $emptyValueDefinition) { |
|
182 | $this->cleanUpEmptyColumnKeys[$headers[$key]] = $key; |
||
183 | $this->row[$key] = ''; |
||
184 | } |
||
185 | // query whether or not the value is empty AND the column has NOT to be cleaned-up |
||
186 | 7 | if (($value === null || $value === '') && |
|
187 | 7 | in_array($key, $this->cleanUpEmptyColumnKeys) === false && |
|
188 | 7 | in_array($key, $this->defaultColumnValues) === false |
|
189 | ) { |
||
190 | 7 | unset($this->row[$key]); |
|
191 | } |
||
192 | } |
||
193 | |||
194 | // finally return the clean row |
||
195 | 7 | return $this->row; |
|
196 | } |
||
197 | |||
198 | /** |
||
199 | * Returns the value(s) of the primary key column(s). As the primary key column can |
||
200 | * also consist of two columns, the return value can be an array also. |
||
201 | * |
||
202 | * @return mixed The primary key value(s) |
||
203 | */ |
||
204 | 7 | protected function getPrimaryKeyValue() |
|
205 | { |
||
206 | 7 | return $this->getValue($this->getPrimaryKeyColumnName()); |
|
207 | } |
||
208 | |||
209 | /** |
||
210 | * Process the observer's business logic. |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | 7 | protected function process() |
|
215 | { |
||
216 | |||
217 | // initialize the store view code |
||
218 | 7 | $this->prepareStoreViewCode(); |
|
219 | |||
220 | // load the store ID, use the admin store if NO store view code has been set |
||
221 | 7 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); |
|
222 | |||
223 | // load the entity's existing attributes |
||
224 | 7 | $this->getAttributesByPrimaryKeyAndStoreId($this->getPrimaryKey(), $storeId); |
|
225 | |||
226 | // load the store view - if no store view has been set, we assume the admin |
||
227 | // store view, which will contain the default (fallback) attribute values |
||
228 | 7 | $storeViewCode = $this->getSubject()->getStoreViewCode(StoreViewCodes::ADMIN); |
|
229 | |||
230 | // query whether or not the row has already been processed |
||
231 | 7 | if ($this->storeViewHasBeenProcessed($pk = $this->getPrimaryKeyValue(), $storeViewCode)) { |
|
232 | // log a message |
||
233 | $this->getSystemLogger()->warning( |
||
234 | $this->appendExceptionSuffix( |
||
235 | sprintf( |
||
236 | 'Attributes for "%s" "%s" + store view code "%s" has already been processed', |
||
237 | $this->getPrimaryKeyColumnName(), |
||
238 | $pk, |
||
239 | $storeViewCode |
||
240 | ) |
||
241 | ) |
||
242 | ); |
||
243 | |||
244 | // return immediately |
||
245 | return; |
||
246 | } |
||
247 | |||
248 | // load the attributes by the found attribute set and the backend types |
||
249 | 7 | $attributes = $this->getAttributes(); |
|
250 | 7 | $backendTypes = $this->getBackendTypes(); |
|
251 | |||
252 | // load the header keys |
||
253 | 7 | $headers = array_flip($this->getHeaders()); |
|
254 | |||
255 | // remove all the empty values from the row |
||
256 | 7 | $row = $this->clearRow(); |
|
257 | |||
258 | // iterate over the attributes and append them to the row |
||
259 | 7 | foreach ($row as $key => $attributeValue) { |
|
260 | // query whether or not attribute with the found code exists |
||
261 | 6 | if (!isset($attributes[$attributeCode = $headers[$key]])) { |
|
262 | // log a message in debug mode |
||
263 | 1 | if ($this->isDebugMode()) { |
|
264 | 1 | $this->getSystemLogger()->debug( |
|
265 | 1 | $this->appendExceptionSuffix( |
|
266 | 1 | sprintf( |
|
267 | 1 | 'Can\'t find attribute with attribute code "%s"', |
|
268 | 1 | $attributeCode |
|
269 | ) |
||
270 | ) |
||
271 | ); |
||
272 | } |
||
273 | |||
274 | // stop processing |
||
275 | 1 | continue; |
|
276 | } else { |
||
277 | // log a message in debug mode |
||
278 | 5 | if ($this->isDebugMode()) { |
|
279 | // log a message in debug mode |
||
280 | 2 | $this->getSystemLogger()->debug( |
|
281 | 2 | $this->appendExceptionSuffix( |
|
282 | 2 | sprintf( |
|
283 | 2 | 'Found attribute with attribute code "%s"', |
|
284 | 2 | $attributeCode |
|
285 | ) |
||
286 | ) |
||
287 | ); |
||
288 | } |
||
289 | } |
||
290 | |||
291 | // if yes, load the attribute by its code |
||
292 | 5 | $this->attribute = $attributes[$attributeCode]; |
|
293 | |||
294 | // load the backend type => to find the apropriate entity |
||
295 | 5 | $backendType = $this->attribute[MemberNames::BACKEND_TYPE]; |
|
296 | 5 | if ($backendType === null) { |
|
297 | // log a message in debug mode |
||
298 | 1 | $this->getSystemLogger()->warning( |
|
299 | 1 | $this->appendExceptionSuffix( |
|
300 | 1 | sprintf( |
|
301 | 1 | 'Found EMTPY backend type for attribute "%s"', |
|
302 | 1 | $attributeCode |
|
303 | ) |
||
304 | ) |
||
305 | ); |
||
306 | // stop processing |
||
307 | 1 | continue; |
|
308 | } |
||
309 | |||
310 | // do nothing on static backend type |
||
311 | 4 | if ($backendType === BackendTypeKeys::BACKEND_TYPE_STATIC) { |
|
312 | 1 | continue; |
|
313 | } |
||
314 | |||
315 | // query whether or not we've found a supported backend type |
||
316 | 3 | if (isset($backendTypes[$backendType])) { |
|
317 | // initialize attribute ID/code and backend type |
||
318 | 2 | $this->backendType = $backendType; |
|
319 | 2 | $this->attributeCode = $attributeCode; |
|
320 | 2 | $this->attributeId = $this->attribute[MemberNames::ATTRIBUTE_ID]; |
|
321 | |||
322 | // set the attribute value as well as the original attribute value |
||
323 | 2 | $this->attributeValue = $attributeValue; |
|
324 | |||
325 | // initialize the persist method for the found backend type |
||
326 | 2 | list ($persistMethod, , $deleteMethod) = $backendTypes[$backendType]; |
|
327 | |||
328 | // prepare the attribute vale and query whether or not it has to be persisted |
||
329 | 2 | if ($this->hasChanges($value = $this->initializeAttribute($this->prepareAttributes()))) { |
|
330 | // query whether or not the entity's value has to be persisted or deleted. if the value is |
||
331 | // an empty string and the status is UPDATE, then the value exists and has to be deleted |
||
332 | // We need to user $attributeValue instead of $value[MemberNames::VALUE] in cases where |
||
333 | // value was casted by attribute type. E.g. special_price = 0 if value is empty string in CSV |
||
334 | 2 | switch ($this->operation) { |
|
335 | // create/update the attribute |
||
336 | 2 | case OperationNames::CREATE: |
|
337 | 1 | case OperationNames::UPDATE: |
|
338 | 1 | $this->$persistMethod($value); |
|
339 | 1 | break; |
|
340 | // delete the attribute |
||
341 | 1 | case OperationNames::DELETE: |
|
342 | $this->$deleteMethod(array(MemberNames::VALUE_ID => $value[MemberNames::VALUE_ID])); |
||
343 | break; |
||
344 | // skip the attribute |
||
345 | 1 | case OperationNames::SKIP: |
|
346 | 1 | $this->getSubject()->getSystemLogger()->debug(sprintf('Skipped processing attribute "%s"', $attributeCode)); |
|
347 | 1 | break; |
|
348 | // should never happen |
||
349 | default: |
||
350 | 2 | $this->getSubject()->getSystemLogger()->debug(sprintf('Found invalid entity status "%s" for attribute "%s"', $value[MemberNames::VALUE] ?? 'NULL', $attributeCode)); |
|
351 | } |
||
352 | } else { |
||
353 | $this->getSubject()->getSystemLogger()->debug(sprintf('Skip to persist value for attribute "%s"', $attributeCode)); |
||
354 | } |
||
355 | |||
356 | // continue with the next value |
||
357 | 2 | continue; |
|
358 | } |
||
359 | |||
360 | // log the debug message |
||
361 | 1 | $this->getSystemLogger()->debug( |
|
362 | 1 | $this->getSubject()->appendExceptionSuffix( |
|
363 | 1 | sprintf( |
|
364 | 1 | 'Found invalid backend type %s for attribute "%s"', |
|
365 | 1 | $backendType, |
|
366 | 1 | $attributeCode |
|
367 | ) |
||
368 | ) |
||
369 | ); |
||
370 | } |
||
371 | 7 | } |
|
372 | |||
373 | /** |
||
374 | * Prepare the attributes of the entity that has to be persisted. |
||
375 | * |
||
376 | * @return array|null The prepared attributes |
||
377 | */ |
||
378 | 2 | protected function prepareAttributes() |
|
379 | { |
||
380 | |||
381 | // load the ID of the product that has been created recently |
||
382 | 2 | $lastEntityId = $this->getPrimaryKey(); |
|
383 | |||
384 | // load the store ID, use the admin store if NO store view code has been set |
||
385 | 2 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); |
|
386 | |||
387 | // prepare the attribute values |
||
388 | 2 | return $this->initializeEntity( |
|
389 | 2 | $this->loadRawEntity( |
|
390 | array( |
||
391 | 2 | $this->getPrimaryKeyMemberName() => $lastEntityId, |
|
392 | 2 | MemberNames::ATTRIBUTE_ID => $this->attributeId, |
|
393 | 2 | MemberNames::STORE_ID => $storeId |
|
394 | ) |
||
395 | ) |
||
396 | ); |
||
397 | } |
||
398 | |||
399 | /** |
||
400 | * Initialize the category product with the passed attributes and returns an instance. |
||
401 | * |
||
402 | * @param array $attr The category product attributes |
||
403 | * |
||
404 | * @return array The initialized category product |
||
405 | */ |
||
406 | 2 | protected function initializeAttribute(array $attr) |
|
407 | { |
||
408 | 2 | return $attr; |
|
409 | } |
||
410 | |||
411 | /** |
||
412 | * Load's and return's a raw customer entity without primary key but the mandatory members only and nulled values. |
||
413 | * |
||
414 | * @param array $data An array with data that will be used to initialize the raw entity with |
||
415 | * |
||
416 | * @return array The initialized entity |
||
417 | */ |
||
418 | 2 | protected function loadRawEntity(array $data = array()) |
|
419 | { |
||
420 | |||
421 | // laod the callbacks for the actual attribute code |
||
422 | 2 | $callbacks = $this->getCallbacksByType($this->attributeCode); |
|
423 | |||
424 | // invoke the pre-cast callbacks |
||
425 | 2 | foreach ($callbacks as $callback) { |
|
426 | 1 | $this->attributeValue = $callback->handle($this); |
|
427 | } |
||
428 | |||
429 | // load the default value |
||
430 | 2 | $defaultValue = isset($this->attribute[MemberNames::DEFAULT_VALUE]) ? $this->attribute[MemberNames::DEFAULT_VALUE] : ''; |
|
431 | |||
432 | // load the value that has to be casted |
||
433 | 2 | $value = $this->attributeValue === '' || $this->attributeValue === null ? $defaultValue : $this->attributeValue; |
|
434 | |||
435 | // cast the value |
||
436 | 2 | $castedValue = $this->castValueByBackendType($this->backendType, $value); |
|
437 | |||
438 | // merge the casted value into the passed data and return it |
||
439 | 2 | return array_merge(array(MemberNames::VALUE => $castedValue), $data); |
|
440 | } |
||
441 | |||
442 | /** |
||
443 | * Initialize's and return's a new entity with the status 'create'. |
||
444 | * |
||
445 | * @param array $attr The attributes to merge into the new entity |
||
446 | * |
||
447 | * @return array The initialized entity |
||
448 | */ |
||
449 | 2 | protected function initializeEntity(array $attr = array()) |
|
450 | { |
||
451 | |||
452 | // initialize the operation name |
||
453 | 2 | $this->operation = OperationNames::CREATE; |
|
454 | |||
455 | // query whether or not the colunm IS empty and it is NOT in the |
||
456 | // array with the default column values, because in that case we |
||
457 | // want to skip processing the attribute |
||
458 | 2 | if (array_key_exists($this->attributeCode, $this->defaultColumnValues) === false && ($this->attributeValue === '' || $this->attributeValue == null)) { |
|
459 | 1 | $this->operation = OperationNames::SKIP; |
|
460 | } |
||
461 | |||
462 | // initialize the entity with the passed data |
||
463 | 2 | return parent::initializeEntity($attr); |
|
464 | } |
||
465 | |||
466 | /** |
||
467 | * Merge's and return's the entity with the passed attributes and set's the |
||
468 | * passed status. |
||
469 | * |
||
470 | * @param array $entity The entity to merge the attributes into |
||
471 | * @param array $attr The attributes to be merged |
||
472 | * @param string|null $changeSetName The change set name to use |
||
473 | * |
||
474 | * @return array The merged entity |
||
475 | */ |
||
476 | protected function mergeEntity(array $entity, array $attr, $changeSetName = null) |
||
505 | |||
506 | /** |
||
507 | * Return's the array with callbacks for the passed type. |
||
508 | * |
||
509 | * @param string $type The type of the callbacks to return |
||
510 | * |
||
511 | * @return array The callbacks |
||
512 | */ |
||
513 | 2 | protected function getCallbacksByType($type) |
|
514 | { |
||
515 | 2 | return $this->getSubject()->getCallbacksByType($type); |
|
516 | } |
||
517 | |||
518 | /** |
||
519 | * Return's mapping for the supported backend types (for the product entity) => persist methods. |
||
520 | * |
||
521 | * @return array The mapping for the supported backend types |
||
522 | */ |
||
523 | 7 | protected function getBackendTypes() |
|
524 | { |
||
525 | 7 | return $this->getSubject()->getBackendTypes(); |
|
526 | } |
||
527 | |||
528 | /** |
||
529 | * Return's the attributes for the attribute set of the product that has to be created. |
||
530 | * |
||
531 | * @return array The attributes |
||
532 | * @throws \Exception |
||
533 | */ |
||
534 | 7 | protected function getAttributes() |
|
535 | { |
||
536 | 7 | return $this->getSubject()->getAttributes(); |
|
537 | } |
||
538 | |||
539 | /** |
||
540 | * Intializes the existing attributes for the entity with the passed primary key. |
||
541 | * |
||
542 | * @param string $pk The primary key of the entity to load the attributes for |
||
543 | * @param integer $storeId The ID of the store view to load the attributes for |
||
544 | * |
||
545 | * @return array The entity attributes |
||
546 | */ |
||
547 | abstract protected function getAttributesByPrimaryKeyAndStoreId($pk, $storeId); |
||
548 | |||
549 | /** |
||
550 | * Return's the logger with the passed name, by default the system logger. |
||
551 | * |
||
552 | * @param string $name The name of the requested system logger |
||
553 | * |
||
554 | * @return \Psr\Log\LoggerInterface The logger instance |
||
555 | * @throws \Exception Is thrown, if the requested logger is NOT available |
||
556 | */ |
||
557 | abstract protected function getSystemLogger($name = LoggerKeys::SYSTEM); |
||
558 | |||
559 | /** |
||
560 | * Return's the PK to create the product => attribute relation. |
||
561 | * |
||
562 | * @return integer The PK to create the relation with |
||
563 | */ |
||
564 | abstract protected function getPrimaryKey(); |
||
565 | |||
566 | /** |
||
567 | * Return's the PK column name to create the product => attribute relation. |
||
568 | * |
||
569 | * @return string The PK column name |
||
570 | */ |
||
571 | abstract protected function getPrimaryKeyMemberName(); |
||
572 | |||
573 | /** |
||
574 | * Return's the column name that contains the primary key. |
||
575 | * |
||
576 | * @return string the column name that contains the primary key |
||
577 | */ |
||
578 | abstract protected function getPrimaryKeyColumnName(); |
||
579 | |||
580 | /** |
||
581 | * Queries whether or not the passed PK and store view code has already been processed. |
||
582 | * |
||
583 | * @param string $pk The PK to check been processed |
||
584 | * @param string $storeViewCode The store view code to check been processed |
||
585 | * |
||
586 | * @return boolean TRUE if the PK and store view code has been processed, else FALSE |
||
587 | */ |
||
588 | abstract protected function storeViewHasBeenProcessed($pk, $storeViewCode); |
||
589 | |||
590 | /** |
||
591 | * Persist's the passed varchar attribute. |
||
592 | * |
||
593 | * @param array $attribute The attribute to persist |
||
594 | * |
||
595 | * @return void |
||
596 | */ |
||
597 | abstract protected function persistVarcharAttribute($attribute); |
||
598 | |||
599 | /** |
||
600 | * Persist's the passed integer attribute. |
||
601 | * |
||
602 | * @param array $attribute The attribute to persist |
||
603 | * |
||
604 | * @return void |
||
605 | */ |
||
606 | abstract protected function persistIntAttribute($attribute); |
||
607 | |||
608 | /** |
||
609 | * Persist's the passed decimal attribute. |
||
610 | * |
||
611 | * @param array $attribute The attribute to persist |
||
612 | * |
||
613 | * @return void |
||
614 | */ |
||
615 | abstract protected function persistDecimalAttribute($attribute); |
||
616 | |||
617 | /** |
||
618 | * Persist's the passed datetime attribute. |
||
619 | * |
||
620 | * @param array $attribute The attribute to persist |
||
621 | * |
||
622 | * @return void |
||
623 | */ |
||
624 | abstract protected function persistDatetimeAttribute($attribute); |
||
625 | |||
626 | /** |
||
627 | * Persist's the passed text attribute. |
||
628 | * |
||
629 | * @param array $attribute The attribute to persist |
||
630 | * |
||
631 | * @return void |
||
632 | */ |
||
633 | abstract protected function persistTextAttribute($attribute); |
||
634 | |||
635 | /** |
||
636 | * Delete's the datetime attribute with the passed value ID. |
||
637 | * |
||
638 | * @param array $row The attributes of the entity to delete |
||
639 | * @param string|null $name The name of the prepared statement that has to be executed |
||
640 | * |
||
641 | * @return void |
||
642 | */ |
||
643 | abstract protected function deleteDatetimeAttribute(array $row, $name = null); |
||
644 | |||
645 | /** |
||
646 | * Delete's the decimal attribute with the passed value ID. |
||
647 | * |
||
648 | * @param array $row The attributes of the entity to delete |
||
649 | * @param string|null $name The name of the prepared statement that has to be executed |
||
650 | * |
||
651 | * @return void |
||
652 | */ |
||
653 | abstract protected function deleteDecimalAttribute(array $row, $name = null); |
||
654 | |||
655 | /** |
||
656 | * Delete's the integer attribute with the passed value ID. |
||
657 | * |
||
658 | * @param array $row The attributes of the entity to delete |
||
659 | * @param string|null $name The name of the prepared statement that has to be executed |
||
660 | * |
||
661 | * @return void |
||
662 | */ |
||
663 | abstract protected function deleteIntAttribute(array $row, $name = null); |
||
664 | |||
665 | /** |
||
666 | * Delete's the text attribute with the passed value ID. |
||
667 | * |
||
668 | * @param array $row The attributes of the entity to delete |
||
669 | * @param string|null $name The name of the prepared statement that has to be executed |
||
670 | * |
||
671 | * @return void |
||
672 | */ |
||
673 | abstract protected function deleteTextAttribute(array $row, $name = null); |
||
674 | |||
675 | /** |
||
676 | * Delete's the varchar attribute with the passed value ID. |
||
677 | * |
||
678 | * @param array $row The attributes of the entity to delete |
||
679 | * @param string|null $name The name of the prepared statement that has to be executed |
||
680 | * |
||
681 | * @return void |
||
682 | */ |
||
683 | abstract protected function deleteVarcharAttribute(array $row, $name = null); |
||
684 | |||
685 | /** |
||
686 | * Query whether or not the entity has to be processed. |
||
687 | * |
||
688 | * @param array $entity The entity to query for |
||
689 | * |
||
690 | * @return boolean TRUE if the entity has to be processed, else FALSE |
||
691 | */ |
||
692 | abstract protected function hasChanges(array $entity); |
||
693 | |||
694 | /** |
||
695 | * Query whether or not a value for the column with the passed name exists. |
||
696 | * |
||
697 | * @param string $name The column name to query for a valid value |
||
698 | * |
||
699 | * @return boolean TRUE if the value is set, else FALSE |
||
700 | */ |
||
701 | abstract protected function hasValue($name); |
||
702 | } |
||
703 |
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
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.