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 |
||
| 25 | abstract class Model implements \ArrayAccess |
||
| 26 | { |
||
| 27 | const IMMUTABLE = 0; |
||
| 28 | const MUTABLE_CREATE_ONLY = 1; |
||
| 29 | const MUTABLE = 2; |
||
| 30 | |||
| 31 | const TYPE_STRING = 'string'; |
||
| 32 | const TYPE_NUMBER = 'number'; |
||
| 33 | const TYPE_BOOLEAN = 'boolean'; |
||
| 34 | const TYPE_DATE = 'date'; |
||
| 35 | const TYPE_OBJECT = 'object'; |
||
| 36 | const TYPE_ARRAY = 'array'; |
||
| 37 | |||
| 38 | const ERROR_REQUIRED_FIELD_MISSING = 'required_field_missing'; |
||
| 39 | const ERROR_VALIDATION_FAILED = 'validation_failed'; |
||
| 40 | const ERROR_NOT_UNIQUE = 'not_unique'; |
||
| 41 | |||
| 42 | const DEFAULT_ID_PROPERTY = 'id'; |
||
| 43 | |||
| 44 | ///////////////////////////// |
||
| 45 | // Model visible variables |
||
| 46 | ///////////////////////////// |
||
| 47 | |||
| 48 | /** |
||
| 49 | * List of model ID property names. |
||
| 50 | * |
||
| 51 | * @staticvar array |
||
| 52 | */ |
||
| 53 | protected static $ids = [self::DEFAULT_ID_PROPERTY]; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Property definitions expressed as a key-value map with |
||
| 57 | * property names as the keys. |
||
| 58 | * i.e. ['enabled' => ['type' => Model::TYPE_BOOLEAN]]. |
||
| 59 | * |
||
| 60 | * @staticvar array |
||
| 61 | */ |
||
| 62 | protected static $properties = []; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @staticvar \Pimple\Container |
||
| 66 | */ |
||
| 67 | protected static $injectedApp; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @staticvar array |
||
| 71 | */ |
||
| 72 | protected static $dispatchers; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var number|string|bool |
||
| 76 | */ |
||
| 77 | protected $_id; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var \Pimple\Container |
||
| 81 | */ |
||
| 82 | protected $app; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var array |
||
| 86 | */ |
||
| 87 | protected $_values = []; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var array |
||
| 91 | */ |
||
| 92 | protected $_unsaved = []; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | protected $_relationships = []; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var \Infuse\ErrorStack |
||
| 101 | */ |
||
| 102 | protected $_errors; |
||
| 103 | |||
| 104 | ///////////////////////////// |
||
| 105 | // Base model variables |
||
| 106 | ///////////////////////////// |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @staticvar array |
||
| 110 | */ |
||
| 111 | private static $propertyDefinitionBase = [ |
||
| 112 | 'type' => self::TYPE_STRING, |
||
| 113 | 'mutable' => self::MUTABLE, |
||
| 114 | 'null' => false, |
||
| 115 | 'unique' => false, |
||
| 116 | 'required' => false, |
||
| 117 | ]; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @staticvar array |
||
| 121 | */ |
||
| 122 | private static $defaultIDProperty = [ |
||
| 123 | 'type' => self::TYPE_NUMBER, |
||
| 124 | 'mutable' => self::IMMUTABLE, |
||
| 125 | ]; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @staticvar array |
||
| 129 | */ |
||
| 130 | private static $timestampProperties = [ |
||
| 131 | 'created_at' => [ |
||
| 132 | 'type' => self::TYPE_DATE, |
||
| 133 | 'default' => null, |
||
| 134 | 'null' => true, |
||
| 135 | 'validate' => 'timestamp|db_timestamp', |
||
| 136 | ], |
||
| 137 | 'updated_at' => [ |
||
| 138 | 'type' => self::TYPE_DATE, |
||
| 139 | 'validate' => 'timestamp|db_timestamp', |
||
| 140 | ], |
||
| 141 | ]; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @staticvar array |
||
| 145 | */ |
||
| 146 | private static $initialized = []; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @staticvar Model\Driver\DriverInterface |
||
| 150 | */ |
||
| 151 | private static $driver; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @staticvar array |
||
| 155 | */ |
||
| 156 | private static $accessors = []; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @staticvar array |
||
| 160 | */ |
||
| 161 | private static $mutators = []; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var bool |
||
| 165 | */ |
||
| 166 | private $_ignoreUnsaved; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Creates a new model object. |
||
| 170 | * |
||
| 171 | * @param array|string|Model|false $id ordered array of ids or comma-separated id string |
||
| 172 | * @param array $values optional key-value map to pre-seed model |
||
| 173 | */ |
||
| 174 | public function __construct($id = false, array $values = []) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Performs initialization on this model. |
||
| 206 | */ |
||
| 207 | private function init() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * The initialize() method is called once per model. It's used |
||
| 219 | * to perform any one-off tasks before the model gets |
||
| 220 | * constructed. This is a great place to add any model |
||
| 221 | * properties. When extending this method be sure to call |
||
| 222 | * parent::initialize() as some important stuff happens here. |
||
| 223 | * If extending this method to add properties then you should |
||
| 224 | * call parent::initialize() after adding any properties. |
||
| 225 | */ |
||
| 226 | protected function initialize() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Injects a DI container. |
||
| 254 | * |
||
| 255 | * @param \Pimple\Container $app |
||
| 256 | */ |
||
| 257 | public static function inject(Container $app) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Gets the DI container used for this model. |
||
| 264 | * |
||
| 265 | * @return Container |
||
| 266 | */ |
||
| 267 | public function getApp() |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Sets the driver for all models. |
||
| 274 | * |
||
| 275 | * @param Model\Driver\DriverInterface $driver |
||
| 276 | */ |
||
| 277 | public static function setDriver(DriverInterface $driver) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Gets the driver for all models. |
||
| 284 | * |
||
| 285 | * @return Model\Driver\DriverInterface |
||
| 286 | */ |
||
| 287 | public static function getDriver() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Gets the name of the model without namespacing. |
||
| 294 | * |
||
| 295 | * @return string |
||
| 296 | */ |
||
| 297 | public static function modelName() |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Gets the model ID. |
||
| 309 | * |
||
| 310 | * @return string|number|false ID |
||
| 311 | */ |
||
| 312 | public function id() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Gets a key-value map of the model ID. |
||
| 319 | * |
||
| 320 | * @return array ID map |
||
| 321 | */ |
||
| 322 | public function ids() |
||
| 340 | |||
| 341 | ///////////////////////////// |
||
| 342 | // Magic Methods |
||
| 343 | ///////////////////////////// |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Converts the model into a string. |
||
| 347 | * |
||
| 348 | * @return string |
||
| 349 | */ |
||
| 350 | public function __toString() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Shortcut to a get() call for a given property. |
||
| 357 | * |
||
| 358 | * @param string $name |
||
| 359 | * |
||
| 360 | * @return mixed |
||
| 361 | */ |
||
| 362 | public function __get($name) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Sets an unsaved value. |
||
| 371 | * |
||
| 372 | * @param string $name |
||
| 373 | * @param mixed $value |
||
| 374 | */ |
||
| 375 | public function __set($name, $value) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Checks if an unsaved value or property exists by this name. |
||
| 393 | * |
||
| 394 | * @param string $name |
||
| 395 | * |
||
| 396 | * @return bool |
||
| 397 | */ |
||
| 398 | public function __isset($name) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Unsets an unsaved value. |
||
| 405 | * |
||
| 406 | * @param string $name |
||
| 407 | */ |
||
| 408 | public function __unset($name) |
||
| 419 | |||
| 420 | ///////////////////////////// |
||
| 421 | // ArrayAccess Interface |
||
| 422 | ///////////////////////////// |
||
| 423 | |||
| 424 | public function offsetExists($offset) |
||
| 428 | |||
| 429 | public function offsetGet($offset) |
||
| 433 | |||
| 434 | public function offsetSet($offset, $value) |
||
| 438 | |||
| 439 | public function offsetUnset($offset) |
||
| 443 | |||
| 444 | public static function __callStatic($name, $parameters) |
||
| 451 | |||
| 452 | ///////////////////////////// |
||
| 453 | // Property Definitions |
||
| 454 | ///////////////////////////// |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Gets all the property definitions for the model. |
||
| 458 | * |
||
| 459 | * @return array key-value map of properties |
||
| 460 | */ |
||
| 461 | public static function getProperties() |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Gets a property defition for the model. |
||
| 468 | * |
||
| 469 | * @param string $property property to lookup |
||
| 470 | * |
||
| 471 | * @return array|null property |
||
| 472 | */ |
||
| 473 | public static function getProperty($property) |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Gets the names of the model ID properties. |
||
| 480 | * |
||
| 481 | * @return array |
||
| 482 | */ |
||
| 483 | public static function getIDProperties() |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Checks if the model has a property. |
||
| 490 | * |
||
| 491 | * @param string $property property |
||
| 492 | * |
||
| 493 | * @return bool has property |
||
| 494 | */ |
||
| 495 | public static function hasProperty($property) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Gets the mutator method name for a given proeprty name. |
||
| 502 | * Looks for methods in the form of `setPropertyValue`. |
||
| 503 | * i.e. the mutator for `last_name` would be `setLastNameValue`. |
||
| 504 | * |
||
| 505 | * @param string $property property |
||
| 506 | * |
||
| 507 | * @return string|false method name if it exists |
||
| 508 | */ |
||
| 509 | View Code Duplication | public static function getMutator($property) |
|
| 527 | |||
| 528 | /** |
||
| 529 | * Gets the accessor method name for a given proeprty name. |
||
| 530 | * Looks for methods in the form of `getPropertyValue`. |
||
| 531 | * i.e. the accessor for `last_name` would be `getLastNameValue`. |
||
| 532 | * |
||
| 533 | * @param string $property property |
||
| 534 | * |
||
| 535 | * @return string|false method name if it exists |
||
| 536 | */ |
||
| 537 | View Code Duplication | public static function getAccessor($property) |
|
| 555 | |||
| 556 | ///////////////////////////// |
||
| 557 | // CRUD Operations |
||
| 558 | ///////////////////////////// |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Saves the model. |
||
| 562 | * |
||
| 563 | * @return bool |
||
| 564 | */ |
||
| 565 | public function save() |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Creates a new model. |
||
| 576 | * |
||
| 577 | * @param array $data optional key-value properties to set |
||
| 578 | * |
||
| 579 | * @return bool |
||
| 580 | * |
||
| 581 | * @throws BadMethodCallException when called on an existing model |
||
| 582 | */ |
||
| 583 | public function create(array $data = []) |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Ignores unsaved values when fetching the next value. |
||
| 674 | * |
||
| 675 | * @return self |
||
| 676 | */ |
||
| 677 | public function ignoreUnsaved() |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Fetches property values from the model. |
||
| 686 | * |
||
| 687 | * This method looks up values in this order: |
||
| 688 | * IDs, local cache, unsaved values, storage layer, defaults |
||
| 689 | * |
||
| 690 | * @param array $properties list of property names to fetch values of |
||
| 691 | * |
||
| 692 | * @return array |
||
| 693 | */ |
||
| 694 | public function get(array $properties) |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Builds a key-value map of the requested properties given a set of values |
||
| 725 | * |
||
| 726 | * @param array $properties |
||
| 727 | * @param array $values |
||
| 728 | * |
||
| 729 | * @return array |
||
| 730 | * |
||
| 731 | * @throws InvalidArgumentException when a property was requested not present in the values |
||
| 732 | */ |
||
| 733 | private function buildGetResponse(array $properties, array $values) |
||
| 762 | |||
| 763 | /** |
||
| 764 | * Gets the ID for a newly created model. |
||
| 765 | * |
||
| 766 | * @return string |
||
| 767 | */ |
||
| 768 | protected function getNewID() |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Converts the model to an array. |
||
| 788 | * |
||
| 789 | * @return array model array |
||
| 790 | */ |
||
| 791 | public function toArray() |
||
| 809 | |||
| 810 | /** |
||
| 811 | * Updates the model. |
||
| 812 | * |
||
| 813 | * @param array $data optional key-value properties to set |
||
| 814 | * |
||
| 815 | * @return bool |
||
| 816 | * |
||
| 817 | * @throws BadMethodCallException when not called on an existing model |
||
| 818 | */ |
||
| 819 | public function set(array $data = []) |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Delete the model. |
||
| 885 | * |
||
| 886 | * @return bool success |
||
| 887 | */ |
||
| 888 | public function delete() |
||
| 915 | |||
| 916 | ///////////////////////////// |
||
| 917 | // Queries |
||
| 918 | ///////////////////////////// |
||
| 919 | |||
| 920 | /** |
||
| 921 | * Generates a new query instance. |
||
| 922 | * |
||
| 923 | * @return Model\Query |
||
| 924 | */ |
||
| 925 | public static function query() |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Gets the toal number of records matching an optional criteria. |
||
| 937 | * |
||
| 938 | * @param array $where criteria |
||
| 939 | * |
||
| 940 | * @return int total |
||
| 941 | */ |
||
| 942 | public static function totalRecords(array $where = []) |
||
| 949 | |||
| 950 | /** |
||
| 951 | * Checks if the model exists in the database. |
||
| 952 | * |
||
| 953 | * @return bool |
||
| 954 | */ |
||
| 955 | public function exists() |
||
| 959 | |||
| 960 | /** |
||
| 961 | * @deprecated alias for refresh() |
||
| 962 | */ |
||
| 963 | public function load() |
||
| 967 | |||
| 968 | /** |
||
| 969 | * Loads the model from the storage layer. |
||
| 970 | * |
||
| 971 | * @return self |
||
| 972 | */ |
||
| 973 | public function refresh() |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Loads values into the model. |
||
| 993 | * |
||
| 994 | * @param array $values values |
||
| 995 | * |
||
| 996 | * @return self |
||
| 997 | */ |
||
| 998 | public function refreshWith(array $values) |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Clears the cache for this model. |
||
| 1007 | * |
||
| 1008 | * @return self |
||
| 1009 | */ |
||
| 1010 | public function clearCache() |
||
| 1018 | |||
| 1019 | ///////////////////////////// |
||
| 1020 | // Relationships |
||
| 1021 | ///////////////////////////// |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Gets the model object corresponding to a relation |
||
| 1025 | * WARNING no check is used to see if the model returned actually exists. |
||
| 1026 | * |
||
| 1027 | * @param string $propertyName property |
||
| 1028 | * |
||
| 1029 | * @return \Pulsar\Model model |
||
| 1030 | */ |
||
| 1031 | public function relation($propertyName) |
||
| 1043 | |||
| 1044 | /** |
||
| 1045 | * Creates the parent side of a One-To-One relationship. |
||
| 1046 | * |
||
| 1047 | * @param string $model foreign model class |
||
| 1048 | * @param string $foreignKey identifying key on foreign model |
||
| 1049 | * @param string $localKey identifying key on local model |
||
| 1050 | * |
||
| 1051 | * @return Relation |
||
| 1052 | */ |
||
| 1053 | View Code Duplication | public function hasOne($model, $foreignKey = '', $localKey = '') |
|
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Creates the child side of a One-To-One or One-To-Many relationship. |
||
| 1071 | * |
||
| 1072 | * @param string $model foreign model class |
||
| 1073 | * @param string $foreignKey identifying key on foreign model |
||
| 1074 | * @param string $localKey identifying key on local model |
||
| 1075 | * |
||
| 1076 | * @return Relation |
||
| 1077 | */ |
||
| 1078 | View Code Duplication | public function belongsTo($model, $foreignKey = '', $localKey = '') |
|
| 1093 | |||
| 1094 | /** |
||
| 1095 | * Creates the parent side of a Many-To-One or Many-To-Many relationship. |
||
| 1096 | * |
||
| 1097 | * @param string $model foreign model class |
||
| 1098 | * @param string $foreignKey identifying key on foreign model |
||
| 1099 | * @param string $localKey identifying key on local model |
||
| 1100 | * |
||
| 1101 | * @return Relation |
||
| 1102 | */ |
||
| 1103 | View Code Duplication | public function hasMany($model, $foreignKey = '', $localKey = '') |
|
| 1118 | |||
| 1119 | /** |
||
| 1120 | * Creates the child side of a Many-To-Many relationship. |
||
| 1121 | * |
||
| 1122 | * @param string $model foreign model class |
||
| 1123 | * @param string $foreignKey identifying key on foreign model |
||
| 1124 | * @param string $localKey identifying key on local model |
||
| 1125 | * |
||
| 1126 | * @return Relation |
||
| 1127 | */ |
||
| 1128 | View Code Duplication | public function belongsToMany($model, $foreignKey = '', $localKey = '') |
|
| 1143 | |||
| 1144 | ///////////////////////////// |
||
| 1145 | // Events |
||
| 1146 | ///////////////////////////// |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * Gets the event dispatcher. |
||
| 1150 | * |
||
| 1151 | * @return \Symfony\Component\EventDispatcher\EventDispatcher |
||
| 1152 | */ |
||
| 1153 | public static function getDispatcher($ignoreCache = false) |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Subscribes to a listener to an event. |
||
| 1165 | * |
||
| 1166 | * @param string $event event name |
||
| 1167 | * @param callable $listener |
||
| 1168 | * @param int $priority optional priority, higher #s get called first |
||
| 1169 | */ |
||
| 1170 | public static function listen($event, callable $listener, $priority = 0) |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Adds a listener to the model.creating event. |
||
| 1177 | * |
||
| 1178 | * @param callable $listener |
||
| 1179 | * @param int $priority |
||
| 1180 | */ |
||
| 1181 | public static function creating(callable $listener, $priority = 0) |
||
| 1185 | |||
| 1186 | /** |
||
| 1187 | * Adds a listener to the model.created event. |
||
| 1188 | * |
||
| 1189 | * @param callable $listener |
||
| 1190 | * @param int $priority |
||
| 1191 | */ |
||
| 1192 | public static function created(callable $listener, $priority = 0) |
||
| 1196 | |||
| 1197 | /** |
||
| 1198 | * Adds a listener to the model.updating event. |
||
| 1199 | * |
||
| 1200 | * @param callable $listener |
||
| 1201 | * @param int $priority |
||
| 1202 | */ |
||
| 1203 | public static function updating(callable $listener, $priority = 0) |
||
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Adds a listener to the model.updated event. |
||
| 1210 | * |
||
| 1211 | * @param callable $listener |
||
| 1212 | * @param int $priority |
||
| 1213 | */ |
||
| 1214 | public static function updated(callable $listener, $priority = 0) |
||
| 1218 | |||
| 1219 | /** |
||
| 1220 | * Adds a listener to the model.deleting event. |
||
| 1221 | * |
||
| 1222 | * @param callable $listener |
||
| 1223 | * @param int $priority |
||
| 1224 | */ |
||
| 1225 | public static function deleting(callable $listener, $priority = 0) |
||
| 1229 | |||
| 1230 | /** |
||
| 1231 | * Adds a listener to the model.deleted event. |
||
| 1232 | * |
||
| 1233 | * @param callable $listener |
||
| 1234 | * @param int $priority |
||
| 1235 | */ |
||
| 1236 | public static function deleted(callable $listener, $priority = 0) |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Dispatches an event. |
||
| 1243 | * |
||
| 1244 | * @param string $eventName |
||
| 1245 | * |
||
| 1246 | * @return Model\ModelEvent |
||
| 1247 | */ |
||
| 1248 | protected function dispatch($eventName) |
||
| 1254 | |||
| 1255 | /** |
||
| 1256 | * Dispatches the given event and checks if it was successful. |
||
| 1257 | * |
||
| 1258 | * @param string $eventName |
||
| 1259 | * |
||
| 1260 | * @return bool |
||
| 1261 | */ |
||
| 1262 | private function handleDispatch($eventName) |
||
| 1268 | |||
| 1269 | ///////////////////////////// |
||
| 1270 | // Validation |
||
| 1271 | ///////////////////////////// |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * Gets the error stack for this model instance. Used to |
||
| 1275 | * keep track of validation errors. |
||
| 1276 | * |
||
| 1277 | * @return \Infuse\ErrorStack |
||
| 1278 | */ |
||
| 1279 | function getErrors() |
||
| 1287 | |||
| 1288 | /** |
||
| 1289 | * Validates and marshals a value to storage. |
||
| 1290 | * |
||
| 1291 | * @param array $property |
||
| 1292 | * @param string $propertyName |
||
| 1293 | * @param mixed $value |
||
| 1294 | * |
||
| 1295 | * @return bool |
||
| 1296 | */ |
||
| 1297 | private function filterAndValidate(array $property, $propertyName, &$value) |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Validates a value for a property. |
||
| 1320 | * |
||
| 1321 | * @param array $property |
||
| 1322 | * @param string $propertyName |
||
| 1323 | * @param mixed $value |
||
| 1324 | * |
||
| 1325 | * @return bool |
||
| 1326 | */ |
||
| 1327 | private function validate(array $property, $propertyName, $value) |
||
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Checks if a value is unique for a property. |
||
| 1350 | * |
||
| 1351 | * @param array $property |
||
| 1352 | * @param string $propertyName |
||
| 1353 | * @param mixed $value |
||
| 1354 | * |
||
| 1355 | * @return bool |
||
| 1356 | */ |
||
| 1357 | private function checkUniqueness(array $property, $propertyName, $value) |
||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * Gets the marshaled default value for a property (if set). |
||
| 1374 | * |
||
| 1375 | * @param string $property |
||
| 1376 | * |
||
| 1377 | * @return mixed |
||
| 1378 | */ |
||
| 1379 | private function getPropertyDefault(array $property) |
||
| 1383 | } |
||
| 1384 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: