Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Selfprice 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 Selfprice, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | abstract class Selfprice implements ActiveRecordInterface |
||
31 | { |
||
32 | /** |
||
33 | * TableMap class name |
||
34 | */ |
||
35 | const TABLE_MAP = '\\Selfprice\\Models\\Selfprice\\Map\\SelfpriceTableMap'; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * attribute to determine if this object has previously been saved. |
||
40 | * @var boolean |
||
41 | */ |
||
42 | protected $new = true; |
||
43 | |||
44 | /** |
||
45 | * attribute to determine whether this object has been deleted. |
||
46 | * @var boolean |
||
47 | */ |
||
48 | protected $deleted = false; |
||
49 | |||
50 | /** |
||
51 | * The columns that have been modified in current object. |
||
52 | * Tracking modified columns allows us to only update modified columns. |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $modifiedColumns = array(); |
||
56 | |||
57 | /** |
||
58 | * The (virtual) columns that are added at runtime |
||
59 | * The formatters can add supplementary columns based on a resultset |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $virtualColumns = array(); |
||
63 | |||
64 | /** |
||
65 | * The value for the id field. |
||
66 | * @var int |
||
67 | */ |
||
68 | protected $id; |
||
69 | |||
70 | /** |
||
71 | * The value for the name field. |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $name; |
||
75 | |||
76 | /** |
||
77 | * The value for the datecreate field. |
||
78 | * @var \DateTime |
||
79 | */ |
||
80 | protected $datecreate; |
||
81 | |||
82 | /** |
||
83 | * The value for the desc field. |
||
84 | * @var string |
||
85 | */ |
||
86 | protected $desc; |
||
87 | |||
88 | /** |
||
89 | * Flag to prevent endless save loop, if this object is referenced |
||
90 | * by another object which falls in this transaction. |
||
91 | * |
||
92 | * @var boolean |
||
93 | */ |
||
94 | protected $alreadyInSave = false; |
||
95 | |||
96 | /** |
||
97 | * Initializes internal state of Selfprice\Models\Selfprice\Base\Selfprice object. |
||
98 | */ |
||
99 | public function __construct() |
||
102 | |||
103 | /** |
||
104 | * Returns whether the object has been modified. |
||
105 | * |
||
106 | * @return boolean True if the object has been modified. |
||
107 | */ |
||
108 | public function isModified() |
||
112 | |||
113 | /** |
||
114 | * Has specified column been modified? |
||
115 | * |
||
116 | * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID |
||
117 | * @return boolean True if $col has been modified. |
||
118 | */ |
||
119 | public function isColumnModified($col) |
||
123 | |||
124 | /** |
||
125 | * Get the columns that have been modified in this object. |
||
126 | * @return array A unique list of the modified column names for this object. |
||
127 | */ |
||
128 | public function getModifiedColumns() |
||
132 | |||
133 | /** |
||
134 | * Returns whether the object has ever been saved. This will |
||
135 | * be false, if the object was retrieved from storage or was created |
||
136 | * and then saved. |
||
137 | * |
||
138 | * @return boolean true, if the object has never been persisted. |
||
139 | */ |
||
140 | public function isNew() |
||
144 | |||
145 | /** |
||
146 | * Setter for the isNew attribute. This method will be called |
||
147 | * by Propel-generated children and objects. |
||
148 | * |
||
149 | * @param boolean $b the state of the object. |
||
150 | */ |
||
151 | public function setNew($b) |
||
155 | |||
156 | /** |
||
157 | * Whether this object has been deleted. |
||
158 | * @return boolean The deleted state of this object. |
||
159 | */ |
||
160 | public function isDeleted() |
||
164 | |||
165 | /** |
||
166 | * Specify whether this object has been deleted. |
||
167 | * @param boolean $b The deleted state of this object. |
||
168 | * @return void |
||
169 | */ |
||
170 | public function setDeleted($b) |
||
174 | |||
175 | /** |
||
176 | * Sets the modified state for the object to be false. |
||
177 | * @param string $col If supplied, only the specified column is reset. |
||
178 | * @return void |
||
179 | */ |
||
180 | View Code Duplication | public function resetModified($col = null) |
|
190 | |||
191 | /** |
||
192 | * Compares this with another <code>Selfprice</code> instance. If |
||
193 | * <code>obj</code> is an instance of <code>Selfprice</code>, delegates to |
||
194 | * <code>equals(Selfprice)</code>. Otherwise, returns <code>false</code>. |
||
195 | * |
||
196 | * @param mixed $obj The object to compare to. |
||
197 | * @return boolean Whether equal to the object specified. |
||
198 | */ |
||
199 | View Code Duplication | public function equals($obj) |
|
215 | |||
216 | /** |
||
217 | * Get the associative array of the virtual columns in this object |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | public function getVirtualColumns() |
||
225 | |||
226 | /** |
||
227 | * Checks the existence of a virtual column in this object |
||
228 | * |
||
229 | * @param string $name The virtual column name |
||
230 | * @return boolean |
||
231 | */ |
||
232 | public function hasVirtualColumn($name) |
||
236 | |||
237 | /** |
||
238 | * Get the value of a virtual column in this object |
||
239 | * |
||
240 | * @param string $name The virtual column name |
||
241 | * @return mixed |
||
242 | * |
||
243 | * @throws PropelException |
||
244 | */ |
||
245 | View Code Duplication | public function getVirtualColumn($name) |
|
253 | |||
254 | /** |
||
255 | * Set the value of a virtual column in this object |
||
256 | * |
||
257 | * @param string $name The virtual column name |
||
258 | * @param mixed $value The value to give to the virtual column |
||
259 | * |
||
260 | * @return $this|Selfprice The current object, for fluid interface |
||
261 | */ |
||
262 | public function setVirtualColumn($name, $value) |
||
268 | |||
269 | /** |
||
270 | * Logs a message using Propel::log(). |
||
271 | * |
||
272 | * @param string $msg |
||
273 | * @param int $priority One of the Propel::LOG_* logging levels |
||
274 | * @return boolean |
||
275 | */ |
||
276 | protected function log($msg, $priority = Propel::LOG_INFO) |
||
280 | |||
281 | /** |
||
282 | * Export the current object properties to a string, using a given parser format |
||
283 | * <code> |
||
284 | * $book = BookQuery::create()->findPk(9012); |
||
285 | * echo $book->exportTo('JSON'); |
||
286 | * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
287 | * </code> |
||
288 | * |
||
289 | * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
290 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. |
||
291 | * @return string The exported data |
||
292 | */ |
||
293 | View Code Duplication | public function exportTo($parser, $includeLazyLoadColumns = true) |
|
301 | |||
302 | /** |
||
303 | * Clean up internal collections prior to serializing |
||
304 | * Avoids recursive loops that turn into segmentation faults when serializing |
||
305 | */ |
||
306 | public function __sleep() |
||
312 | |||
313 | /** |
||
314 | * Get the [id] column value. |
||
315 | * |
||
316 | * @return int |
||
317 | */ |
||
318 | public function getId() |
||
322 | |||
323 | /** |
||
324 | * Get the [name] column value. |
||
325 | * |
||
326 | * @return string |
||
327 | */ |
||
328 | public function getName() |
||
332 | |||
333 | /** |
||
334 | * Get the [optionally formatted] temporal [datecreate] column value. |
||
335 | * |
||
336 | * |
||
337 | * @param string $format The date/time format string (either date()-style or strftime()-style). |
||
338 | * If format is NULL, then the raw DateTime object will be returned. |
||
339 | * |
||
340 | * @return string|DateTime Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 |
||
341 | * |
||
342 | * @throws PropelException - if unable to parse/validate the date/time value. |
||
343 | */ |
||
344 | public function getDatecreate($format = NULL) |
||
352 | |||
353 | /** |
||
354 | * Get the [desc] column value. |
||
355 | * |
||
356 | * @return string |
||
357 | */ |
||
358 | public function getDesc() |
||
362 | |||
363 | /** |
||
364 | * Set the value of [id] column. |
||
365 | * |
||
366 | * @param int $v new value |
||
367 | * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support) |
||
368 | */ |
||
369 | public function setId($v) |
||
382 | |||
383 | /** |
||
384 | * Set the value of [name] column. |
||
385 | * |
||
386 | * @param string $v new value |
||
387 | * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support) |
||
388 | */ |
||
389 | public function setName($v) |
||
402 | |||
403 | /** |
||
404 | * Sets the value of [datecreate] column to a normalized version of the date/time value specified. |
||
405 | * |
||
406 | * @param mixed $v string, integer (timestamp), or \DateTime value. |
||
407 | * Empty strings are treated as NULL. |
||
408 | * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support) |
||
409 | */ |
||
410 | View Code Duplication | public function setDatecreate($v) |
|
422 | |||
423 | /** |
||
424 | * Set the value of [desc] column. |
||
425 | * |
||
426 | * @param string $v new value |
||
427 | * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support) |
||
428 | */ |
||
429 | public function setDesc($v) |
||
442 | |||
443 | /** |
||
444 | * Indicates whether the columns in this object are only set to default values. |
||
445 | * |
||
446 | * This method can be used in conjunction with isModified() to indicate whether an object is both |
||
447 | * modified _and_ has some values set which are non-default. |
||
448 | * |
||
449 | * @return boolean Whether the columns in this object are only been set with default values. |
||
450 | */ |
||
451 | public function hasOnlyDefaultValues() |
||
456 | |||
457 | /** |
||
458 | * Hydrates (populates) the object variables with values from the database resultset. |
||
459 | * |
||
460 | * An offset (0-based "start column") is specified so that objects can be hydrated |
||
461 | * with a subset of the columns in the resultset rows. This is needed, for example, |
||
462 | * for results of JOIN queries where the resultset row includes columns from two or |
||
463 | * more tables. |
||
464 | * |
||
465 | * @param array $row The row returned by DataFetcher->fetch(). |
||
466 | * @param int $startcol 0-based offset column which indicates which restultset column to start with. |
||
467 | * @param boolean $rehydrate Whether this object is being re-hydrated from the database. |
||
468 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
469 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
470 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
471 | * |
||
472 | * @return int next starting column |
||
473 | * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. |
||
474 | */ |
||
475 | public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) |
||
507 | |||
508 | /** |
||
509 | * Checks and repairs the internal consistency of the object. |
||
510 | * |
||
511 | * This method is executed after an already-instantiated object is re-hydrated |
||
512 | * from the database. It exists to check any foreign keys to make sure that |
||
513 | * the objects related to the current object are correct based on foreign key. |
||
514 | * |
||
515 | * You can override this method in the stub class, but you should always invoke |
||
516 | * the base method from the overridden method (i.e. parent::ensureConsistency()), |
||
517 | * in case your model changes. |
||
518 | * |
||
519 | * @throws PropelException |
||
520 | */ |
||
521 | public function ensureConsistency() |
||
524 | |||
525 | /** |
||
526 | * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. |
||
527 | * |
||
528 | * This will only work if the object has been saved and has a valid primary key set. |
||
529 | * |
||
530 | * @param boolean $deep (optional) Whether to also de-associated any related objects. |
||
531 | * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. |
||
532 | * @return void |
||
533 | * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db |
||
534 | */ |
||
535 | View Code Duplication | public function reload($deep = false, ConnectionInterface $con = null) |
|
564 | |||
565 | /** |
||
566 | * Removes this object from datastore and sets delete attribute. |
||
567 | * |
||
568 | * @param ConnectionInterface $con |
||
569 | * @return void |
||
570 | * @throws PropelException |
||
571 | * @see Selfprice::setDeleted() |
||
572 | * @see Selfprice::isDeleted() |
||
573 | */ |
||
574 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
595 | |||
596 | /** |
||
597 | * Persists this object to the database. |
||
598 | * |
||
599 | * If the object is new, it inserts it; otherwise an update is performed. |
||
600 | * All modified related objects will also be persisted in the doSave() |
||
601 | * method. This method wraps all precipitate database operations in a |
||
602 | * single transaction. |
||
603 | * |
||
604 | * @param ConnectionInterface $con |
||
605 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
606 | * @throws PropelException |
||
607 | * @see doSave() |
||
608 | */ |
||
609 | View Code Duplication | public function save(ConnectionInterface $con = null) |
|
643 | |||
644 | /** |
||
645 | * Performs the work of inserting or updating the row in the database. |
||
646 | * |
||
647 | * If the object is new, it inserts it; otherwise an update is performed. |
||
648 | * All related objects are also updated in this method. |
||
649 | * |
||
650 | * @param ConnectionInterface $con |
||
651 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
652 | * @throws PropelException |
||
653 | * @see save() |
||
654 | */ |
||
655 | View Code Duplication | protected function doSave(ConnectionInterface $con) |
|
678 | |||
679 | /** |
||
680 | * Insert the row in the database. |
||
681 | * |
||
682 | * @param ConnectionInterface $con |
||
683 | * |
||
684 | * @throws PropelException |
||
685 | * @see doSave() |
||
686 | */ |
||
687 | protected function doInsert(ConnectionInterface $con) |
||
750 | |||
751 | /** |
||
752 | * Update the row in the database. |
||
753 | * |
||
754 | * @param ConnectionInterface $con |
||
755 | * |
||
756 | * @return Integer Number of updated rows |
||
757 | * @see doSave() |
||
758 | */ |
||
759 | protected function doUpdate(ConnectionInterface $con) |
||
766 | |||
767 | /** |
||
768 | * Retrieves a field from the object by name passed in as a string. |
||
769 | * |
||
770 | * @param string $name name |
||
771 | * @param string $type The type of fieldname the $name is of: |
||
772 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
773 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
774 | * Defaults to TableMap::TYPE_PHPNAME. |
||
775 | * @return mixed Value of field. |
||
776 | */ |
||
777 | View Code Duplication | public function getByName($name, $type = TableMap::TYPE_PHPNAME) |
|
784 | |||
785 | /** |
||
786 | * Retrieves a field from the object by Position as specified in the xml schema. |
||
787 | * Zero-based. |
||
788 | * |
||
789 | * @param int $pos position in xml schema |
||
790 | * @return mixed Value of field at $pos |
||
791 | */ |
||
792 | public function getByPosition($pos) |
||
812 | |||
813 | /** |
||
814 | * Exports the object as an array. |
||
815 | * |
||
816 | * You can specify the key type of the array by passing one of the class |
||
817 | * type constants. |
||
818 | * |
||
819 | * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
820 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
821 | * Defaults to TableMap::TYPE_PHPNAME. |
||
822 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. |
||
823 | * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion |
||
824 | * |
||
825 | * @return array an associative array containing the field names (as keys) and field values |
||
826 | */ |
||
827 | public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array()) |
||
857 | |||
858 | /** |
||
859 | * Sets a field from the object by name passed in as a string. |
||
860 | * |
||
861 | * @param string $name |
||
862 | * @param mixed $value field value |
||
863 | * @param string $type The type of fieldname the $name is of: |
||
864 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
865 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
866 | * Defaults to TableMap::TYPE_PHPNAME. |
||
867 | * @return $this|\Selfprice\Models\Selfprice\Selfprice |
||
868 | */ |
||
869 | public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) |
||
875 | |||
876 | /** |
||
877 | * Sets a field from the object by Position as specified in the xml schema. |
||
878 | * Zero-based. |
||
879 | * |
||
880 | * @param int $pos position in xml schema |
||
881 | * @param mixed $value field value |
||
882 | * @return $this|\Selfprice\Models\Selfprice\Selfprice |
||
883 | */ |
||
884 | public function setByPosition($pos, $value) |
||
903 | |||
904 | /** |
||
905 | * Populates the object using an array. |
||
906 | * |
||
907 | * This is particularly useful when populating an object from one of the |
||
908 | * request arrays (e.g. $_POST). This method goes through the column |
||
909 | * names, checking to see whether a matching key exists in populated |
||
910 | * array. If so the setByName() method is called for that column. |
||
911 | * |
||
912 | * You can specify the key type of the array by additionally passing one |
||
913 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
914 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
915 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
916 | * |
||
917 | * @param array $arr An array to populate the object from. |
||
918 | * @param string $keyType The type of keys the array uses. |
||
919 | * @return void |
||
920 | */ |
||
921 | public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) |
||
938 | |||
939 | /** |
||
940 | * Populate the current object from a string, using a given parser format |
||
941 | * <code> |
||
942 | * $book = new Book(); |
||
943 | * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
944 | * </code> |
||
945 | * |
||
946 | * You can specify the key type of the array by additionally passing one |
||
947 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
948 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
949 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
950 | * |
||
951 | * @param mixed $parser A AbstractParser instance, |
||
952 | * or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
953 | * @param string $data The source data to import from |
||
954 | * @param string $keyType The type of keys the array uses. |
||
955 | * |
||
956 | * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object, for fluid interface |
||
957 | */ |
||
958 | View Code Duplication | public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) |
|
968 | |||
969 | /** |
||
970 | * Build a Criteria object containing the values of all modified columns in this object. |
||
971 | * |
||
972 | * @return Criteria The Criteria object containing all modified values. |
||
973 | */ |
||
974 | public function buildCriteria() |
||
993 | |||
994 | /** |
||
995 | * Builds a Criteria object containing the primary key for this object. |
||
996 | * |
||
997 | * Unlike buildCriteria() this method includes the primary key values regardless |
||
998 | * of whether or not they have been modified. |
||
999 | * |
||
1000 | * @throws LogicException if no primary key is defined |
||
1001 | * |
||
1002 | * @return Criteria The Criteria object containing value(s) for primary key(s). |
||
1003 | */ |
||
1004 | public function buildPkeyCriteria() |
||
1011 | |||
1012 | /** |
||
1013 | * If the primary key is not null, return the hashcode of the |
||
1014 | * primary key. Otherwise, return the hash code of the object. |
||
1015 | * |
||
1016 | * @return int Hashcode |
||
1017 | */ |
||
1018 | View Code Duplication | public function hashCode() |
|
1033 | |||
1034 | /** |
||
1035 | * Returns the primary key for this object (row). |
||
1036 | * @return int |
||
1037 | */ |
||
1038 | public function getPrimaryKey() |
||
1042 | |||
1043 | /** |
||
1044 | * Generic method to set the primary key (id column). |
||
1045 | * |
||
1046 | * @param int $key Primary key. |
||
1047 | * @return void |
||
1048 | */ |
||
1049 | public function setPrimaryKey($key) |
||
1053 | |||
1054 | /** |
||
1055 | * Returns true if the primary key for this object is null. |
||
1056 | * @return boolean |
||
1057 | */ |
||
1058 | public function isPrimaryKeyNull() |
||
1062 | |||
1063 | /** |
||
1064 | * Sets contents of passed object to values from current object. |
||
1065 | * |
||
1066 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
1067 | * objects. |
||
1068 | * |
||
1069 | * @param object $copyObj An object of \Selfprice\Models\Selfprice\Selfprice (or compatible) type. |
||
1070 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
1071 | * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. |
||
1072 | * @throws PropelException |
||
1073 | */ |
||
1074 | public function copyInto($copyObj, $deepCopy = false, $makeNew = true) |
||
1084 | |||
1085 | /** |
||
1086 | * Makes a copy of this object that will be inserted as a new row in table when saved. |
||
1087 | * It creates a new object filling in the simple attributes, but skipping any primary |
||
1088 | * keys that are defined for the table. |
||
1089 | * |
||
1090 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
1091 | * objects. |
||
1092 | * |
||
1093 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
1094 | * @return \Selfprice\Models\Selfprice\Selfprice Clone of current object. |
||
1095 | * @throws PropelException |
||
1096 | */ |
||
1097 | View Code Duplication | public function copy($deepCopy = false) |
|
1106 | |||
1107 | /** |
||
1108 | * Clears the current object, sets all attributes to their default values and removes |
||
1109 | * outgoing references as well as back-references (from other objects to this one. Results probably in a database |
||
1110 | * change of those foreign objects when you call `save` there). |
||
1111 | */ |
||
1112 | View Code Duplication | public function clear() |
|
1124 | |||
1125 | /** |
||
1126 | * Resets all references and back-references to other model objects or collections of model objects. |
||
1127 | * |
||
1128 | * This method is used to reset all php object references (not the actual reference in the database). |
||
1129 | * Necessary for object serialisation. |
||
1130 | * |
||
1131 | * @param boolean $deep Whether to also clear the references on all referrer objects. |
||
1132 | */ |
||
1133 | public function clearAllReferences($deep = false) |
||
1139 | |||
1140 | /** |
||
1141 | * Return the string representation of this object |
||
1142 | * |
||
1143 | * @return string |
||
1144 | */ |
||
1145 | public function __toString() |
||
1149 | |||
1150 | /** |
||
1151 | * Code to be run before persisting the object |
||
1152 | * @param ConnectionInterface $con |
||
1153 | * @return boolean |
||
1154 | */ |
||
1155 | public function preSave(ConnectionInterface $con = null) |
||
1159 | |||
1160 | /** |
||
1161 | * Code to be run after persisting the object |
||
1162 | * @param ConnectionInterface $con |
||
1163 | */ |
||
1164 | public function postSave(ConnectionInterface $con = null) |
||
1168 | |||
1169 | /** |
||
1170 | * Code to be run before inserting to database |
||
1171 | * @param ConnectionInterface $con |
||
1172 | * @return boolean |
||
1173 | */ |
||
1174 | public function preInsert(ConnectionInterface $con = null) |
||
1178 | |||
1179 | /** |
||
1180 | * Code to be run after inserting to database |
||
1181 | * @param ConnectionInterface $con |
||
1182 | */ |
||
1183 | public function postInsert(ConnectionInterface $con = null) |
||
1187 | |||
1188 | /** |
||
1189 | * Code to be run before updating the object in database |
||
1190 | * @param ConnectionInterface $con |
||
1191 | * @return boolean |
||
1192 | */ |
||
1193 | public function preUpdate(ConnectionInterface $con = null) |
||
1197 | |||
1198 | /** |
||
1199 | * Code to be run after updating the object in database |
||
1200 | * @param ConnectionInterface $con |
||
1201 | */ |
||
1202 | public function postUpdate(ConnectionInterface $con = null) |
||
1206 | |||
1207 | /** |
||
1208 | * Code to be run before deleting the object in database |
||
1209 | * @param ConnectionInterface $con |
||
1210 | * @return boolean |
||
1211 | */ |
||
1212 | public function preDelete(ConnectionInterface $con = null) |
||
1216 | |||
1217 | /** |
||
1218 | * Code to be run after deleting the object in database |
||
1219 | * @param ConnectionInterface $con |
||
1220 | */ |
||
1221 | public function postDelete(ConnectionInterface $con = null) |
||
1225 | |||
1226 | |||
1227 | /** |
||
1228 | * Derived method to catches calls to undefined methods. |
||
1229 | * |
||
1230 | * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). |
||
1231 | * Allows to define default __call() behavior if you overwrite __call() |
||
1232 | * |
||
1233 | * @param string $name |
||
1234 | * @param mixed $params |
||
1235 | * |
||
1236 | * @return array|string |
||
1237 | */ |
||
1238 | View Code Duplication | public function __call($name, $params) |
|
1267 | |||
1268 | } |
||
1269 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.