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 |
||
| 43 | abstract class Model implements ArrayAccess |
||
| 44 | { |
||
| 45 | /** @deprecated */ |
||
| 46 | const IMMUTABLE = 'immutable'; |
||
| 47 | /** @deprecated */ |
||
| 48 | const MUTABLE_CREATE_ONLY = 'mutable_create_only'; |
||
| 49 | /** @deprecated */ |
||
| 50 | const MUTABLE = 'mutable'; |
||
| 51 | |||
| 52 | /** @deprecated */ |
||
| 53 | const TYPE_STRING = 'string'; |
||
| 54 | /** @deprecated */ |
||
| 55 | const TYPE_INTEGER = 'integer'; |
||
| 56 | /** @deprecated */ |
||
| 57 | const TYPE_FLOAT = 'float'; |
||
| 58 | /** @deprecated */ |
||
| 59 | const TYPE_BOOLEAN = 'boolean'; |
||
| 60 | /** @deprecated */ |
||
| 61 | const TYPE_DATE = 'date'; |
||
| 62 | /** @deprecated */ |
||
| 63 | const TYPE_OBJECT = 'object'; |
||
| 64 | /** @deprecated */ |
||
| 65 | const TYPE_ARRAY = 'array'; |
||
| 66 | |||
| 67 | const RELATIONSHIP_HAS_ONE = 'has_one'; |
||
| 68 | const RELATIONSHIP_HAS_MANY = 'has_many'; |
||
| 69 | const RELATIONSHIP_BELONGS_TO = 'belongs_to'; |
||
| 70 | const RELATIONSHIP_BELONGS_TO_MANY = 'belongs_to_many'; |
||
| 71 | |||
| 72 | const DEFAULT_ID_NAME = 'id'; |
||
| 73 | |||
| 74 | ///////////////////////////// |
||
| 75 | // Model visible variables |
||
| 76 | ///////////////////////////// |
||
| 77 | |||
| 78 | /** |
||
| 79 | * List of model ID property names. |
||
| 80 | * |
||
| 81 | * @var array |
||
| 82 | */ |
||
| 83 | protected static $ids = [self::DEFAULT_ID_NAME]; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Property definitions expressed as a key-value map with |
||
| 87 | * property names as the keys. |
||
| 88 | * i.e. ['enabled' => ['type' => Type::BOOLEAN]]. |
||
| 89 | * |
||
| 90 | * @var array |
||
| 91 | */ |
||
| 92 | protected static $properties = []; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | protected $_values = []; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var array |
||
| 101 | */ |
||
| 102 | protected $_unsaved = []; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var bool |
||
| 106 | */ |
||
| 107 | protected $_persisted = false; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var array |
||
| 111 | */ |
||
| 112 | protected $_relationships = []; |
||
| 113 | |||
| 114 | ///////////////////////////// |
||
| 115 | // Base model variables |
||
| 116 | ///////////////////////////// |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var array |
||
| 120 | */ |
||
| 121 | private static $initialized = []; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var DriverInterface |
||
| 125 | */ |
||
| 126 | private static $driver; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var array |
||
| 130 | */ |
||
| 131 | private static $accessors = []; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var array |
||
| 135 | */ |
||
| 136 | private static $mutators = []; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var array |
||
| 140 | */ |
||
| 141 | private static $dispatchers = []; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var bool |
||
| 145 | */ |
||
| 146 | private $hasId; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var array |
||
| 150 | */ |
||
| 151 | private $idValues; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var bool |
||
| 155 | */ |
||
| 156 | private $loaded = false; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var Errors |
||
| 160 | */ |
||
| 161 | private $errors; |
||
| 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 = []) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Performs initialization on this model. |
||
| 190 | */ |
||
| 191 | private function init() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * The initialize() method is called once per model. This is a great |
||
| 203 | * place to install event listeners. |
||
| 204 | */ |
||
| 205 | protected function initialize() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Parses the given ID, which can be a single or composite primary key. |
||
| 222 | * |
||
| 223 | * @param mixed $id |
||
| 224 | */ |
||
| 225 | private function parseId($id) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Sets the driver for all models. |
||
| 273 | */ |
||
| 274 | public static function setDriver(DriverInterface $driver) |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Gets the driver for all models. |
||
| 281 | * |
||
| 282 | * @throws DriverMissingException when a driver has not been set yet |
||
| 283 | */ |
||
| 284 | public static function getDriver(): DriverInterface |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Clears the driver for all models. |
||
| 295 | */ |
||
| 296 | public static function clearDriver() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Gets the name of the model, i.e. User. |
||
| 303 | */ |
||
| 304 | public static function modelName(): string |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Gets the model ID. |
||
| 314 | * |
||
| 315 | * @return string|number|false ID |
||
| 316 | */ |
||
| 317 | public function id() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Gets a key-value map of the model ID. |
||
| 337 | * |
||
| 338 | * @return array ID map |
||
| 339 | */ |
||
| 340 | public function ids(): array |
||
| 344 | |||
| 345 | ///////////////////////////// |
||
| 346 | // Magic Methods |
||
| 347 | ///////////////////////////// |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Converts the model into a string. |
||
| 351 | * |
||
| 352 | * @return string |
||
| 353 | */ |
||
| 354 | public function __toString() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Shortcut to a get() call for a given property. |
||
| 364 | * |
||
| 365 | * @param string $name |
||
| 366 | * |
||
| 367 | * @return mixed |
||
| 368 | */ |
||
| 369 | public function __get($name) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Sets an unsaved value. |
||
| 378 | * |
||
| 379 | * @param string $name |
||
| 380 | * @param mixed $value |
||
| 381 | */ |
||
| 382 | public function __set($name, $value) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Checks if an unsaved value or property exists by this name. |
||
| 408 | * |
||
| 409 | * @param string $name |
||
| 410 | * |
||
| 411 | * @return bool |
||
| 412 | */ |
||
| 413 | public function __isset($name) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Unsets an unsaved value. |
||
| 420 | * |
||
| 421 | * @param string $name |
||
| 422 | */ |
||
| 423 | public function __unset($name) |
||
| 434 | |||
| 435 | ///////////////////////////// |
||
| 436 | // ArrayAccess Interface |
||
| 437 | ///////////////////////////// |
||
| 438 | |||
| 439 | public function offsetExists($offset) |
||
| 443 | |||
| 444 | public function offsetGet($offset) |
||
| 448 | |||
| 449 | public function offsetSet($offset, $value) |
||
| 453 | |||
| 454 | public function offsetUnset($offset) |
||
| 458 | |||
| 459 | public static function __callStatic($name, $parameters) |
||
| 466 | |||
| 467 | ///////////////////////////// |
||
| 468 | // Property Definitions |
||
| 469 | ///////////////////////////// |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Gets the definition of all model properties. |
||
| 473 | */ |
||
| 474 | public static function getProperties(): Definition |
||
| 478 | |||
| 479 | /** |
||
| 480 | * The buildDefinition() method is called once per model. It's used |
||
| 481 | * to generate the model definition. This is a great place to add any |
||
| 482 | * dynamic model properties. |
||
| 483 | */ |
||
| 484 | public static function buildDefinition(): Definition |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Gets the definition of a specific property. |
||
| 494 | * |
||
| 495 | * @param string $property property to lookup |
||
| 496 | */ |
||
| 497 | public static function getProperty(string $property): ?Property |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Gets the names of the model ID properties. |
||
| 504 | */ |
||
| 505 | public static function getIDProperties(): array |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Checks if the model has a property. |
||
| 512 | * |
||
| 513 | * @param string $property property |
||
| 514 | * |
||
| 515 | * @return bool has property |
||
| 516 | */ |
||
| 517 | public static function hasProperty(string $property): bool |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Gets the mutator method name for a given proeprty name. |
||
| 524 | * Looks for methods in the form of `setPropertyValue`. |
||
| 525 | * i.e. the mutator for `last_name` would be `setLastNameValue`. |
||
| 526 | * |
||
| 527 | * @param string $property property |
||
| 528 | * |
||
| 529 | * @return string|null method name if it exists |
||
| 530 | */ |
||
| 531 | public static function getMutator(string $property): ?string |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Gets the accessor method name for a given proeprty name. |
||
| 552 | * Looks for methods in the form of `getPropertyValue`. |
||
| 553 | * i.e. the accessor for `last_name` would be `getLastNameValue`. |
||
| 554 | * |
||
| 555 | * @param string $property property |
||
| 556 | * |
||
| 557 | * @return string|null method name if it exists |
||
| 558 | */ |
||
| 559 | public static function getAccessor(string $property): ?string |
||
| 577 | |||
| 578 | ///////////////////////////// |
||
| 579 | // CRUD Operations |
||
| 580 | ///////////////////////////// |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Gets the tablename for storing this model. |
||
| 584 | */ |
||
| 585 | public function getTablename(): string |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Gets the ID of the connection in the connection manager |
||
| 594 | * that stores this model. |
||
| 595 | */ |
||
| 596 | public function getConnection(): ?string |
||
| 600 | |||
| 601 | protected function usesTransactions(): bool |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Saves the model. |
||
| 608 | * |
||
| 609 | * @return bool true when the operation was successful |
||
| 610 | */ |
||
| 611 | public function save(): bool |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Saves the model. Throws an exception when the operation fails. |
||
| 622 | * |
||
| 623 | * @throws ModelException when the model cannot be saved |
||
| 624 | */ |
||
| 625 | public function saveOrFail() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Creates a new model. |
||
| 639 | * |
||
| 640 | * @param array $data optional key-value properties to set |
||
| 641 | * |
||
| 642 | * @return bool true when the operation was successful |
||
| 643 | * |
||
| 644 | * @throws BadMethodCallException when called on an existing model |
||
| 645 | */ |
||
| 646 | public function create(array $data = []): bool |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Ignores unsaved values when fetching the next value. |
||
| 758 | * |
||
| 759 | * @return $this |
||
| 760 | */ |
||
| 761 | public function ignoreUnsaved() |
||
| 767 | |||
| 768 | /** |
||
| 769 | * Fetches property values from the model. |
||
| 770 | * |
||
| 771 | * This method looks up values in this order: |
||
| 772 | * IDs, local cache, unsaved values, storage layer, defaults |
||
| 773 | * |
||
| 774 | * @param array $properties list of property names to fetch values of |
||
| 775 | */ |
||
| 776 | public function get(array $properties): array |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Gets a property value from the model. |
||
| 817 | * |
||
| 818 | * Values are looked up in this order: |
||
| 819 | * 1. unsaved values |
||
| 820 | * 2. local values |
||
| 821 | * 3. default value |
||
| 822 | * 4. null |
||
| 823 | * |
||
| 824 | * @param string $property |
||
| 825 | * |
||
| 826 | * @return mixed |
||
| 827 | */ |
||
| 828 | protected function getValue($property, array $values) |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Populates a newly created model with its ID. |
||
| 848 | */ |
||
| 849 | protected function getNewID() |
||
| 869 | |||
| 870 | /** |
||
| 871 | * Sets a collection values on the model from an untrusted input. |
||
| 872 | * |
||
| 873 | * @param array $values |
||
| 874 | * |
||
| 875 | * @throws MassAssignmentException when assigning a value that is protected or not whitelisted |
||
| 876 | * |
||
| 877 | * @return $this |
||
| 878 | */ |
||
| 879 | public function setValues($values) |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Converts the model to an array. |
||
| 902 | */ |
||
| 903 | public function toArray(): array |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Updates the model. |
||
| 931 | * |
||
| 932 | * @param array $data optional key-value properties to set |
||
| 933 | * |
||
| 934 | * @return bool true when the operation was successful |
||
| 935 | * |
||
| 936 | * @throws BadMethodCallException when not called on an existing model |
||
| 937 | */ |
||
| 938 | public function set(array $data = []): bool |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Delete the model. |
||
| 1025 | * |
||
| 1026 | * @return bool true when the operation was successful |
||
| 1027 | */ |
||
| 1028 | public function delete(): bool |
||
| 1078 | |||
| 1079 | /** |
||
| 1080 | * Restores a soft-deleted model. |
||
| 1081 | */ |
||
| 1082 | public function restore(): bool |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Checks if the model has been deleted. |
||
| 1119 | */ |
||
| 1120 | public function isDeleted(): bool |
||
| 1128 | |||
| 1129 | ///////////////////////////// |
||
| 1130 | // Queries |
||
| 1131 | ///////////////////////////// |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Generates a new query instance. |
||
| 1135 | */ |
||
| 1136 | public static function query(): Query |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Generates a new query instance that includes soft-deleted models. |
||
| 1154 | */ |
||
| 1155 | public static function withDeleted(): Query |
||
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Finds a single instance of a model given it's ID. |
||
| 1167 | * |
||
| 1168 | * @param mixed $id |
||
| 1169 | * |
||
| 1170 | * @return static|null |
||
| 1171 | */ |
||
| 1172 | public static function find($id): ?self |
||
| 1189 | |||
| 1190 | /** |
||
| 1191 | * Finds a single instance of a model given it's ID or throws an exception. |
||
| 1192 | * |
||
| 1193 | * @param mixed $id |
||
| 1194 | * |
||
| 1195 | * @return static |
||
| 1196 | * |
||
| 1197 | * @throws ModelNotFoundException when a model could not be found |
||
| 1198 | */ |
||
| 1199 | public static function findOrFail($id): self |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Tells if this model instance has been persisted to the data layer. |
||
| 1211 | * |
||
| 1212 | * NOTE: this does not actually perform a check with the data layer |
||
| 1213 | */ |
||
| 1214 | public function persisted(): bool |
||
| 1218 | |||
| 1219 | /** |
||
| 1220 | * Loads the model from the storage layer. |
||
| 1221 | * |
||
| 1222 | * @return $this |
||
| 1223 | */ |
||
| 1224 | public function refresh() |
||
| 1241 | |||
| 1242 | /** |
||
| 1243 | * Loads values into the model. |
||
| 1244 | * |
||
| 1245 | * @param array $values values |
||
| 1246 | * |
||
| 1247 | * @return $this |
||
| 1248 | */ |
||
| 1249 | public function refreshWith(array $values) |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Clears the cache for this model. |
||
| 1267 | * |
||
| 1268 | * @return $this |
||
| 1269 | */ |
||
| 1270 | public function clearCache() |
||
| 1279 | |||
| 1280 | ///////////////////////////// |
||
| 1281 | // Relationships |
||
| 1282 | ///////////////////////////// |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * @deprecated |
||
| 1286 | * |
||
| 1287 | * Gets the model(s) for a relationship |
||
| 1288 | * |
||
| 1289 | * @param string $k property |
||
| 1290 | * |
||
| 1291 | * @throws InvalidArgumentException when the relationship manager cannot be created |
||
| 1292 | * |
||
| 1293 | * @return Model|array|null |
||
| 1294 | */ |
||
| 1295 | public function relation(string $k) |
||
| 1304 | |||
| 1305 | /** |
||
| 1306 | * @deprecated |
||
| 1307 | * |
||
| 1308 | * Sets the model for a one-to-one relationship (has-one or belongs-to) |
||
| 1309 | * |
||
| 1310 | * @return $this |
||
| 1311 | */ |
||
| 1312 | public function setRelation(string $k, Model $model) |
||
| 1319 | |||
| 1320 | /** |
||
| 1321 | * @deprecated |
||
| 1322 | * |
||
| 1323 | * Sets the model for a one-to-many relationship |
||
| 1324 | * |
||
| 1325 | * @return $this |
||
| 1326 | */ |
||
| 1327 | public function setRelationCollection(string $k, iterable $models) |
||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * Sets the model for a one-to-one relationship (has-one or belongs-to) as null. |
||
| 1336 | * |
||
| 1337 | * @return $this |
||
| 1338 | */ |
||
| 1339 | public function clearRelation(string $k) |
||
| 1346 | |||
| 1347 | ///////////////////////////// |
||
| 1348 | // Events |
||
| 1349 | ///////////////////////////// |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Gets the event dispatcher. |
||
| 1353 | */ |
||
| 1354 | public static function getDispatcher($ignoreCache = false): EventDispatcher |
||
| 1363 | |||
| 1364 | /** |
||
| 1365 | * Subscribes to a listener to an event. |
||
| 1366 | * |
||
| 1367 | * @param string $event event name |
||
| 1368 | * @param int $priority optional priority, higher #s get called first |
||
| 1369 | */ |
||
| 1370 | public static function listen(string $event, callable $listener, int $priority = 0) |
||
| 1374 | |||
| 1375 | /** |
||
| 1376 | * Adds a listener to the model.creating and model.updating events. |
||
| 1377 | */ |
||
| 1378 | public static function saving(callable $listener, int $priority = 0) |
||
| 1383 | |||
| 1384 | /** |
||
| 1385 | * Adds a listener to the model.created and model.updated events. |
||
| 1386 | */ |
||
| 1387 | public static function saved(callable $listener, int $priority = 0) |
||
| 1392 | |||
| 1393 | /** |
||
| 1394 | * Adds a listener to the model.creating event. |
||
| 1395 | */ |
||
| 1396 | public static function creating(callable $listener, int $priority = 0) |
||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Adds a listener to the model.created event. |
||
| 1403 | */ |
||
| 1404 | public static function created(callable $listener, int $priority = 0) |
||
| 1408 | |||
| 1409 | /** |
||
| 1410 | * Adds a listener to the model.updating event. |
||
| 1411 | */ |
||
| 1412 | public static function updating(callable $listener, int $priority = 0) |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Adds a listener to the model.updated event. |
||
| 1419 | */ |
||
| 1420 | public static function updated(callable $listener, int $priority = 0) |
||
| 1424 | |||
| 1425 | /** |
||
| 1426 | * Adds a listener to the model.deleting event. |
||
| 1427 | */ |
||
| 1428 | public static function deleting(callable $listener, int $priority = 0) |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Adds a listener to the model.deleted event. |
||
| 1435 | */ |
||
| 1436 | public static function deleted(callable $listener, int $priority = 0) |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * Dispatches the given event and checks if it was successful. |
||
| 1443 | * |
||
| 1444 | * @return bool true if the events were successfully propagated |
||
| 1445 | */ |
||
| 1446 | private function performDispatch(string $eventName, bool $usesTransactions): bool |
||
| 1462 | |||
| 1463 | ///////////////////////////// |
||
| 1464 | // Validation |
||
| 1465 | ///////////////////////////// |
||
| 1466 | |||
| 1467 | /** |
||
| 1468 | * Gets the error stack for this model. |
||
| 1469 | */ |
||
| 1470 | public function getErrors(): Errors |
||
| 1478 | |||
| 1479 | /** |
||
| 1480 | * Checks if the model in its current state is valid. |
||
| 1481 | */ |
||
| 1482 | public function valid(): bool |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Validates and marshals a value to storage. |
||
| 1506 | * |
||
| 1507 | * @param Property $property property definition |
||
| 1508 | * @param string $name property name |
||
| 1509 | * @param mixed $value |
||
| 1510 | */ |
||
| 1511 | private function filterAndValidate(Property $property, string $name, &$value): bool |
||
| 1531 | |||
| 1532 | /** |
||
| 1533 | * Validates a value for a property. |
||
| 1534 | * |
||
| 1535 | * @param Property $property property definition |
||
| 1536 | * @param string $name property name |
||
| 1537 | * @param mixed $value |
||
| 1538 | */ |
||
| 1539 | private function validateValue(Property $property, string $name, $value): array |
||
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Checks if a value is unique for a property. |
||
| 1566 | * |
||
| 1567 | * @param string $name property name |
||
| 1568 | * @param mixed $value |
||
| 1569 | */ |
||
| 1570 | private function checkUniqueness(string $name, $value): bool |
||
| 1585 | |||
| 1586 | /** |
||
| 1587 | * Gets the humanized name of a property. |
||
| 1588 | * |
||
| 1589 | * @param string $name property name |
||
| 1590 | */ |
||
| 1591 | private function getPropertyTitle(string $name): string |
||
| 1605 | } |
||
| 1606 |
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.