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 |
||
47 | abstract class Model implements ArrayAccess |
||
48 | { |
||
49 | const DEFAULT_ID_NAME = 'id'; |
||
50 | |||
51 | ///////////////////////////// |
||
52 | // Model visible variables |
||
53 | ///////////////////////////// |
||
54 | |||
55 | /** |
||
56 | * List of model ID property names. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected static $ids = [self::DEFAULT_ID_NAME]; |
||
61 | |||
62 | /** |
||
63 | * Property definitions expressed as a key-value map with |
||
64 | * property names as the keys. |
||
65 | * i.e. ['enabled' => ['type' => Type::BOOLEAN]]. |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | protected static $properties = []; |
||
70 | |||
71 | /** |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $_values = []; |
||
75 | |||
76 | /** |
||
77 | * @var array |
||
78 | */ |
||
79 | private $_unsaved = []; |
||
80 | |||
81 | /** |
||
82 | * @var bool |
||
83 | */ |
||
84 | protected $_persisted = false; |
||
85 | |||
86 | /** |
||
87 | * @var array |
||
88 | */ |
||
89 | protected $_relationships = []; |
||
90 | |||
91 | /** |
||
92 | * @var AbstractRelation[] |
||
93 | */ |
||
94 | private $relationships = []; |
||
95 | |||
96 | ///////////////////////////// |
||
97 | // Base model variables |
||
98 | ///////////////////////////// |
||
99 | |||
100 | /** |
||
101 | * @var array |
||
102 | */ |
||
103 | private static $initialized = []; |
||
104 | |||
105 | /** |
||
106 | * @var DriverInterface |
||
107 | */ |
||
108 | private static $driver; |
||
109 | |||
110 | /** |
||
111 | * @var array |
||
112 | */ |
||
113 | private static $accessors = []; |
||
114 | |||
115 | /** |
||
116 | * @var array |
||
117 | */ |
||
118 | private static $mutators = []; |
||
119 | |||
120 | /** |
||
121 | * @var string |
||
122 | */ |
||
123 | private $tablename; |
||
124 | |||
125 | /** |
||
126 | * @var bool |
||
127 | */ |
||
128 | private $hasId; |
||
129 | |||
130 | /** |
||
131 | * @var array |
||
132 | */ |
||
133 | private $idValues; |
||
134 | |||
135 | /** |
||
136 | * @var bool |
||
137 | */ |
||
138 | private $loaded = false; |
||
139 | |||
140 | /** |
||
141 | * @var Errors |
||
142 | */ |
||
143 | private $errors; |
||
144 | |||
145 | /** |
||
146 | * @var bool |
||
147 | */ |
||
148 | private $ignoreUnsaved = false; |
||
149 | |||
150 | /** |
||
151 | * Creates a new model object. |
||
152 | * |
||
153 | * @param array|string|Model|false $id ordered array of ids or comma-separated id string |
||
|
|||
154 | * @param array $values optional key-value map to pre-seed model |
||
155 | */ |
||
156 | public function __construct(array $values = []) |
||
157 | { |
||
158 | // initialize the model |
||
159 | $this->init(); |
||
160 | |||
161 | $ids = []; |
||
162 | $this->hasId = true; |
||
163 | foreach (static::$ids as $name) { |
||
164 | $id = null; |
||
165 | if (array_key_exists($name, $values)) { |
||
166 | $idProperty = static::definition()->get($name); |
||
167 | $id = Type::cast($idProperty, $values[$name]); |
||
168 | } |
||
169 | |||
170 | $ids[$name] = $id; |
||
171 | $this->hasId = $this->hasId && $id; |
||
172 | } |
||
173 | |||
174 | $this->idValues = $ids; |
||
175 | |||
176 | // load any given values |
||
177 | if ($this->hasId && count($values) > count($ids)) { |
||
178 | $this->refreshWith($values); |
||
179 | } elseif (!$this->hasId) { |
||
180 | $this->_unsaved = $values; |
||
181 | } else { |
||
182 | $this->_values = $this->idValues; |
||
183 | } |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Performs initialization on this model. |
||
188 | */ |
||
189 | private function init() |
||
198 | |||
199 | /** |
||
200 | * The initialize() method is called once per model. This is a great |
||
201 | * place to install event listeners. Any methods on the model that have |
||
202 | * "autoInitialize" in the name will automatically be called. |
||
203 | */ |
||
204 | protected function initialize() |
||
205 | { |
||
206 | // Use reflection to automatically call any method here that has a name |
||
207 | // that starts with "autoInitialize". This is useful for traits to install listeners. |
||
208 | $methods = get_class_methods(static::class); |
||
209 | foreach ($methods as $method) { |
||
210 | if (0 === strpos($method, 'autoInitialize')) { |
||
211 | $this->$method(); |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Sets the driver for all models. |
||
218 | */ |
||
219 | public static function setDriver(DriverInterface $driver) |
||
220 | { |
||
221 | self::$driver = $driver; |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * Gets the driver for all models. |
||
226 | * |
||
227 | * @throws DriverMissingException when a driver has not been set yet |
||
228 | */ |
||
229 | public static function getDriver(): DriverInterface |
||
230 | { |
||
231 | if (!self::$driver) { |
||
232 | throw new DriverMissingException('A model driver has not been set yet.'); |
||
233 | } |
||
234 | |||
235 | return self::$driver; |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Clears the driver for all models. |
||
240 | */ |
||
241 | public static function clearDriver() |
||
242 | { |
||
243 | self::$driver = null; |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * Gets the name of the model, i.e. User. |
||
248 | */ |
||
249 | public static function modelName(): string |
||
250 | { |
||
251 | // strip namespacing |
||
252 | $paths = explode('\\', static::class); |
||
253 | |||
254 | return end($paths); |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * Gets the model ID. |
||
259 | * |
||
260 | * @return string|number|false ID |
||
261 | */ |
||
262 | public function id() |
||
263 | { |
||
264 | if (!$this->hasId) { |
||
265 | return false; |
||
266 | } |
||
267 | |||
268 | if (1 == count($this->idValues)) { |
||
269 | return reset($this->idValues); |
||
270 | } |
||
271 | |||
272 | $result = []; |
||
273 | foreach (static::$ids as $k) { |
||
274 | $result[] = $this->idValues[$k]; |
||
275 | } |
||
276 | |||
277 | return implode(',', $result); |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * Gets a key-value map of the model ID. |
||
282 | * |
||
283 | * @return array ID map |
||
284 | */ |
||
285 | public function ids(): array |
||
286 | { |
||
287 | return $this->idValues; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * Checks if the model has an identifier present. |
||
292 | * This does not indicate whether the model has been |
||
293 | * persisted to the database or loaded from the database. |
||
294 | */ |
||
295 | public function hasId(): bool |
||
296 | { |
||
297 | return $this->hasId; |
||
298 | } |
||
299 | |||
300 | ///////////////////////////// |
||
301 | // Magic Methods |
||
302 | ///////////////////////////// |
||
303 | |||
304 | /** |
||
305 | * Converts the model into a string. |
||
306 | * |
||
307 | * @return string |
||
308 | */ |
||
309 | public function __toString() |
||
310 | { |
||
311 | $values = array_merge($this->_values, $this->_unsaved, $this->idValues); |
||
312 | ksort($values); |
||
313 | |||
314 | return static::class.'('.json_encode($values, JSON_PRETTY_PRINT).')'; |
||
315 | } |
||
316 | |||
317 | /** |
||
318 | * Shortcut to a get() call for a given property. |
||
319 | * |
||
320 | * @param string $name |
||
321 | * |
||
322 | * @return mixed |
||
323 | */ |
||
324 | public function __get($name) |
||
325 | { |
||
326 | $result = $this->get([$name]); |
||
327 | |||
328 | return reset($result); |
||
329 | } |
||
330 | |||
331 | /** |
||
332 | * Sets an unsaved value. |
||
333 | * |
||
334 | * @param string $name |
||
335 | * @param mixed $value |
||
336 | */ |
||
337 | public function __set($name, $value) |
||
338 | { |
||
339 | // if changing property, remove relation model |
||
340 | if (isset($this->_relationships[$name])) { |
||
341 | unset($this->_relationships[$name]); |
||
342 | } |
||
343 | |||
344 | // call any mutators |
||
345 | $mutator = self::getMutator($name); |
||
346 | if ($mutator) { |
||
347 | $this->_unsaved[$name] = $this->$mutator($value); |
||
348 | } else { |
||
349 | $this->_unsaved[$name] = $value; |
||
350 | } |
||
351 | |||
352 | // set local ID property on belongs_to relationship |
||
353 | if (static::definition()->has($name)) { |
||
354 | $property = static::definition()->get($name); |
||
355 | if (Relationship::BELONGS_TO == $property->getRelationshipType() && !$property->isPersisted()) { |
||
356 | if ($value instanceof self) { |
||
357 | $this->_unsaved[$property->getLocalKey()] = $value->{$property->getForeignKey()}; |
||
358 | } elseif (null === $value) { |
||
359 | $this->_unsaved[$property->getLocalKey()] = null; |
||
360 | } else { |
||
361 | throw new ModelException('The value set on the "'.$name.'" property must be a model or null.'); |
||
362 | } |
||
363 | } |
||
364 | } |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * Checks if an unsaved value or property exists by this name. |
||
369 | * |
||
370 | * @param string $name |
||
371 | * |
||
372 | * @return bool |
||
373 | */ |
||
374 | public function __isset($name) |
||
382 | |||
383 | /** |
||
384 | * Unsets an unsaved value. |
||
385 | * |
||
386 | * @param string $name |
||
387 | */ |
||
388 | public function __unset($name) |
||
399 | |||
400 | ///////////////////////////// |
||
401 | // ArrayAccess Interface |
||
402 | ///////////////////////////// |
||
403 | |||
404 | public function offsetExists($offset) |
||
408 | |||
409 | public function offsetGet($offset) |
||
413 | |||
414 | public function offsetSet($offset, $value) |
||
418 | |||
419 | public function offsetUnset($offset) |
||
423 | |||
424 | public static function __callStatic($name, $parameters) |
||
431 | |||
432 | ///////////////////////////// |
||
433 | // Property Definitions |
||
434 | ///////////////////////////// |
||
435 | |||
436 | /** |
||
437 | * Gets the model definition. |
||
438 | */ |
||
439 | public static function definition(): Definition |
||
443 | |||
444 | /** |
||
445 | * The buildDefinition() method is called once per model. It's used |
||
446 | * to generate the model definition. This is a great place to add any |
||
447 | * dynamic model properties. |
||
448 | */ |
||
449 | public static function buildDefinition(): Definition |
||
450 | { |
||
451 | // Use reflection to automatically call any method on the model that has a name |
||
452 | // that starts with "buildDefinition". This is useful for traits to add properties. |
||
453 | $methods = get_class_methods(static::class); |
||
454 | foreach ($methods as $method) { |
||
455 | if (0 === strpos($method, 'autoDefinition')) { |
||
462 | |||
463 | /** |
||
464 | * Gets the names of the model ID properties. |
||
465 | */ |
||
466 | public static function getIDProperties(): array |
||
470 | |||
471 | /** |
||
472 | * Gets the mutator method name for a given property name. |
||
473 | * Looks for methods in the form of `setPropertyValue`. |
||
474 | * i.e. the mutator for `last_name` would be `setLastNameValue`. |
||
475 | * |
||
476 | * @param string $property property |
||
477 | * |
||
478 | * @return string|null method name if it exists |
||
479 | */ |
||
480 | public static function getMutator(string $property): ?string |
||
498 | |||
499 | /** |
||
500 | * Gets the accessor method name for a given property name. |
||
501 | * Looks for methods in the form of `getPropertyValue`. |
||
502 | * i.e. the accessor for `last_name` would be `getLastNameValue`. |
||
503 | * |
||
504 | * @param string $property property |
||
505 | * |
||
506 | * @return string|null method name if it exists |
||
507 | */ |
||
508 | public static function getAccessor(string $property): ?string |
||
526 | |||
527 | ///////////////////////////// |
||
528 | // CRUD Operations |
||
529 | ///////////////////////////// |
||
530 | |||
531 | /** |
||
532 | * Gets the table name for storing this model. |
||
533 | */ |
||
534 | public function getTablename(): string |
||
544 | |||
545 | /** |
||
546 | * Gets the ID of the connection in the connection manager |
||
547 | * that stores this model. |
||
548 | */ |
||
549 | public function getConnection(): ?string |
||
553 | |||
554 | protected function usesTransactions(): bool |
||
558 | |||
559 | /** |
||
560 | * Saves the model. |
||
561 | * |
||
562 | * @return bool true when the operation was successful |
||
563 | */ |
||
564 | public function save(): bool |
||
572 | |||
573 | /** |
||
574 | * Saves the model. Throws an exception when the operation fails. |
||
575 | * |
||
576 | * @throws ModelException when the model cannot be saved |
||
577 | */ |
||
578 | public function saveOrFail() |
||
589 | |||
590 | /** |
||
591 | * Creates a new model. |
||
592 | * |
||
593 | * @param array $data optional key-value properties to set |
||
594 | * |
||
595 | * @return bool true when the operation was successful |
||
596 | * |
||
597 | * @throws BadMethodCallException when called on an existing model |
||
598 | */ |
||
599 | public function create(array $data = []): bool |
||
723 | |||
724 | /** |
||
725 | * Ignores unsaved values when fetching the next value. |
||
726 | * |
||
727 | * @return $this |
||
728 | */ |
||
729 | public function ignoreUnsaved() |
||
735 | |||
736 | /** |
||
737 | * Fetches property values from the model. |
||
738 | * |
||
739 | * This method looks up values in this order: |
||
740 | * IDs, local cache, unsaved values, storage layer, defaults |
||
741 | * |
||
742 | * @param array $properties list of property names to fetch values of |
||
743 | */ |
||
744 | public function get(array $properties): array |
||
765 | |||
766 | /** |
||
767 | * Loads the model from the database if needed. |
||
768 | */ |
||
769 | private function loadIfNeeded(array $properties, bool $ignoreUnsaved): void |
||
786 | |||
787 | /** |
||
788 | * Gets a property value from the model. |
||
789 | * |
||
790 | * Values are looked up in this order: |
||
791 | * 1. unsaved values |
||
792 | * 2. local values |
||
793 | * 3. default value |
||
794 | * 4. null |
||
795 | * |
||
796 | * @return mixed |
||
797 | */ |
||
798 | private function getValue(string $name, bool $ignoreUnsaved) |
||
821 | |||
822 | /** |
||
823 | * Populates a newly created model with its ID. |
||
824 | */ |
||
825 | private function getNewId() |
||
847 | |||
848 | protected function getMassAssignmentWhitelist(): ?array |
||
857 | |||
858 | protected function getMassAssignmentBlacklist(): ?array |
||
867 | |||
868 | /** |
||
869 | * Sets a collection values on the model from an untrusted input. |
||
870 | * |
||
871 | * @param array $values |
||
872 | * |
||
873 | * @throws MassAssignmentException when assigning a value that is protected or not whitelisted |
||
874 | * |
||
875 | * @return $this |
||
876 | */ |
||
877 | public function setValues($values) |
||
908 | |||
909 | /** |
||
910 | * Converts the model to an array. |
||
911 | */ |
||
912 | public function toArray(): array |
||
959 | |||
960 | /** |
||
961 | * Checks if the unsaved value for a property is present and |
||
962 | * is different from the original value. |
||
963 | * |
||
964 | * @property string|null $name |
||
965 | * @property bool $hasChanged when true, checks if the unsaved value is different from the saved value |
||
966 | */ |
||
967 | public function dirty(?string $name = null, bool $hasChanged = false): bool |
||
987 | |||
988 | /** |
||
989 | * Updates the model. |
||
990 | * |
||
991 | * @param array $data optional key-value properties to set |
||
992 | * |
||
993 | * @return bool true when the operation was successful |
||
994 | * |
||
995 | * @throws BadMethodCallException when not called on an existing model |
||
996 | */ |
||
997 | public function set(array $data = []): bool |
||
1096 | |||
1097 | /** |
||
1098 | * Delete the model. |
||
1099 | * |
||
1100 | * @return bool true when the operation was successful |
||
1101 | */ |
||
1102 | public function delete(): bool |
||
1152 | |||
1153 | /** |
||
1154 | * Restores a soft-deleted model. |
||
1155 | */ |
||
1156 | public function restore(): bool |
||
1190 | |||
1191 | /** |
||
1192 | * Checks if the model has been deleted. |
||
1193 | */ |
||
1194 | public function isDeleted(): bool |
||
1202 | |||
1203 | ///////////////////////////// |
||
1204 | // Queries |
||
1205 | ///////////////////////////// |
||
1206 | |||
1207 | /** |
||
1208 | * Generates a new query instance. |
||
1209 | */ |
||
1210 | public static function query(): Query |
||
1225 | |||
1226 | /** |
||
1227 | * Generates a new query instance that includes soft-deleted models. |
||
1228 | */ |
||
1229 | public static function withDeleted(): Query |
||
1238 | |||
1239 | /** |
||
1240 | * Finds a single instance of a model given it's ID. |
||
1241 | * |
||
1242 | * @param mixed $id |
||
1243 | * |
||
1244 | * @return static|null |
||
1245 | */ |
||
1246 | public static function find($id): ?self |
||
1263 | |||
1264 | /** |
||
1265 | * Finds a single instance of a model given it's ID or throws an exception. |
||
1266 | * |
||
1267 | * @param mixed $id |
||
1268 | * |
||
1269 | * @return static |
||
1270 | * |
||
1271 | * @throws ModelNotFoundException when a model could not be found |
||
1272 | */ |
||
1273 | public static function findOrFail($id): self |
||
1282 | |||
1283 | /** |
||
1284 | * Tells if this model instance has been persisted to the data layer. |
||
1285 | * |
||
1286 | * NOTE: this does not actually perform a check with the data layer |
||
1287 | */ |
||
1288 | public function persisted(): bool |
||
1292 | |||
1293 | /** |
||
1294 | * Loads the model from the storage layer. |
||
1295 | * |
||
1296 | * @return $this |
||
1297 | */ |
||
1298 | public function refresh() |
||
1322 | |||
1323 | /** |
||
1324 | * Loads values into the model. |
||
1325 | * |
||
1326 | * @param array $values values |
||
1327 | * |
||
1328 | * @return $this |
||
1329 | */ |
||
1330 | public function refreshWith(array $values) |
||
1338 | |||
1339 | /** |
||
1340 | * Clears the cache for this model. |
||
1341 | * |
||
1342 | * @return $this |
||
1343 | */ |
||
1344 | public function clearCache() |
||
1353 | |||
1354 | ///////////////////////////// |
||
1355 | // Relationships |
||
1356 | ///////////////////////////// |
||
1357 | |||
1358 | /** |
||
1359 | * Gets the relationship manager for a property. |
||
1360 | * |
||
1361 | * @throws InvalidArgumentException when the relationship manager cannot be created |
||
1362 | */ |
||
1363 | private function getRelationship(Property $property): AbstractRelation |
||
1372 | |||
1373 | /** |
||
1374 | * Saves any unsaved models attached through a relationship. This will only |
||
1375 | * save attached models that have not been saved yet. |
||
1376 | */ |
||
1377 | private function saveRelationships(bool $usesTransactions): bool |
||
1411 | |||
1412 | /** |
||
1413 | * This hydrates an individual property in the model. It can be a |
||
1414 | * scalar value or relationship. |
||
1415 | * |
||
1416 | * @internal |
||
1417 | * |
||
1418 | * @param $value |
||
1419 | */ |
||
1420 | public function hydrateValue(string $name, $value): void |
||
1429 | |||
1430 | /** |
||
1431 | * @deprecated |
||
1432 | * |
||
1433 | * Gets the model(s) for a relationship |
||
1434 | * |
||
1435 | * @param string $k property |
||
1436 | * |
||
1437 | * @throws InvalidArgumentException when the relationship manager cannot be created |
||
1438 | * |
||
1439 | * @return Model|array|null |
||
1440 | */ |
||
1441 | public function relation(string $k) |
||
1450 | |||
1451 | /** |
||
1452 | * @deprecated |
||
1453 | * |
||
1454 | * Sets the model for a one-to-one relationship (has-one or belongs-to) |
||
1455 | * |
||
1456 | * @return $this |
||
1457 | */ |
||
1458 | public function setRelation(string $k, Model $model) |
||
1465 | |||
1466 | /** |
||
1467 | * @deprecated |
||
1468 | * |
||
1469 | * Sets the model for a one-to-many relationship |
||
1470 | * |
||
1471 | * @return $this |
||
1472 | */ |
||
1473 | public function setRelationCollection(string $k, iterable $models) |
||
1479 | |||
1480 | /** |
||
1481 | * @deprecated |
||
1482 | * |
||
1483 | * Sets the model for a one-to-one relationship (has-one or belongs-to) as null |
||
1484 | * |
||
1485 | * @return $this |
||
1486 | */ |
||
1487 | public function clearRelation(string $k) |
||
1494 | |||
1495 | ///////////////////////////// |
||
1496 | // Events |
||
1497 | ///////////////////////////// |
||
1498 | |||
1499 | /** |
||
1500 | * Adds a listener to the model.creating and model.updating events. |
||
1501 | */ |
||
1502 | public static function saving(callable $listener, int $priority = 0): void |
||
1507 | |||
1508 | /** |
||
1509 | * Adds a listener to the model.created and model.updated events. |
||
1510 | */ |
||
1511 | public static function saved(callable $listener, int $priority = 0): void |
||
1516 | |||
1517 | /** |
||
1518 | * Adds a listener to the model.creating, model.updating, and model.deleting events. |
||
1519 | */ |
||
1520 | public static function beforePersist(callable $listener, int $priority = 0): void |
||
1526 | |||
1527 | /** |
||
1528 | * Adds a listener to the model.created, model.updated, and model.deleted events. |
||
1529 | */ |
||
1530 | public static function afterPersist(callable $listener, int $priority = 0): void |
||
1536 | |||
1537 | /** |
||
1538 | * Adds a listener to the model.creating event. |
||
1539 | */ |
||
1540 | public static function creating(callable $listener, int $priority = 0): void |
||
1544 | |||
1545 | /** |
||
1546 | * Adds a listener to the model.created event. |
||
1547 | */ |
||
1548 | public static function created(callable $listener, int $priority = 0): void |
||
1552 | |||
1553 | /** |
||
1554 | * Adds a listener to the model.updating event. |
||
1555 | */ |
||
1556 | public static function updating(callable $listener, int $priority = 0): void |
||
1560 | |||
1561 | /** |
||
1562 | * Adds a listener to the model.updated event. |
||
1563 | */ |
||
1564 | public static function updated(callable $listener, int $priority = 0): void |
||
1568 | |||
1569 | /** |
||
1570 | * Adds a listener to the model.deleting event. |
||
1571 | */ |
||
1572 | public static function deleting(callable $listener, int $priority = 0): void |
||
1576 | |||
1577 | /** |
||
1578 | * Adds a listener to the model.deleted event. |
||
1579 | */ |
||
1580 | public static function deleted(callable $listener, int $priority = 0): void |
||
1584 | |||
1585 | ///////////////////////////// |
||
1586 | // Validation |
||
1587 | ///////////////////////////// |
||
1588 | |||
1589 | /** |
||
1590 | * Gets the error stack for this model. |
||
1591 | */ |
||
1592 | public function getErrors(): Errors |
||
1600 | |||
1601 | /** |
||
1602 | * Checks if the model in its current state is valid. |
||
1603 | */ |
||
1604 | public function valid(): bool |
||
1618 | } |
||
1619 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.