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 User 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 User, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | abstract class User implements ActiveRecordInterface |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * TableMap class name |
||
| 34 | */ |
||
| 35 | const TABLE_MAP = '\\Models\\User\\Map\\UserTableMap'; |
||
| 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 email field. |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | protected $email; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * The value for the password field. |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | protected $password; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * The value for the remember_token field. |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $remember_token; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The value for the created_at field. |
||
| 96 | * @var \DateTime |
||
| 97 | */ |
||
| 98 | protected $created_at; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * The value for the updated_at field. |
||
| 102 | * @var \DateTime |
||
| 103 | */ |
||
| 104 | protected $updated_at; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Flag to prevent endless save loop, if this object is referenced |
||
| 108 | * by another object which falls in this transaction. |
||
| 109 | * |
||
| 110 | * @var boolean |
||
| 111 | */ |
||
| 112 | protected $alreadyInSave = false; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Initializes internal state of Models\User\Base\User object. |
||
| 116 | */ |
||
| 117 | public function __construct() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Returns whether the object has been modified. |
||
| 123 | * |
||
| 124 | * @return boolean True if the object has been modified. |
||
| 125 | */ |
||
| 126 | public function isModified() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Has specified column been modified? |
||
| 133 | * |
||
| 134 | * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID |
||
| 135 | * @return boolean True if $col has been modified. |
||
| 136 | */ |
||
| 137 | public function isColumnModified($col) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Get the columns that have been modified in this object. |
||
| 144 | * @return array A unique list of the modified column names for this object. |
||
| 145 | */ |
||
| 146 | public function getModifiedColumns() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Returns whether the object has ever been saved. This will |
||
| 153 | * be false, if the object was retrieved from storage or was created |
||
| 154 | * and then saved. |
||
| 155 | * |
||
| 156 | * @return boolean true, if the object has never been persisted. |
||
| 157 | */ |
||
| 158 | public function isNew() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Setter for the isNew attribute. This method will be called |
||
| 165 | * by Propel-generated children and objects. |
||
| 166 | * |
||
| 167 | * @param boolean $b the state of the object. |
||
| 168 | */ |
||
| 169 | public function setNew($b) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Whether this object has been deleted. |
||
| 176 | * @return boolean The deleted state of this object. |
||
| 177 | */ |
||
| 178 | public function isDeleted() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Specify whether this object has been deleted. |
||
| 185 | * @param boolean $b The deleted state of this object. |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | public function setDeleted($b) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Sets the modified state for the object to be false. |
||
| 195 | * @param string $col If supplied, only the specified column is reset. |
||
| 196 | * @return void |
||
| 197 | */ |
||
| 198 | View Code Duplication | public function resetModified($col = null) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * Compares this with another <code>User</code> instance. If |
||
| 211 | * <code>obj</code> is an instance of <code>User</code>, delegates to |
||
| 212 | * <code>equals(User)</code>. Otherwise, returns <code>false</code>. |
||
| 213 | * |
||
| 214 | * @param mixed $obj The object to compare to. |
||
| 215 | * @return boolean Whether equal to the object specified. |
||
| 216 | */ |
||
| 217 | View Code Duplication | public function equals($obj) |
|
| 233 | |||
| 234 | /** |
||
| 235 | * Get the associative array of the virtual columns in this object |
||
| 236 | * |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | public function getVirtualColumns() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Checks the existence of a virtual column in this object |
||
| 246 | * |
||
| 247 | * @param string $name The virtual column name |
||
| 248 | * @return boolean |
||
| 249 | */ |
||
| 250 | public function hasVirtualColumn($name) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Get the value of a virtual column in this object |
||
| 257 | * |
||
| 258 | * @param string $name The virtual column name |
||
| 259 | * @return mixed |
||
| 260 | * |
||
| 261 | * @throws PropelException |
||
| 262 | */ |
||
| 263 | View Code Duplication | public function getVirtualColumn($name) |
|
| 271 | |||
| 272 | /** |
||
| 273 | * Set the value of a virtual column in this object |
||
| 274 | * |
||
| 275 | * @param string $name The virtual column name |
||
| 276 | * @param mixed $value The value to give to the virtual column |
||
| 277 | * |
||
| 278 | * @return $this|User The current object, for fluid interface |
||
| 279 | */ |
||
| 280 | public function setVirtualColumn($name, $value) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Logs a message using Propel::log(). |
||
| 289 | * |
||
| 290 | * @param string $msg |
||
| 291 | * @param int $priority One of the Propel::LOG_* logging levels |
||
| 292 | * @return boolean |
||
| 293 | */ |
||
| 294 | protected function log($msg, $priority = Propel::LOG_INFO) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Export the current object properties to a string, using a given parser format |
||
| 301 | * <code> |
||
| 302 | * $book = BookQuery::create()->findPk(9012); |
||
| 303 | * echo $book->exportTo('JSON'); |
||
| 304 | * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 305 | * </code> |
||
| 306 | * |
||
| 307 | * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 308 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. |
||
| 309 | * @return string The exported data |
||
| 310 | */ |
||
| 311 | View Code Duplication | public function exportTo($parser, $includeLazyLoadColumns = true) |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Clean up internal collections prior to serializing |
||
| 322 | * Avoids recursive loops that turn into segmentation faults when serializing |
||
| 323 | */ |
||
| 324 | public function __sleep() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Get the [id] column value. |
||
| 333 | * |
||
| 334 | * @return int |
||
| 335 | */ |
||
| 336 | public function getId() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Get the [name] column value. |
||
| 343 | * |
||
| 344 | * @return string |
||
| 345 | */ |
||
| 346 | public function getName() |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Get the [email] column value. |
||
| 353 | * |
||
| 354 | * @return string |
||
| 355 | */ |
||
| 356 | public function getEmail() |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Get the [password] column value. |
||
| 363 | * |
||
| 364 | * @return string |
||
| 365 | */ |
||
| 366 | public function getPassword() |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Get the [remember_token] column value. |
||
| 373 | * |
||
| 374 | * @return string |
||
| 375 | */ |
||
| 376 | public function getRememberToken() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Get the [optionally formatted] temporal [created_at] column value. |
||
| 383 | * |
||
| 384 | * |
||
| 385 | * @param string $format The date/time format string (either date()-style or strftime()-style). |
||
| 386 | * If format is NULL, then the raw DateTime object will be returned. |
||
| 387 | * |
||
| 388 | * @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 |
||
| 389 | * |
||
| 390 | * @throws PropelException - if unable to parse/validate the date/time value. |
||
| 391 | */ |
||
| 392 | View Code Duplication | public function getCreatedAt($format = NULL) |
|
| 400 | |||
| 401 | /** |
||
| 402 | * Get the [optionally formatted] temporal [updated_at] column value. |
||
| 403 | * |
||
| 404 | * |
||
| 405 | * @param string $format The date/time format string (either date()-style or strftime()-style). |
||
| 406 | * If format is NULL, then the raw DateTime object will be returned. |
||
| 407 | * |
||
| 408 | * @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 |
||
| 409 | * |
||
| 410 | * @throws PropelException - if unable to parse/validate the date/time value. |
||
| 411 | */ |
||
| 412 | View Code Duplication | public function getUpdatedAt($format = NULL) |
|
| 420 | |||
| 421 | /** |
||
| 422 | * Set the value of [id] column. |
||
| 423 | * |
||
| 424 | * @param int $v new value |
||
| 425 | * @return $this|\Models\User\User The current object (for fluent API support) |
||
| 426 | */ |
||
| 427 | View Code Duplication | public function setId($v) |
|
| 440 | |||
| 441 | /** |
||
| 442 | * Set the value of [name] column. |
||
| 443 | * |
||
| 444 | * @param string $v new value |
||
| 445 | * @return $this|\Models\User\User The current object (for fluent API support) |
||
| 446 | */ |
||
| 447 | View Code Duplication | public function setName($v) |
|
| 460 | |||
| 461 | /** |
||
| 462 | * Set the value of [email] column. |
||
| 463 | * |
||
| 464 | * @param string $v new value |
||
| 465 | * @return $this|\Models\User\User The current object (for fluent API support) |
||
| 466 | */ |
||
| 467 | View Code Duplication | public function setEmail($v) |
|
| 480 | |||
| 481 | /** |
||
| 482 | * Set the value of [password] column. |
||
| 483 | * |
||
| 484 | * @param string $v new value |
||
| 485 | * @return $this|\Models\User\User The current object (for fluent API support) |
||
| 486 | */ |
||
| 487 | View Code Duplication | public function setPassword($v) |
|
| 500 | |||
| 501 | /** |
||
| 502 | * Set the value of [remember_token] column. |
||
| 503 | * |
||
| 504 | * @param string $v new value |
||
| 505 | * @return $this|\Models\User\User The current object (for fluent API support) |
||
| 506 | */ |
||
| 507 | View Code Duplication | public function setRememberToken($v) |
|
| 520 | |||
| 521 | /** |
||
| 522 | * Sets the value of [created_at] column to a normalized version of the date/time value specified. |
||
| 523 | * |
||
| 524 | * @param mixed $v string, integer (timestamp), or \DateTime value. |
||
| 525 | * Empty strings are treated as NULL. |
||
| 526 | * @return $this|\Models\User\User The current object (for fluent API support) |
||
| 527 | */ |
||
| 528 | View Code Duplication | public function setCreatedAt($v) |
|
| 540 | |||
| 541 | /** |
||
| 542 | * Sets the value of [updated_at] column to a normalized version of the date/time value specified. |
||
| 543 | * |
||
| 544 | * @param mixed $v string, integer (timestamp), or \DateTime value. |
||
| 545 | * Empty strings are treated as NULL. |
||
| 546 | * @return $this|\Models\User\User The current object (for fluent API support) |
||
| 547 | */ |
||
| 548 | View Code Duplication | public function setUpdatedAt($v) |
|
| 560 | |||
| 561 | /** |
||
| 562 | * Indicates whether the columns in this object are only set to default values. |
||
| 563 | * |
||
| 564 | * This method can be used in conjunction with isModified() to indicate whether an object is both |
||
| 565 | * modified _and_ has some values set which are non-default. |
||
| 566 | * |
||
| 567 | * @return boolean Whether the columns in this object are only been set with default values. |
||
| 568 | */ |
||
| 569 | public function hasOnlyDefaultValues() |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Hydrates (populates) the object variables with values from the database resultset. |
||
| 577 | * |
||
| 578 | * An offset (0-based "start column") is specified so that objects can be hydrated |
||
| 579 | * with a subset of the columns in the resultset rows. This is needed, for example, |
||
| 580 | * for results of JOIN queries where the resultset row includes columns from two or |
||
| 581 | * more tables. |
||
| 582 | * |
||
| 583 | * @param array $row The row returned by DataFetcher->fetch(). |
||
| 584 | * @param int $startcol 0-based offset column which indicates which restultset column to start with. |
||
| 585 | * @param boolean $rehydrate Whether this object is being re-hydrated from the database. |
||
| 586 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
| 587 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 588 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 589 | * |
||
| 590 | * @return int next starting column |
||
| 591 | * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. |
||
| 592 | */ |
||
| 593 | public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Checks and repairs the internal consistency of the object. |
||
| 640 | * |
||
| 641 | * This method is executed after an already-instantiated object is re-hydrated |
||
| 642 | * from the database. It exists to check any foreign keys to make sure that |
||
| 643 | * the objects related to the current object are correct based on foreign key. |
||
| 644 | * |
||
| 645 | * You can override this method in the stub class, but you should always invoke |
||
| 646 | * the base method from the overridden method (i.e. parent::ensureConsistency()), |
||
| 647 | * in case your model changes. |
||
| 648 | * |
||
| 649 | * @throws PropelException |
||
| 650 | */ |
||
| 651 | public function ensureConsistency() |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. |
||
| 657 | * |
||
| 658 | * This will only work if the object has been saved and has a valid primary key set. |
||
| 659 | * |
||
| 660 | * @param boolean $deep (optional) Whether to also de-associated any related objects. |
||
| 661 | * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. |
||
| 662 | * @return void |
||
| 663 | * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db |
||
| 664 | */ |
||
| 665 | View Code Duplication | public function reload($deep = false, ConnectionInterface $con = null) |
|
| 694 | |||
| 695 | /** |
||
| 696 | * Removes this object from datastore and sets delete attribute. |
||
| 697 | * |
||
| 698 | * @param ConnectionInterface $con |
||
| 699 | * @return void |
||
| 700 | * @throws PropelException |
||
| 701 | * @see User::setDeleted() |
||
| 702 | * @see User::isDeleted() |
||
| 703 | */ |
||
| 704 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
| 725 | |||
| 726 | /** |
||
| 727 | * Persists this object to the database. |
||
| 728 | * |
||
| 729 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 730 | * All modified related objects will also be persisted in the doSave() |
||
| 731 | * method. This method wraps all precipitate database operations in a |
||
| 732 | * single transaction. |
||
| 733 | * |
||
| 734 | * @param ConnectionInterface $con |
||
| 735 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 736 | * @throws PropelException |
||
| 737 | * @see doSave() |
||
| 738 | */ |
||
| 739 | View Code Duplication | public function save(ConnectionInterface $con = null) |
|
| 773 | |||
| 774 | /** |
||
| 775 | * Performs the work of inserting or updating the row in the database. |
||
| 776 | * |
||
| 777 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 778 | * All related objects are also updated in this method. |
||
| 779 | * |
||
| 780 | * @param ConnectionInterface $con |
||
| 781 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 782 | * @throws PropelException |
||
| 783 | * @see save() |
||
| 784 | */ |
||
| 785 | View Code Duplication | protected function doSave(ConnectionInterface $con) |
|
| 808 | |||
| 809 | /** |
||
| 810 | * Insert the row in the database. |
||
| 811 | * |
||
| 812 | * @param ConnectionInterface $con |
||
| 813 | * |
||
| 814 | * @throws PropelException |
||
| 815 | * @see doSave() |
||
| 816 | */ |
||
| 817 | protected function doInsert(ConnectionInterface $con) |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Update the row in the database. |
||
| 901 | * |
||
| 902 | * @param ConnectionInterface $con |
||
| 903 | * |
||
| 904 | * @return Integer Number of updated rows |
||
| 905 | * @see doSave() |
||
| 906 | */ |
||
| 907 | protected function doUpdate(ConnectionInterface $con) |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Retrieves a field from the object by name passed in as a string. |
||
| 917 | * |
||
| 918 | * @param string $name name |
||
| 919 | * @param string $type The type of fieldname the $name is of: |
||
| 920 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 921 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 922 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 923 | * @return mixed Value of field. |
||
| 924 | */ |
||
| 925 | View Code Duplication | public function getByName($name, $type = TableMap::TYPE_PHPNAME) |
|
| 932 | |||
| 933 | /** |
||
| 934 | * Retrieves a field from the object by Position as specified in the xml schema. |
||
| 935 | * Zero-based. |
||
| 936 | * |
||
| 937 | * @param int $pos position in xml schema |
||
| 938 | * @return mixed Value of field at $pos |
||
| 939 | */ |
||
| 940 | public function getByPosition($pos) |
||
| 969 | |||
| 970 | /** |
||
| 971 | * Exports the object as an array. |
||
| 972 | * |
||
| 973 | * You can specify the key type of the array by passing one of the class |
||
| 974 | * type constants. |
||
| 975 | * |
||
| 976 | * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 977 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 978 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 979 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. |
||
| 980 | * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion |
||
| 981 | * |
||
| 982 | * @return array an associative array containing the field names (as keys) and field values |
||
| 983 | */ |
||
| 984 | public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array()) |
||
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Sets a field from the object by name passed in as a string. |
||
| 1026 | * |
||
| 1027 | * @param string $name |
||
| 1028 | * @param mixed $value field value |
||
| 1029 | * @param string $type The type of fieldname the $name is of: |
||
| 1030 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 1031 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1032 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 1033 | * @return $this|\Models\User\User |
||
| 1034 | */ |
||
| 1035 | public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) |
||
| 1041 | |||
| 1042 | /** |
||
| 1043 | * Sets a field from the object by Position as specified in the xml schema. |
||
| 1044 | * Zero-based. |
||
| 1045 | * |
||
| 1046 | * @param int $pos position in xml schema |
||
| 1047 | * @param mixed $value field value |
||
| 1048 | * @return $this|\Models\User\User |
||
| 1049 | */ |
||
| 1050 | public function setByPosition($pos, $value) |
||
| 1078 | |||
| 1079 | /** |
||
| 1080 | * Populates the object using an array. |
||
| 1081 | * |
||
| 1082 | * This is particularly useful when populating an object from one of the |
||
| 1083 | * request arrays (e.g. $_POST). This method goes through the column |
||
| 1084 | * names, checking to see whether a matching key exists in populated |
||
| 1085 | * array. If so the setByName() method is called for that column. |
||
| 1086 | * |
||
| 1087 | * You can specify the key type of the array by additionally passing one |
||
| 1088 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1089 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1090 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 1091 | * |
||
| 1092 | * @param array $arr An array to populate the object from. |
||
| 1093 | * @param string $keyType The type of keys the array uses. |
||
| 1094 | * @return void |
||
| 1095 | */ |
||
| 1096 | public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Populate the current object from a string, using a given parser format |
||
| 1125 | * <code> |
||
| 1126 | * $book = new Book(); |
||
| 1127 | * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 1128 | * </code> |
||
| 1129 | * |
||
| 1130 | * You can specify the key type of the array by additionally passing one |
||
| 1131 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1132 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1133 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 1134 | * |
||
| 1135 | * @param mixed $parser A AbstractParser instance, |
||
| 1136 | * or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 1137 | * @param string $data The source data to import from |
||
| 1138 | * @param string $keyType The type of keys the array uses. |
||
| 1139 | * |
||
| 1140 | * @return $this|\Models\User\User The current object, for fluid interface |
||
| 1141 | */ |
||
| 1142 | View Code Duplication | public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) |
|
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Build a Criteria object containing the values of all modified columns in this object. |
||
| 1155 | * |
||
| 1156 | * @return Criteria The Criteria object containing all modified values. |
||
| 1157 | */ |
||
| 1158 | public function buildCriteria() |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Builds a Criteria object containing the primary key for this object. |
||
| 1189 | * |
||
| 1190 | * Unlike buildCriteria() this method includes the primary key values regardless |
||
| 1191 | * of whether or not they have been modified. |
||
| 1192 | * |
||
| 1193 | * @throws LogicException if no primary key is defined |
||
| 1194 | * |
||
| 1195 | * @return Criteria The Criteria object containing value(s) for primary key(s). |
||
| 1196 | */ |
||
| 1197 | public function buildPkeyCriteria() |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * If the primary key is not null, return the hashcode of the |
||
| 1207 | * primary key. Otherwise, return the hash code of the object. |
||
| 1208 | * |
||
| 1209 | * @return int Hashcode |
||
| 1210 | */ |
||
| 1211 | View Code Duplication | public function hashCode() |
|
| 1226 | |||
| 1227 | /** |
||
| 1228 | * Returns the primary key for this object (row). |
||
| 1229 | * @return int |
||
| 1230 | */ |
||
| 1231 | public function getPrimaryKey() |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Generic method to set the primary key (id column). |
||
| 1238 | * |
||
| 1239 | * @param int $key Primary key. |
||
| 1240 | * @return void |
||
| 1241 | */ |
||
| 1242 | public function setPrimaryKey($key) |
||
| 1246 | |||
| 1247 | /** |
||
| 1248 | * Returns true if the primary key for this object is null. |
||
| 1249 | * @return boolean |
||
| 1250 | */ |
||
| 1251 | public function isPrimaryKeyNull() |
||
| 1255 | |||
| 1256 | /** |
||
| 1257 | * Sets contents of passed object to values from current object. |
||
| 1258 | * |
||
| 1259 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1260 | * objects. |
||
| 1261 | * |
||
| 1262 | * @param object $copyObj An object of \Models\User\User (or compatible) type. |
||
| 1263 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1264 | * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. |
||
| 1265 | * @throws PropelException |
||
| 1266 | */ |
||
| 1267 | public function copyInto($copyObj, $deepCopy = false, $makeNew = true) |
||
| 1280 | |||
| 1281 | /** |
||
| 1282 | * Makes a copy of this object that will be inserted as a new row in table when saved. |
||
| 1283 | * It creates a new object filling in the simple attributes, but skipping any primary |
||
| 1284 | * keys that are defined for the table. |
||
| 1285 | * |
||
| 1286 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1287 | * objects. |
||
| 1288 | * |
||
| 1289 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1290 | * @return \Models\User\User Clone of current object. |
||
| 1291 | * @throws PropelException |
||
| 1292 | */ |
||
| 1293 | View Code Duplication | public function copy($deepCopy = false) |
|
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Clears the current object, sets all attributes to their default values and removes |
||
| 1305 | * outgoing references as well as back-references (from other objects to this one. Results probably in a database |
||
| 1306 | * change of those foreign objects when you call `save` there). |
||
| 1307 | */ |
||
| 1308 | public function clear() |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * Resets all references and back-references to other model objects or collections of model objects. |
||
| 1326 | * |
||
| 1327 | * This method is used to reset all php object references (not the actual reference in the database). |
||
| 1328 | * Necessary for object serialisation. |
||
| 1329 | * |
||
| 1330 | * @param boolean $deep Whether to also clear the references on all referrer objects. |
||
| 1331 | */ |
||
| 1332 | public function clearAllReferences($deep = false) |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * Return the string representation of this object |
||
| 1341 | * |
||
| 1342 | * @return string |
||
| 1343 | */ |
||
| 1344 | public function __toString() |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Code to be run before persisting the object |
||
| 1351 | * @param ConnectionInterface $con |
||
| 1352 | * @return boolean |
||
| 1353 | */ |
||
| 1354 | public function preSave(ConnectionInterface $con = null) |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * Code to be run after persisting the object |
||
| 1361 | * @param ConnectionInterface $con |
||
| 1362 | */ |
||
| 1363 | public function postSave(ConnectionInterface $con = null) |
||
| 1367 | |||
| 1368 | /** |
||
| 1369 | * Code to be run before inserting to database |
||
| 1370 | * @param ConnectionInterface $con |
||
| 1371 | * @return boolean |
||
| 1372 | */ |
||
| 1373 | public function preInsert(ConnectionInterface $con = null) |
||
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Code to be run after inserting to database |
||
| 1380 | * @param ConnectionInterface $con |
||
| 1381 | */ |
||
| 1382 | public function postInsert(ConnectionInterface $con = null) |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Code to be run before updating the object in database |
||
| 1389 | * @param ConnectionInterface $con |
||
| 1390 | * @return boolean |
||
| 1391 | */ |
||
| 1392 | public function preUpdate(ConnectionInterface $con = null) |
||
| 1396 | |||
| 1397 | /** |
||
| 1398 | * Code to be run after updating the object in database |
||
| 1399 | * @param ConnectionInterface $con |
||
| 1400 | */ |
||
| 1401 | public function postUpdate(ConnectionInterface $con = null) |
||
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Code to be run before deleting the object in database |
||
| 1408 | * @param ConnectionInterface $con |
||
| 1409 | * @return boolean |
||
| 1410 | */ |
||
| 1411 | public function preDelete(ConnectionInterface $con = null) |
||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Code to be run after deleting the object in database |
||
| 1418 | * @param ConnectionInterface $con |
||
| 1419 | */ |
||
| 1420 | public function postDelete(ConnectionInterface $con = null) |
||
| 1424 | |||
| 1425 | |||
| 1426 | /** |
||
| 1427 | * Derived method to catches calls to undefined methods. |
||
| 1428 | * |
||
| 1429 | * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). |
||
| 1430 | * Allows to define default __call() behavior if you overwrite __call() |
||
| 1431 | * |
||
| 1432 | * @param string $name |
||
| 1433 | * @param mixed $params |
||
| 1434 | * |
||
| 1435 | * @return array|string |
||
| 1436 | */ |
||
| 1437 | View Code Duplication | public function __call($name, $params) |
|
| 1466 | |||
| 1467 | } |
||
| 1468 |
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.