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 |
||
| 45 | abstract class Model implements ArrayAccess |
||
| 46 | { |
||
| 47 | const IMMUTABLE = 0; |
||
| 48 | const MUTABLE_CREATE_ONLY = 1; |
||
| 49 | const MUTABLE = 2; |
||
| 50 | |||
| 51 | const TYPE_STRING = 'string'; |
||
| 52 | const TYPE_INTEGER = 'integer'; |
||
| 53 | const TYPE_FLOAT = 'float'; |
||
| 54 | const TYPE_BOOLEAN = 'boolean'; |
||
| 55 | const TYPE_DATE = 'date'; |
||
| 56 | const TYPE_OBJECT = 'object'; |
||
| 57 | const TYPE_ARRAY = 'array'; |
||
| 58 | |||
| 59 | const RELATIONSHIP_HAS_ONE = 'has_one'; |
||
| 60 | const RELATIONSHIP_HAS_MANY = 'has_many'; |
||
| 61 | const RELATIONSHIP_BELONGS_TO = 'belongs_to'; |
||
| 62 | const RELATIONSHIP_BELONGS_TO_MANY = 'belongs_to_many'; |
||
| 63 | |||
| 64 | const DEFAULT_ID_PROPERTY = 'id'; |
||
| 65 | |||
| 66 | ///////////////////////////// |
||
| 67 | // Model visible variables |
||
| 68 | ///////////////////////////// |
||
| 69 | |||
| 70 | /** |
||
| 71 | * List of model ID property names. |
||
| 72 | * |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | protected static $ids = [self::DEFAULT_ID_PROPERTY]; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Property definitions expressed as a key-value map with |
||
| 79 | * property names as the keys. |
||
| 80 | * i.e. ['enabled' => ['type' => Model::TYPE_BOOLEAN]]. |
||
| 81 | * |
||
| 82 | * @var array |
||
| 83 | */ |
||
| 84 | protected static $properties = []; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | private static $dispatchers; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var bool |
||
| 93 | */ |
||
| 94 | private $hasId; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | private $idValues; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | protected $_values = []; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var array |
||
| 108 | */ |
||
| 109 | protected $_unsaved = []; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var bool |
||
| 113 | */ |
||
| 114 | protected $_persisted = false; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var array |
||
| 118 | */ |
||
| 119 | protected $_relationships = []; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var bool |
||
| 123 | */ |
||
| 124 | private $loaded = false; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @var Errors |
||
| 128 | */ |
||
| 129 | private $errors; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var bool |
||
| 133 | */ |
||
| 134 | private $ignoreUnsaved; |
||
| 135 | |||
| 136 | ///////////////////////////// |
||
| 137 | // Base model variables |
||
| 138 | ///////////////////////////// |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var array |
||
| 142 | */ |
||
| 143 | private static $defaultIDProperty = [ |
||
| 144 | 'type' => self::TYPE_INTEGER, |
||
| 145 | 'mutable' => self::IMMUTABLE, |
||
| 146 | ]; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var array |
||
| 150 | */ |
||
| 151 | private static $timestampProperties = [ |
||
| 152 | 'created_at' => [ |
||
| 153 | 'type' => self::TYPE_DATE, |
||
| 154 | 'validate' => 'timestamp|db_timestamp', |
||
| 155 | ], |
||
| 156 | 'updated_at' => [ |
||
| 157 | 'type' => self::TYPE_DATE, |
||
| 158 | 'validate' => 'timestamp|db_timestamp', |
||
| 159 | ], |
||
| 160 | ]; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @var array |
||
| 164 | */ |
||
| 165 | private static $softDeleteProperties = [ |
||
| 166 | 'deleted_at' => [ |
||
| 167 | 'type' => self::TYPE_DATE, |
||
| 168 | 'validate' => 'timestamp|db_timestamp', |
||
| 169 | 'null' => true, |
||
| 170 | ], |
||
| 171 | ]; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var array |
||
| 175 | */ |
||
| 176 | private static $initialized = []; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var DriverInterface |
||
| 180 | */ |
||
| 181 | private static $driver; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var array |
||
| 185 | */ |
||
| 186 | private static $accessors = []; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var array |
||
| 190 | */ |
||
| 191 | private static $mutators = []; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Creates a new model object. |
||
| 195 | * |
||
| 196 | * @param array|string|Model|false $id ordered array of ids or comma-separated id string |
||
| 197 | * @param array $values optional key-value map to pre-seed model |
||
| 198 | */ |
||
| 199 | public function __construct($id = false, array $values = []) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Performs initialization on this model. |
||
| 215 | */ |
||
| 216 | private function init() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * The initialize() method is called once per model. This is a great |
||
| 228 | * place to install event listeners. |
||
| 229 | */ |
||
| 230 | protected function initialize() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Installs the `created_at` and `updated_at` properties. |
||
| 236 | */ |
||
| 237 | private static function installAutoTimestamps() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Installs the `deleted_at` properties. |
||
| 254 | */ |
||
| 255 | private static function installSoftDelete() |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Parses the given ID, which can be a single or composite primary key. |
||
| 262 | * |
||
| 263 | * @param mixed $id |
||
| 264 | */ |
||
| 265 | private function parseId($id) |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Sets the driver for all models. |
||
| 313 | */ |
||
| 314 | public static function setDriver(DriverInterface $driver) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Gets the driver for all models. |
||
| 321 | * |
||
| 322 | * @throws DriverMissingException when a driver has not been set yet |
||
| 323 | */ |
||
| 324 | public static function getDriver(): DriverInterface |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Clears the driver for all models. |
||
| 335 | */ |
||
| 336 | public static function clearDriver() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Gets the name of the model, i.e. User. |
||
| 343 | */ |
||
| 344 | public static function modelName(): string |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Gets the model ID. |
||
| 354 | * |
||
| 355 | * @return string|number|false ID |
||
| 356 | */ |
||
| 357 | public function id() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Gets a key-value map of the model ID. |
||
| 377 | * |
||
| 378 | * @return array ID map |
||
| 379 | */ |
||
| 380 | public function ids(): array |
||
| 384 | |||
| 385 | ///////////////////////////// |
||
| 386 | // Magic Methods |
||
| 387 | ///////////////////////////// |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Converts the model into a string. |
||
| 391 | * |
||
| 392 | * @return string |
||
| 393 | */ |
||
| 394 | public function __toString() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Shortcut to a get() call for a given property. |
||
| 404 | * |
||
| 405 | * @param string $name |
||
| 406 | * |
||
| 407 | * @return mixed |
||
| 408 | */ |
||
| 409 | public function __get($name) |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Sets an unsaved value. |
||
| 418 | * |
||
| 419 | * @param string $name |
||
| 420 | * @param mixed $value |
||
| 421 | */ |
||
| 422 | public function __set($name, $value) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Checks if an unsaved value or property exists by this name. |
||
| 440 | * |
||
| 441 | * @param string $name |
||
| 442 | * |
||
| 443 | * @return bool |
||
| 444 | */ |
||
| 445 | public function __isset($name) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Unsets an unsaved value. |
||
| 452 | * |
||
| 453 | * @param string $name |
||
| 454 | */ |
||
| 455 | public function __unset($name) |
||
| 466 | |||
| 467 | ///////////////////////////// |
||
| 468 | // ArrayAccess Interface |
||
| 469 | ///////////////////////////// |
||
| 470 | |||
| 471 | public function offsetExists($offset) |
||
| 475 | |||
| 476 | public function offsetGet($offset) |
||
| 480 | |||
| 481 | public function offsetSet($offset, $value) |
||
| 485 | |||
| 486 | public function offsetUnset($offset) |
||
| 490 | |||
| 491 | public static function __callStatic($name, $parameters) |
||
| 498 | |||
| 499 | ///////////////////////////// |
||
| 500 | // Property Definitions |
||
| 501 | ///////////////////////////// |
||
| 502 | |||
| 503 | /** |
||
| 504 | * The buildDefinition() method is called once per model. It's used |
||
| 505 | * to generate the model definition. This is a great place to add any |
||
| 506 | * dynamic model properties. |
||
| 507 | */ |
||
| 508 | public static function buildDefinition(): Definition |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Gets the definition of all model properties. |
||
| 563 | */ |
||
| 564 | public static function getProperties(): Definition |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Gets the definition of a specific property. |
||
| 571 | * |
||
| 572 | * @param string $property property to lookup |
||
| 573 | */ |
||
| 574 | public static function getProperty(string $property): ?Property |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Gets the names of the model ID properties. |
||
| 581 | */ |
||
| 582 | public static function getIDProperties(): array |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Checks if the model has a property. |
||
| 589 | * |
||
| 590 | * @param string $property property |
||
| 591 | * |
||
| 592 | * @return bool has property |
||
| 593 | */ |
||
| 594 | public static function hasProperty(string $property): bool |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Gets the mutator method name for a given proeprty name. |
||
| 601 | * Looks for methods in the form of `setPropertyValue`. |
||
| 602 | * i.e. the mutator for `last_name` would be `setLastNameValue`. |
||
| 603 | * |
||
| 604 | * @param string $property property |
||
| 605 | * |
||
| 606 | * @return string|null method name if it exists |
||
| 607 | */ |
||
| 608 | public static function getMutator(string $property): ?string |
||
| 626 | |||
| 627 | /** |
||
| 628 | * Gets the accessor method name for a given proeprty name. |
||
| 629 | * Looks for methods in the form of `getPropertyValue`. |
||
| 630 | * i.e. the accessor for `last_name` would be `getLastNameValue`. |
||
| 631 | * |
||
| 632 | * @param string $property property |
||
| 633 | * |
||
| 634 | * @return string|null method name if it exists |
||
| 635 | */ |
||
| 636 | public static function getAccessor(string $property): ?string |
||
| 654 | |||
| 655 | ///////////////////////////// |
||
| 656 | // CRUD Operations |
||
| 657 | ///////////////////////////// |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Gets the tablename for storing this model. |
||
| 661 | */ |
||
| 662 | public function getTablename(): string |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Gets the ID of the connection in the connection manager |
||
| 671 | * that stores this model. |
||
| 672 | */ |
||
| 673 | public function getConnection(): ?string |
||
| 677 | |||
| 678 | protected function usesTransactions(): bool |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Saves the model. |
||
| 685 | * |
||
| 686 | * @return bool true when the operation was successful |
||
| 687 | */ |
||
| 688 | public function save(): bool |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Saves the model. Throws an exception when the operation fails. |
||
| 699 | * |
||
| 700 | * @throws ModelException when the model cannot be saved |
||
| 701 | */ |
||
| 702 | public function saveOrFail() |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Creates a new model. |
||
| 716 | * |
||
| 717 | * @param array $data optional key-value properties to set |
||
| 718 | * |
||
| 719 | * @return bool true when the operation was successful |
||
| 720 | * |
||
| 721 | * @throws BadMethodCallException when called on an existing model |
||
| 722 | */ |
||
| 723 | public function create(array $data = []): bool |
||
| 825 | |||
| 826 | /** |
||
| 827 | * Ignores unsaved values when fetching the next value. |
||
| 828 | * |
||
| 829 | * @return $this |
||
| 830 | */ |
||
| 831 | public function ignoreUnsaved() |
||
| 837 | |||
| 838 | /** |
||
| 839 | * Fetches property values from the model. |
||
| 840 | * |
||
| 841 | * This method looks up values in this order: |
||
| 842 | * IDs, local cache, unsaved values, storage layer, defaults |
||
| 843 | * |
||
| 844 | * @param array $properties list of property names to fetch values of |
||
| 845 | */ |
||
| 846 | public function get(array $properties): array |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Gets a property value from the model. |
||
| 887 | * |
||
| 888 | * Values are looked up in this order: |
||
| 889 | * 1. unsaved values |
||
| 890 | * 2. local values |
||
| 891 | * 3. default value |
||
| 892 | * 4. null |
||
| 893 | * |
||
| 894 | * @param string $property |
||
| 895 | * |
||
| 896 | * @return mixed |
||
| 897 | */ |
||
| 898 | protected function getValue($property, array $values) |
||
| 915 | |||
| 916 | /** |
||
| 917 | * Populates a newly created model with its ID. |
||
| 918 | */ |
||
| 919 | protected function getNewID() |
||
| 939 | |||
| 940 | /** |
||
| 941 | * Sets a collection values on the model from an untrusted input. |
||
| 942 | * |
||
| 943 | * @param array $values |
||
| 944 | * |
||
| 945 | * @throws MassAssignmentException when assigning a value that is protected or not whitelisted |
||
| 946 | * |
||
| 947 | * @return $this |
||
| 948 | */ |
||
| 949 | public function setValues($values) |
||
| 969 | |||
| 970 | /** |
||
| 971 | * Converts the model to an array. |
||
| 972 | */ |
||
| 973 | public function toArray(): array |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Updates the model. |
||
| 1001 | * |
||
| 1002 | * @param array $data optional key-value properties to set |
||
| 1003 | * |
||
| 1004 | * @return bool true when the operation was successful |
||
| 1005 | * |
||
| 1006 | * @throws BadMethodCallException when not called on an existing model |
||
| 1007 | */ |
||
| 1008 | public function set(array $data = []): bool |
||
| 1085 | |||
| 1086 | /** |
||
| 1087 | * Delete the model. |
||
| 1088 | * |
||
| 1089 | * @return bool true when the operation was successful |
||
| 1090 | */ |
||
| 1091 | public function delete(): bool |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Restores a soft-deleted model. |
||
| 1144 | */ |
||
| 1145 | public function restore(): bool |
||
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Checks if the model has been deleted. |
||
| 1182 | */ |
||
| 1183 | public function isDeleted(): bool |
||
| 1191 | |||
| 1192 | ///////////////////////////// |
||
| 1193 | // Queries |
||
| 1194 | ///////////////////////////// |
||
| 1195 | |||
| 1196 | /** |
||
| 1197 | * Generates a new query instance. |
||
| 1198 | */ |
||
| 1199 | public static function query(): Query |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Generates a new query instance that includes soft-deleted models. |
||
| 1217 | */ |
||
| 1218 | public static function withDeleted(): Query |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Finds a single instance of a model given it's ID. |
||
| 1230 | * |
||
| 1231 | * @param mixed $id |
||
| 1232 | * |
||
| 1233 | * @return static|null |
||
| 1234 | */ |
||
| 1235 | public static function find($id): ?self |
||
| 1252 | |||
| 1253 | /** |
||
| 1254 | * Finds a single instance of a model given it's ID or throws an exception. |
||
| 1255 | * |
||
| 1256 | * @param mixed $id |
||
| 1257 | * |
||
| 1258 | * @return static |
||
| 1259 | * |
||
| 1260 | * @throws ModelNotFoundException when a model could not be found |
||
| 1261 | */ |
||
| 1262 | public static function findOrFail($id): self |
||
| 1271 | |||
| 1272 | /** |
||
| 1273 | * Tells if this model instance has been persisted to the data layer. |
||
| 1274 | * |
||
| 1275 | * NOTE: this does not actually perform a check with the data layer |
||
| 1276 | */ |
||
| 1277 | public function persisted(): bool |
||
| 1281 | |||
| 1282 | /** |
||
| 1283 | * Loads the model from the storage layer. |
||
| 1284 | * |
||
| 1285 | * @return $this |
||
| 1286 | */ |
||
| 1287 | public function refresh() |
||
| 1304 | |||
| 1305 | /** |
||
| 1306 | * Loads values into the model. |
||
| 1307 | * |
||
| 1308 | * @param array $values values |
||
| 1309 | * |
||
| 1310 | * @return $this |
||
| 1311 | */ |
||
| 1312 | public function refreshWith(array $values) |
||
| 1327 | |||
| 1328 | /** |
||
| 1329 | * Clears the cache for this model. |
||
| 1330 | * |
||
| 1331 | * @return $this |
||
| 1332 | */ |
||
| 1333 | public function clearCache() |
||
| 1342 | |||
| 1343 | ///////////////////////////// |
||
| 1344 | // Relationships |
||
| 1345 | ///////////////////////////// |
||
| 1346 | |||
| 1347 | /** |
||
| 1348 | * @deprecated |
||
| 1349 | * |
||
| 1350 | * Gets the model(s) for a relationship |
||
| 1351 | * |
||
| 1352 | * @param string $k property |
||
| 1353 | * |
||
| 1354 | * @throws InvalidArgumentException when the relationship manager cannot be created |
||
| 1355 | * |
||
| 1356 | * @return Model|array|null |
||
| 1357 | */ |
||
| 1358 | public function relation(string $k) |
||
| 1367 | |||
| 1368 | /** |
||
| 1369 | * @deprecated |
||
| 1370 | * |
||
| 1371 | * Sets the model for a one-to-one relationship (has-one or belongs-to) |
||
| 1372 | * |
||
| 1373 | * @return $this |
||
| 1374 | */ |
||
| 1375 | public function setRelation(string $k, Model $model) |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * @deprecated |
||
| 1385 | * |
||
| 1386 | * Sets the model for a one-to-many relationship |
||
| 1387 | * |
||
| 1388 | * @return $this |
||
| 1389 | */ |
||
| 1390 | public function setRelationCollection(string $k, iterable $models) |
||
| 1396 | |||
| 1397 | /** |
||
| 1398 | * Sets the model for a one-to-one relationship (has-one or belongs-to) as null. |
||
| 1399 | * |
||
| 1400 | * @return $this |
||
| 1401 | */ |
||
| 1402 | public function clearRelation(string $k) |
||
| 1409 | |||
| 1410 | ///////////////////////////// |
||
| 1411 | // Events |
||
| 1412 | ///////////////////////////// |
||
| 1413 | |||
| 1414 | /** |
||
| 1415 | * Gets the event dispatcher. |
||
| 1416 | */ |
||
| 1417 | public static function getDispatcher($ignoreCache = false): EventDispatcher |
||
| 1426 | |||
| 1427 | /** |
||
| 1428 | * Subscribes to a listener to an event. |
||
| 1429 | * |
||
| 1430 | * @param string $event event name |
||
| 1431 | * @param int $priority optional priority, higher #s get called first |
||
| 1432 | */ |
||
| 1433 | public static function listen(string $event, callable $listener, int $priority = 0) |
||
| 1437 | |||
| 1438 | /** |
||
| 1439 | * Adds a listener to the model.creating and model.updating events. |
||
| 1440 | */ |
||
| 1441 | public static function saving(callable $listener, int $priority = 0) |
||
| 1446 | |||
| 1447 | /** |
||
| 1448 | * Adds a listener to the model.created and model.updated events. |
||
| 1449 | */ |
||
| 1450 | public static function saved(callable $listener, int $priority = 0) |
||
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Adds a listener to the model.creating event. |
||
| 1458 | */ |
||
| 1459 | public static function creating(callable $listener, int $priority = 0) |
||
| 1463 | |||
| 1464 | /** |
||
| 1465 | * Adds a listener to the model.created event. |
||
| 1466 | */ |
||
| 1467 | public static function created(callable $listener, int $priority = 0) |
||
| 1471 | |||
| 1472 | /** |
||
| 1473 | * Adds a listener to the model.updating event. |
||
| 1474 | */ |
||
| 1475 | public static function updating(callable $listener, int $priority = 0) |
||
| 1479 | |||
| 1480 | /** |
||
| 1481 | * Adds a listener to the model.updated event. |
||
| 1482 | */ |
||
| 1483 | public static function updated(callable $listener, int $priority = 0) |
||
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Adds a listener to the model.deleting event. |
||
| 1490 | */ |
||
| 1491 | public static function deleting(callable $listener, int $priority = 0) |
||
| 1495 | |||
| 1496 | /** |
||
| 1497 | * Adds a listener to the model.deleted event. |
||
| 1498 | */ |
||
| 1499 | public static function deleted(callable $listener, int $priority = 0) |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Dispatches the given event and checks if it was successful. |
||
| 1506 | * |
||
| 1507 | * @return bool true if the events were successfully propagated |
||
| 1508 | */ |
||
| 1509 | private function performDispatch(string $eventName, bool $usesTransactions): bool |
||
| 1525 | |||
| 1526 | ///////////////////////////// |
||
| 1527 | // Validation |
||
| 1528 | ///////////////////////////// |
||
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Gets the error stack for this model. |
||
| 1532 | */ |
||
| 1533 | public function getErrors(): Errors |
||
| 1541 | |||
| 1542 | /** |
||
| 1543 | * Checks if the model in its current state is valid. |
||
| 1544 | */ |
||
| 1545 | public function valid(): bool |
||
| 1566 | |||
| 1567 | /** |
||
| 1568 | * Validates and marshals a value to storage. |
||
| 1569 | * |
||
| 1570 | * @param Property $property property definition |
||
| 1571 | * @param string $name property name |
||
| 1572 | * @param mixed $value |
||
| 1573 | */ |
||
| 1574 | private function filterAndValidate(Property $property, string $name, &$value): bool |
||
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Validates a value for a property. |
||
| 1597 | * |
||
| 1598 | * @param Property $property property definition |
||
| 1599 | * @param string $name property name |
||
| 1600 | * @param mixed $value |
||
| 1601 | */ |
||
| 1602 | private function validateValue(Property $property, string $name, $value): array |
||
| 1626 | |||
| 1627 | /** |
||
| 1628 | * Checks if a value is unique for a property. |
||
| 1629 | * |
||
| 1630 | * @param string $name property name |
||
| 1631 | * @param mixed $value |
||
| 1632 | */ |
||
| 1633 | private function checkUniqueness(string $name, $value): bool |
||
| 1648 | |||
| 1649 | /** |
||
| 1650 | * Gets the humanized name of a property. |
||
| 1651 | * |
||
| 1652 | * @param string $name property name |
||
| 1653 | */ |
||
| 1654 | private function getPropertyTitle(string $name): string |
||
| 1668 | } |
||
| 1669 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.