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 Model 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 Model, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | abstract class Model implements \ArrayAccess |
||
| 29 | { |
||
| 30 | const IMMUTABLE = 0; |
||
| 31 | const MUTABLE_CREATE_ONLY = 1; |
||
| 32 | const MUTABLE = 2; |
||
| 33 | |||
| 34 | const TYPE_STRING = 'string'; |
||
| 35 | const TYPE_NUMBER = 'number'; |
||
| 36 | const TYPE_BOOLEAN = 'boolean'; |
||
| 37 | const TYPE_DATE = 'date'; |
||
| 38 | const TYPE_OBJECT = 'object'; |
||
| 39 | const TYPE_ARRAY = 'array'; |
||
| 40 | |||
| 41 | const ERROR_REQUIRED_FIELD_MISSING = 'required_field_missing'; |
||
| 42 | const ERROR_VALIDATION_FAILED = 'validation_failed'; |
||
| 43 | const ERROR_NOT_UNIQUE = 'not_unique'; |
||
| 44 | |||
| 45 | const DEFAULT_ID_PROPERTY = 'id'; |
||
| 46 | |||
| 47 | ///////////////////////////// |
||
| 48 | // Model visible variables |
||
| 49 | ///////////////////////////// |
||
| 50 | |||
| 51 | /** |
||
| 52 | * List of model ID property names. |
||
| 53 | * |
||
| 54 | * @var array |
||
| 55 | */ |
||
| 56 | protected static $ids = [self::DEFAULT_ID_PROPERTY]; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Property definitions expressed as a key-value map with |
||
| 60 | * property names as the keys. |
||
| 61 | * i.e. ['enabled' => ['type' => Model::TYPE_BOOLEAN]]. |
||
| 62 | * |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | protected static $properties = []; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var Container |
||
| 69 | */ |
||
| 70 | protected static $injectedApp; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | protected static $dispatchers; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var number|string|bool |
||
| 79 | */ |
||
| 80 | protected $_id; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var Container |
||
| 84 | */ |
||
| 85 | protected $app; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var array |
||
| 89 | */ |
||
| 90 | protected $_values = []; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var array |
||
| 94 | */ |
||
| 95 | protected $_unsaved = []; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var array |
||
| 99 | */ |
||
| 100 | protected $_relationships = []; |
||
| 101 | |||
| 102 | ///////////////////////////// |
||
| 103 | // Base model variables |
||
| 104 | ///////////////////////////// |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var array |
||
| 108 | */ |
||
| 109 | private static $propertyDefinitionBase = [ |
||
| 110 | 'type' => self::TYPE_STRING, |
||
| 111 | 'mutable' => self::MUTABLE, |
||
| 112 | 'null' => false, |
||
| 113 | 'unique' => false, |
||
| 114 | 'required' => false, |
||
| 115 | ]; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var array |
||
| 119 | */ |
||
| 120 | private static $defaultIDProperty = [ |
||
| 121 | 'type' => self::TYPE_NUMBER, |
||
| 122 | 'mutable' => self::IMMUTABLE, |
||
| 123 | ]; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var array |
||
| 127 | */ |
||
| 128 | private static $timestampProperties = [ |
||
| 129 | 'created_at' => [ |
||
| 130 | 'type' => self::TYPE_DATE, |
||
| 131 | 'default' => null, |
||
| 132 | 'null' => true, |
||
| 133 | 'validate' => 'timestamp|db_timestamp', |
||
| 134 | ], |
||
| 135 | 'updated_at' => [ |
||
| 136 | 'type' => self::TYPE_DATE, |
||
| 137 | 'validate' => 'timestamp|db_timestamp', |
||
| 138 | ], |
||
| 139 | ]; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var array |
||
| 143 | */ |
||
| 144 | private static $initialized = []; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @var DriverInterface |
||
| 148 | */ |
||
| 149 | private static $driver; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var array |
||
| 153 | */ |
||
| 154 | private static $accessors = []; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @var array |
||
| 158 | */ |
||
| 159 | private static $mutators = []; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @var bool |
||
| 163 | */ |
||
| 164 | private $_ignoreUnsaved; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Creates a new model object. |
||
| 168 | * |
||
| 169 | * @param array|string|Model|false $id ordered array of ids or comma-separated id string |
||
| 170 | * @param array $values optional key-value map to pre-seed model |
||
| 171 | */ |
||
| 172 | public function __construct($id = false, array $values = []) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Performs initialization on this model. |
||
| 204 | */ |
||
| 205 | private function init() |
||
| 214 | |||
| 215 | /** |
||
| 216 | * The initialize() method is called once per model. It's used |
||
| 217 | * to perform any one-off tasks before the model gets |
||
| 218 | * constructed. This is a great place to add any model |
||
| 219 | * properties. When extending this method be sure to call |
||
| 220 | * parent::initialize() as some important stuff happens here. |
||
| 221 | * If extending this method to add properties then you should |
||
| 222 | * call parent::initialize() after adding any properties. |
||
| 223 | */ |
||
| 224 | protected function initialize() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Injects a DI container. |
||
| 252 | * |
||
| 253 | * @param Container $app |
||
| 254 | */ |
||
| 255 | public static function inject(Container $app) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Gets the DI container used for this model. |
||
| 262 | * |
||
| 263 | * @return Container |
||
| 264 | */ |
||
| 265 | public function getApp() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Sets the driver for all models. |
||
| 272 | * |
||
| 273 | * @param DriverInterface $driver |
||
| 274 | */ |
||
| 275 | public static function setDriver(DriverInterface $driver) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Gets the driver for all models. |
||
| 282 | * |
||
| 283 | * @return DriverInterface |
||
| 284 | * |
||
| 285 | * @throws DriverMissingException when a driver has not been set yet |
||
| 286 | */ |
||
| 287 | public static function getDriver() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Clears the driver for all models. |
||
| 298 | */ |
||
| 299 | public static function clearDriver() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Gets the name of the model, i.e. User. |
||
| 306 | * |
||
| 307 | * @return string |
||
| 308 | */ |
||
| 309 | public static function modelName() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Gets the model ID. |
||
| 319 | * |
||
| 320 | * @return string|number|false ID |
||
| 321 | */ |
||
| 322 | public function id() |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Gets a key-value map of the model ID. |
||
| 329 | * |
||
| 330 | * @return array ID map |
||
| 331 | */ |
||
| 332 | public function ids() |
||
| 350 | |||
| 351 | ///////////////////////////// |
||
| 352 | // Magic Methods |
||
| 353 | ///////////////////////////// |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Converts the model into a string. |
||
| 357 | * |
||
| 358 | * @return string |
||
| 359 | */ |
||
| 360 | public function __toString() |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Shortcut to a get() call for a given property. |
||
| 367 | * |
||
| 368 | * @param string $name |
||
| 369 | * |
||
| 370 | * @return mixed |
||
| 371 | */ |
||
| 372 | public function __get($name) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Sets an unsaved value. |
||
| 381 | * |
||
| 382 | * @param string $name |
||
| 383 | * @param mixed $value |
||
| 384 | */ |
||
| 385 | public function __set($name, $value) |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Checks if an unsaved value or property exists by this name. |
||
| 403 | * |
||
| 404 | * @param string $name |
||
| 405 | * |
||
| 406 | * @return bool |
||
| 407 | */ |
||
| 408 | public function __isset($name) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Unsets an unsaved value. |
||
| 415 | * |
||
| 416 | * @param string $name |
||
| 417 | */ |
||
| 418 | public function __unset($name) |
||
| 429 | |||
| 430 | ///////////////////////////// |
||
| 431 | // ArrayAccess Interface |
||
| 432 | ///////////////////////////// |
||
| 433 | |||
| 434 | public function offsetExists($offset) |
||
| 438 | |||
| 439 | public function offsetGet($offset) |
||
| 443 | |||
| 444 | public function offsetSet($offset, $value) |
||
| 448 | |||
| 449 | public function offsetUnset($offset) |
||
| 453 | |||
| 454 | public static function __callStatic($name, $parameters) |
||
| 461 | |||
| 462 | ///////////////////////////// |
||
| 463 | // Property Definitions |
||
| 464 | ///////////////////////////// |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Gets all the property definitions for the model. |
||
| 468 | * |
||
| 469 | * @return array key-value map of properties |
||
| 470 | */ |
||
| 471 | public static function getProperties() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Gets a property defition for the model. |
||
| 478 | * |
||
| 479 | * @param string $property property to lookup |
||
| 480 | * |
||
| 481 | * @return array|null property |
||
| 482 | */ |
||
| 483 | public static function getProperty($property) |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Gets the names of the model ID properties. |
||
| 490 | * |
||
| 491 | * @return array |
||
| 492 | */ |
||
| 493 | public static function getIDProperties() |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Checks if the model has a property. |
||
| 500 | * |
||
| 501 | * @param string $property property |
||
| 502 | * |
||
| 503 | * @return bool has property |
||
| 504 | */ |
||
| 505 | public static function hasProperty($property) |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Gets the mutator method name for a given proeprty name. |
||
| 512 | * Looks for methods in the form of `setPropertyValue`. |
||
| 513 | * i.e. the mutator for `last_name` would be `setLastNameValue`. |
||
| 514 | * |
||
| 515 | * @param string $property property |
||
| 516 | * |
||
| 517 | * @return string|false method name if it exists |
||
| 518 | */ |
||
| 519 | View Code Duplication | public static function getMutator($property) |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Gets the accessor method name for a given proeprty name. |
||
| 540 | * Looks for methods in the form of `getPropertyValue`. |
||
| 541 | * i.e. the accessor for `last_name` would be `getLastNameValue`. |
||
| 542 | * |
||
| 543 | * @param string $property property |
||
| 544 | * |
||
| 545 | * @return string|false method name if it exists |
||
| 546 | */ |
||
| 547 | View Code Duplication | public static function getAccessor($property) |
|
| 565 | |||
| 566 | ///////////////////////////// |
||
| 567 | // CRUD Operations |
||
| 568 | ///////////////////////////// |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Saves the model. |
||
| 572 | * |
||
| 573 | * @return bool true when the operation was successful |
||
| 574 | */ |
||
| 575 | public function save() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Creates a new model. |
||
| 586 | * |
||
| 587 | * @param array $data optional key-value properties to set |
||
| 588 | * |
||
| 589 | * @return bool true when the operation was successful |
||
| 590 | * |
||
| 591 | * @throws BadMethodCallException when called on an existing model |
||
| 592 | */ |
||
| 593 | public function create(array $data = []) |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Ignores unsaved values when fetching the next value. |
||
| 684 | * |
||
| 685 | * @return self |
||
| 686 | */ |
||
| 687 | public function ignoreUnsaved() |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Fetches property values from the model. |
||
| 696 | * |
||
| 697 | * This method looks up values in this order: |
||
| 698 | * IDs, local cache, unsaved values, storage layer, defaults |
||
| 699 | * |
||
| 700 | * @param array $properties list of property names to fetch values of |
||
| 701 | * |
||
| 702 | * @return array |
||
| 703 | */ |
||
| 704 | public function get(array $properties) |
||
| 749 | |||
| 750 | /** |
||
| 751 | * Gets the ID for a newly created model. |
||
| 752 | * |
||
| 753 | * @return string |
||
| 754 | */ |
||
| 755 | protected function getNewID() |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Converts the model to an array. |
||
| 775 | * |
||
| 776 | * @return array |
||
| 777 | */ |
||
| 778 | public function toArray() |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Updates the model. |
||
| 804 | * |
||
| 805 | * @param array $data optional key-value properties to set |
||
| 806 | * |
||
| 807 | * @return bool true when the operation was successful |
||
| 808 | * |
||
| 809 | * @throws BadMethodCallException when not called on an existing model |
||
| 810 | */ |
||
| 811 | public function set(array $data = []) |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Delete the model. |
||
| 882 | * |
||
| 883 | * @return bool true when the operation was successful |
||
| 884 | */ |
||
| 885 | public function delete() |
||
| 912 | |||
| 913 | ///////////////////////////// |
||
| 914 | // Queries |
||
| 915 | ///////////////////////////// |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Generates a new query instance. |
||
| 919 | * |
||
| 920 | * @return Query |
||
| 921 | */ |
||
| 922 | public static function query() |
||
| 931 | |||
| 932 | /** |
||
| 933 | * Gets the total number of records matching an optional criteria. |
||
| 934 | * |
||
| 935 | * @param array $where criteria |
||
| 936 | * |
||
| 937 | * @return int |
||
| 938 | */ |
||
| 939 | public static function totalRecords(array $where = []) |
||
| 946 | |||
| 947 | /** |
||
| 948 | * @deprecated |
||
| 949 | * |
||
| 950 | * Checks if the model exists in the database |
||
| 951 | * |
||
| 952 | * @return bool |
||
| 953 | */ |
||
| 954 | public function exists() |
||
| 958 | |||
| 959 | /** |
||
| 960 | * Loads the model from the storage layer. |
||
| 961 | * |
||
| 962 | * @return self |
||
| 963 | */ |
||
| 964 | public function refresh() |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Loads values into the model. |
||
| 984 | * |
||
| 985 | * @param array $values values |
||
| 986 | * |
||
| 987 | * @return self |
||
| 988 | */ |
||
| 989 | public function refreshWith(array $values) |
||
| 995 | |||
| 996 | /** |
||
| 997 | * Clears the cache for this model. |
||
| 998 | * |
||
| 999 | * @return self |
||
| 1000 | */ |
||
| 1001 | public function clearCache() |
||
| 1009 | |||
| 1010 | ///////////////////////////// |
||
| 1011 | // Relationships |
||
| 1012 | ///////////////////////////// |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * @deprecated |
||
| 1016 | * |
||
| 1017 | * Gets the model object corresponding to a relation |
||
| 1018 | * WARNING no check is used to see if the model returned actually exists |
||
| 1019 | * |
||
| 1020 | * @param string $propertyName property |
||
| 1021 | * |
||
| 1022 | * @return Model |
||
| 1023 | */ |
||
| 1024 | public function relation($propertyName) |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Creates the parent side of a One-To-One relationship. |
||
| 1038 | * |
||
| 1039 | * @param string $model foreign model class |
||
| 1040 | * @param string $foreignKey identifying key on foreign model |
||
| 1041 | * @param string $localKey identifying key on local model |
||
| 1042 | * |
||
| 1043 | * @return Relation\Relation |
||
| 1044 | */ |
||
| 1045 | View Code Duplication | public function hasOne($model, $foreignKey = '', $localKey = '') |
|
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Creates the child side of a One-To-One or One-To-Many relationship. |
||
| 1063 | * |
||
| 1064 | * @param string $model foreign model class |
||
| 1065 | * @param string $foreignKey identifying key on foreign model |
||
| 1066 | * @param string $localKey identifying key on local model |
||
| 1067 | * |
||
| 1068 | * @return Relation\Relation |
||
| 1069 | */ |
||
| 1070 | View Code Duplication | public function belongsTo($model, $foreignKey = '', $localKey = '') |
|
| 1085 | |||
| 1086 | /** |
||
| 1087 | * Creates the parent side of a Many-To-One or Many-To-Many relationship. |
||
| 1088 | * |
||
| 1089 | * @param string $model foreign model class |
||
| 1090 | * @param string $foreignKey identifying key on foreign model |
||
| 1091 | * @param string $localKey identifying key on local model |
||
| 1092 | * |
||
| 1093 | * @return Relation\Relation |
||
| 1094 | */ |
||
| 1095 | View Code Duplication | public function hasMany($model, $foreignKey = '', $localKey = '') |
|
| 1110 | |||
| 1111 | /** |
||
| 1112 | * Creates the child side of a Many-To-Many relationship. |
||
| 1113 | * |
||
| 1114 | * @param string $model foreign model class |
||
| 1115 | * @param string $foreignKey identifying key on foreign model |
||
| 1116 | * @param string $localKey identifying key on local model |
||
| 1117 | * |
||
| 1118 | * @return Relation\Relation |
||
| 1119 | */ |
||
| 1120 | View Code Duplication | public function belongsToMany($model, $foreignKey = '', $localKey = '') |
|
| 1135 | |||
| 1136 | ///////////////////////////// |
||
| 1137 | // Events |
||
| 1138 | ///////////////////////////// |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Gets the event dispatcher. |
||
| 1142 | * |
||
| 1143 | * @return EventDispatcher |
||
| 1144 | */ |
||
| 1145 | public static function getDispatcher($ignoreCache = false) |
||
| 1154 | |||
| 1155 | /** |
||
| 1156 | * Subscribes to a listener to an event. |
||
| 1157 | * |
||
| 1158 | * @param string $event event name |
||
| 1159 | * @param callable $listener |
||
| 1160 | * @param int $priority optional priority, higher #s get called first |
||
| 1161 | */ |
||
| 1162 | public static function listen($event, callable $listener, $priority = 0) |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Adds a listener to the model.creating and model.updating events. |
||
| 1169 | * |
||
| 1170 | * @param callable $listener |
||
| 1171 | * @param int $priority |
||
| 1172 | */ |
||
| 1173 | public static function saving(callable $listener, $priority = 0) |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Adds a listener to the model.created and model.updated events. |
||
| 1181 | * |
||
| 1182 | * @param callable $listener |
||
| 1183 | * @param int $priority |
||
| 1184 | */ |
||
| 1185 | public static function saved(callable $listener, $priority = 0) |
||
| 1190 | |||
| 1191 | /** |
||
| 1192 | * Adds a listener to the model.creating event. |
||
| 1193 | * |
||
| 1194 | * @param callable $listener |
||
| 1195 | * @param int $priority |
||
| 1196 | */ |
||
| 1197 | public static function creating(callable $listener, $priority = 0) |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Adds a listener to the model.created event. |
||
| 1204 | * |
||
| 1205 | * @param callable $listener |
||
| 1206 | * @param int $priority |
||
| 1207 | */ |
||
| 1208 | public static function created(callable $listener, $priority = 0) |
||
| 1212 | |||
| 1213 | /** |
||
| 1214 | * Adds a listener to the model.updating event. |
||
| 1215 | * |
||
| 1216 | * @param callable $listener |
||
| 1217 | * @param int $priority |
||
| 1218 | */ |
||
| 1219 | public static function updating(callable $listener, $priority = 0) |
||
| 1223 | |||
| 1224 | /** |
||
| 1225 | * Adds a listener to the model.updated event. |
||
| 1226 | * |
||
| 1227 | * @param callable $listener |
||
| 1228 | * @param int $priority |
||
| 1229 | */ |
||
| 1230 | public static function updated(callable $listener, $priority = 0) |
||
| 1234 | |||
| 1235 | /** |
||
| 1236 | * Adds a listener to the model.deleting event. |
||
| 1237 | * |
||
| 1238 | * @param callable $listener |
||
| 1239 | * @param int $priority |
||
| 1240 | */ |
||
| 1241 | public static function deleting(callable $listener, $priority = 0) |
||
| 1245 | |||
| 1246 | /** |
||
| 1247 | * Adds a listener to the model.deleted event. |
||
| 1248 | * |
||
| 1249 | * @param callable $listener |
||
| 1250 | * @param int $priority |
||
| 1251 | */ |
||
| 1252 | public static function deleted(callable $listener, $priority = 0) |
||
| 1256 | |||
| 1257 | /** |
||
| 1258 | * Dispatches an event. |
||
| 1259 | * |
||
| 1260 | * @param string $eventName |
||
| 1261 | * |
||
| 1262 | * @return ModelEvent |
||
| 1263 | */ |
||
| 1264 | protected function dispatch($eventName) |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Dispatches the given event and checks if it was successful. |
||
| 1273 | * |
||
| 1274 | * @param string $eventName |
||
| 1275 | * |
||
| 1276 | * @return bool true if the events were successfully propagated |
||
| 1277 | */ |
||
| 1278 | private function handleDispatch($eventName) |
||
| 1284 | |||
| 1285 | ///////////////////////////// |
||
| 1286 | // Validation |
||
| 1287 | ///////////////////////////// |
||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * Validates and marshals a value to storage. |
||
| 1291 | * |
||
| 1292 | * @param array $property |
||
| 1293 | * @param string $propertyName |
||
| 1294 | * @param mixed $value |
||
| 1295 | * |
||
| 1296 | * @return bool |
||
| 1297 | */ |
||
| 1298 | private function filterAndValidate(array $property, $propertyName, &$value) |
||
| 1318 | |||
| 1319 | /** |
||
| 1320 | * Validates a value for a property. |
||
| 1321 | * |
||
| 1322 | * @param array $property |
||
| 1323 | * @param string $propertyName |
||
| 1324 | * @param mixed $value |
||
| 1325 | * |
||
| 1326 | * @return array |
||
| 1327 | */ |
||
| 1328 | private function validate(array $property, $propertyName, $value) |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Checks if a value is unique for a property. |
||
| 1351 | * |
||
| 1352 | * @param array $property |
||
| 1353 | * @param string $propertyName |
||
| 1354 | * @param mixed $value |
||
| 1355 | * |
||
| 1356 | * @return bool |
||
| 1357 | */ |
||
| 1358 | private function checkUniqueness(array $property, $propertyName, $value) |
||
| 1372 | |||
| 1373 | /** |
||
| 1374 | * Gets the marshaled default value for a property (if set). |
||
| 1375 | * |
||
| 1376 | * @param string $property |
||
| 1377 | * |
||
| 1378 | * @return mixed |
||
| 1379 | */ |
||
| 1380 | private function getPropertyDefault(array $property) |
||
| 1384 | } |
||
| 1385 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: