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 EntityMap 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 EntityMap, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class EntityMap |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * The mapping driver to use with this entity. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $driver = 'illuminate'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The Database Connection name for the model. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $connection; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The table associated with the entity. |
||
| 44 | * |
||
| 45 | * @var string|null |
||
| 46 | */ |
||
| 47 | protected $table = null; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The primary key for the model. |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $primaryKey = 'id'; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Name of the entity's array property that should |
||
| 58 | * contain the attributes. |
||
| 59 | * If set to null, analogue will only hydrate object's properties. |
||
| 60 | * |
||
| 61 | * @var string|null |
||
| 62 | */ |
||
| 63 | protected $arrayName = 'attributes'; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Array containing the list of database columns to be mapped |
||
| 67 | * in the attributes array of the entity. |
||
| 68 | * |
||
| 69 | * @var array |
||
| 70 | */ |
||
| 71 | protected $attributes = []; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Array containing the list of database columns to be mapped |
||
| 75 | * to the entity's class properties. |
||
| 76 | * |
||
| 77 | * @var array |
||
| 78 | */ |
||
| 79 | protected $properties = []; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The Custom Domain Class to use with this mapping. |
||
| 83 | * |
||
| 84 | * @var string|null |
||
| 85 | */ |
||
| 86 | protected $class = null; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Embedded Value Objects. |
||
| 90 | * |
||
| 91 | * @var array |
||
| 92 | */ |
||
| 93 | protected $embeddables = []; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Determine the relationships method used on the entity. |
||
| 97 | * If not set, mapper will autodetect them. |
||
| 98 | * |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | private $relationships = []; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Relationships that should be treated as collection. |
||
| 105 | * |
||
| 106 | * @var array |
||
| 107 | */ |
||
| 108 | private $manyRelations = []; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Relationships that should be treated as single entity. |
||
| 112 | * |
||
| 113 | * @var array |
||
| 114 | */ |
||
| 115 | private $singleRelations = []; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Relationships for which the key is stored in the Entity itself. |
||
| 119 | * |
||
| 120 | * @var array |
||
| 121 | */ |
||
| 122 | private $localRelations = []; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * List of local keys associated to local relation methods. |
||
| 126 | * |
||
| 127 | * @var array |
||
| 128 | */ |
||
| 129 | private $localForeignKeys = []; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Relationships for which the key is stored in the Related Entity. |
||
| 133 | * |
||
| 134 | * @var array |
||
| 135 | */ |
||
| 136 | private $foreignRelations = []; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Relationships which use a pivot record. |
||
| 140 | * |
||
| 141 | * @var array |
||
| 142 | */ |
||
| 143 | private $pivotRelations = []; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Polymorphic relationships. |
||
| 147 | * |
||
| 148 | * @var array |
||
| 149 | */ |
||
| 150 | private $polymorphicRelations = []; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Dynamic relationships. |
||
| 154 | * |
||
| 155 | * @var array |
||
| 156 | */ |
||
| 157 | private $dynamicRelationships = []; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Targetted class for the relationship method. value is set to `null` for |
||
| 161 | * polymorphic relations. |
||
| 162 | * |
||
| 163 | * @var array |
||
| 164 | */ |
||
| 165 | private $relatedClasses = []; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Some relation methods like embedded objects, or HasOne and MorphOne, |
||
| 169 | * will never have a proxy loaded on them. |
||
| 170 | * |
||
| 171 | * @var array |
||
| 172 | */ |
||
| 173 | private $nonProxyRelationships = []; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Relation methods that are embedded objects. |
||
| 177 | * |
||
| 178 | * @var array |
||
| 179 | */ |
||
| 180 | private $embeddedRelations = []; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * The number of models to return for pagination. |
||
| 184 | * |
||
| 185 | * @var int |
||
| 186 | */ |
||
| 187 | protected $perPage = 15; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * The relations to eager load on every query. |
||
| 191 | * |
||
| 192 | * @var array |
||
| 193 | */ |
||
| 194 | protected $with = []; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * The class name to be used in polymorphic relations. |
||
| 198 | * |
||
| 199 | * @var string |
||
| 200 | */ |
||
| 201 | protected $morphClass; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Sequence name, to be used with postgreSql |
||
| 205 | * defaults to %table_name%_id_seq. |
||
| 206 | * |
||
| 207 | * @var string|null |
||
| 208 | */ |
||
| 209 | protected $sequence = null; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Indicates if the entity should be timestamped. |
||
| 213 | * |
||
| 214 | * @var bool |
||
| 215 | */ |
||
| 216 | public $timestamps = false; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * The name of the "created at" column. |
||
| 220 | * |
||
| 221 | * @var string |
||
| 222 | */ |
||
| 223 | protected $createdAtColumn = 'created_at'; |
||
| 224 | |||
| 225 | /** |
||
| 226 | * The name of the "updated at" column. |
||
| 227 | * |
||
| 228 | * @var string |
||
| 229 | */ |
||
| 230 | protected $updatedAtColumn = 'updated_at'; |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Indicates if the entity uses softdeletes. |
||
| 234 | * |
||
| 235 | * @var bool |
||
| 236 | */ |
||
| 237 | public $softDeletes = false; |
||
| 238 | |||
| 239 | /** |
||
| 240 | * The name of the "deleted at" column. |
||
| 241 | * |
||
| 242 | * @var string |
||
| 243 | */ |
||
| 244 | protected $deletedAtColumn = 'deleted_at'; |
||
| 245 | |||
| 246 | /** |
||
| 247 | * The date format to use with the current database connection. |
||
| 248 | * |
||
| 249 | * @var string |
||
| 250 | */ |
||
| 251 | protected $dateFormat; |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Set this property to true if the entity should be instantiated |
||
| 255 | * using the IoC Container. |
||
| 256 | * |
||
| 257 | * @var bool |
||
| 258 | */ |
||
| 259 | protected $dependencyInjection = false; |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Set the usage of inheritance, possible values are : |
||
| 263 | * "single_table" |
||
| 264 | * null. |
||
| 265 | * |
||
| 266 | * @var string | null |
||
| 267 | */ |
||
| 268 | protected $inheritanceType = null; |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Discriminator column name. |
||
| 272 | * |
||
| 273 | * @var string |
||
| 274 | */ |
||
| 275 | protected $discriminatorColumn = 'type'; |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Allow using a string to define which entity type should be instantiated. |
||
| 279 | * If not set, analogue will uses entity's FQDN. |
||
| 280 | * |
||
| 281 | * @var array |
||
| 282 | */ |
||
| 283 | protected $discriminatorColumnMap = []; |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Return Domain class attributes, useful when mapping to a Plain PHP Object. |
||
| 287 | * |
||
| 288 | * @return array |
||
| 289 | */ |
||
| 290 | public function getAttributes() : array |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Set the domain class attributes. |
||
| 297 | * |
||
| 298 | * @param array $attributeNames |
||
| 299 | */ |
||
| 300 | public function setAttributes(array $attributeNames) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Return true if the Entity has an 'attributes' array property. |
||
| 307 | * |
||
| 308 | * @return bool |
||
| 309 | */ |
||
| 310 | public function usesAttributesArray() : bool |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Return the name of the Entity's attributes property. |
||
| 324 | * |
||
| 325 | * @return string|null |
||
| 326 | */ |
||
| 327 | public function getAttributesArrayName() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Get all the attribute names for the class, including relationships, embeddables and primary key. |
||
| 334 | * |
||
| 335 | * @return array |
||
| 336 | */ |
||
| 337 | public function getCompiledAttributes() : array |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Set the date format to use with the current database connection. |
||
| 352 | * |
||
| 353 | * @param string $format |
||
| 354 | */ |
||
| 355 | public function setDateFormat($format) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Get the date format to use with the current database connection. |
||
| 362 | * |
||
| 363 | * @return string |
||
| 364 | */ |
||
| 365 | public function getDateFormat() : string |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Set the Driver for this mapping. |
||
| 372 | * |
||
| 373 | * @param string $driver |
||
| 374 | */ |
||
| 375 | public function setDriver($driver) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Get the Driver for this mapping. |
||
| 382 | * |
||
| 383 | * @return string |
||
| 384 | */ |
||
| 385 | public function getDriver() : string |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Set the db connection to use on the table. |
||
| 392 | * |
||
| 393 | * @param $connection |
||
| 394 | */ |
||
| 395 | public function setConnection($connection) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Get the Database connection the Entity is stored on. |
||
| 402 | * |
||
| 403 | * @return string | null |
||
| 404 | */ |
||
| 405 | public function getConnection() |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Get the table associated with the entity. |
||
| 412 | * |
||
| 413 | * @return string |
||
| 414 | */ |
||
| 415 | public function getTable() : string |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Set the database table name. |
||
| 426 | * |
||
| 427 | * @param string $table |
||
| 428 | */ |
||
| 429 | public function setTable($table) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Get the pgSql sequence name. |
||
| 436 | * |
||
| 437 | * @return string |
||
| 438 | */ |
||
| 439 | public function getSequence() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Get the custom entity class. |
||
| 450 | * |
||
| 451 | * @return string namespaced class name |
||
| 452 | */ |
||
| 453 | public function getClass() : string |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Set the custom entity class. |
||
| 460 | * |
||
| 461 | * @param string $class namespaced class name |
||
| 462 | */ |
||
| 463 | public function setClass($class) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Get the embedded Value Objects. |
||
| 470 | * |
||
| 471 | * @return array |
||
| 472 | */ |
||
| 473 | public function getEmbeddables() : array |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Return attributes that should be mapped to class properties. |
||
| 480 | * |
||
| 481 | * @return array |
||
| 482 | */ |
||
| 483 | public function getProperties() : array |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Return the array property in which will be mapped all attributes |
||
| 490 | * that are not mapped to class properties. |
||
| 491 | * |
||
| 492 | * @return string |
||
| 493 | */ |
||
| 494 | public function getAttributesPropertyName() : string |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Set the embedded Value Objects. |
||
| 500 | * |
||
| 501 | * @param array $embeddables |
||
| 502 | */ |
||
| 503 | public function setEmbeddables(array $embeddables) |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Get the relationships to map on a custom domain |
||
| 510 | * class. |
||
| 511 | * |
||
| 512 | * @return array |
||
| 513 | */ |
||
| 514 | public function getRelationships() : array |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Return all relationships that are not embedded objects. |
||
| 521 | * |
||
| 522 | * @return array |
||
| 523 | */ |
||
| 524 | public function getNonEmbeddedRelationships() : array |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Get the relationships that will not have a proxy |
||
| 531 | * set on them. |
||
| 532 | * |
||
| 533 | * @return array |
||
| 534 | */ |
||
| 535 | public function getRelationshipsWithoutProxy() : array |
||
| 539 | |||
| 540 | /** |
||
| 541 | * Relationships of the Entity type. |
||
| 542 | * |
||
| 543 | * @return array |
||
| 544 | */ |
||
| 545 | public function getSingleRelationships() : array |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Relationships of type Collection. |
||
| 552 | * |
||
| 553 | * @return array |
||
| 554 | */ |
||
| 555 | public function getManyRelationships() : array |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Relationships with foreign key in the mapped entity record. |
||
| 562 | * |
||
| 563 | * @return array |
||
| 564 | */ |
||
| 565 | public function getLocalRelationships() : array |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Return the local keys associated to the relationship. |
||
| 572 | * |
||
| 573 | * @param string $relation |
||
| 574 | * |
||
| 575 | * @return string | array | null |
||
| 576 | */ |
||
| 577 | public function getLocalKeys($relation) |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Relationships with foreign key in the related Entity record. |
||
| 584 | * |
||
| 585 | * @return array |
||
| 586 | */ |
||
| 587 | public function getForeignRelationships() : array |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Relationships which keys are stored in a pivot record. |
||
| 594 | * |
||
| 595 | * @return array |
||
| 596 | */ |
||
| 597 | public function getPivotRelationships() : array |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Return an array containing all embedded relationships. |
||
| 604 | * |
||
| 605 | * @return array |
||
| 606 | */ |
||
| 607 | public function getEmbeddedRelationships() : array |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Return true if the relationship method is polymorphic. |
||
| 614 | * |
||
| 615 | * @param string $relation |
||
| 616 | * |
||
| 617 | * @return bool |
||
| 618 | */ |
||
| 619 | public function isPolymorphic($relation) : bool |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Get the targetted type for a relationship. Return null if polymorphic. |
||
| 626 | * |
||
| 627 | * @param string $relation |
||
| 628 | * |
||
| 629 | * @return string | null |
||
| 630 | */ |
||
| 631 | public function getTargettedClass($relation) |
||
| 639 | |||
| 640 | /** |
||
| 641 | * Add a Dynamic Relationship method at runtime. This has to be done |
||
| 642 | * by hooking the 'initializing' event, before entityMap is initialized. |
||
| 643 | * |
||
| 644 | * @param string $name Relation name |
||
| 645 | * @param \Closure $relationship |
||
| 646 | * |
||
| 647 | * @return void |
||
| 648 | */ |
||
| 649 | public function addRelationshipMethod($name, \Closure $relationship) |
||
| 653 | |||
| 654 | /** |
||
| 655 | * Get the dynamic relationship method names. |
||
| 656 | * |
||
| 657 | * @return array |
||
| 658 | */ |
||
| 659 | public function getDynamicRelationships() : array |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Get the relationships that have to be eager loaded |
||
| 666 | * on each request. |
||
| 667 | * |
||
| 668 | * @return array |
||
| 669 | */ |
||
| 670 | public function getEagerloadedRelationships() : array |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Get the primary key attribute for the entity. |
||
| 677 | * |
||
| 678 | * @return string |
||
| 679 | */ |
||
| 680 | public function getKeyName() : string |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Set the primary key for the entity. |
||
| 687 | * |
||
| 688 | * @param $key |
||
| 689 | * |
||
| 690 | * @return void |
||
| 691 | */ |
||
| 692 | public function setKeyName($key) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Get the table qualified key name. |
||
| 699 | * |
||
| 700 | * @return string |
||
| 701 | */ |
||
| 702 | public function getQualifiedKeyName() : string |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Get the number of models to return per page. |
||
| 709 | * |
||
| 710 | * @return int |
||
| 711 | */ |
||
| 712 | public function getPerPage() : int |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Set the number of models to return per page. |
||
| 719 | * |
||
| 720 | * @param int $perPage |
||
| 721 | * |
||
| 722 | * @return void |
||
| 723 | */ |
||
| 724 | public function setPerPage($perPage) |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Determine if the entity uses get. |
||
| 731 | * |
||
| 732 | * @return bool |
||
| 733 | */ |
||
| 734 | public function usesTimestamps() : bool |
||
| 738 | |||
| 739 | /** |
||
| 740 | * Determine if the entity uses soft deletes. |
||
| 741 | * |
||
| 742 | * @return bool |
||
| 743 | */ |
||
| 744 | public function usesSoftDeletes() : bool |
||
| 748 | |||
| 749 | /** |
||
| 750 | * Get the 'created_at' column name. |
||
| 751 | * |
||
| 752 | * @return string |
||
| 753 | */ |
||
| 754 | public function getCreatedAtColumn() : string |
||
| 758 | |||
| 759 | /** |
||
| 760 | * Get the 'updated_at' column name. |
||
| 761 | * |
||
| 762 | * @return string |
||
| 763 | */ |
||
| 764 | public function getUpdatedAtColumn() : string |
||
| 768 | |||
| 769 | /** |
||
| 770 | * Get the deleted_at column. |
||
| 771 | * |
||
| 772 | * @return string |
||
| 773 | */ |
||
| 774 | public function getQualifiedDeletedAtColumn() : string |
||
| 778 | |||
| 779 | /** |
||
| 780 | * Get the default foreign key name for the model. |
||
| 781 | * |
||
| 782 | * @return string |
||
| 783 | */ |
||
| 784 | public function getForeignKey() : string |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Return the inheritance type used by the entity. |
||
| 791 | * |
||
| 792 | * @return string|null |
||
| 793 | */ |
||
| 794 | public function getInheritanceType() |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Return the discriminator column name on the entity that's |
||
| 801 | * used for table inheritance. |
||
| 802 | * |
||
| 803 | * @return string |
||
| 804 | */ |
||
| 805 | public function getDiscriminatorColumn() : string |
||
| 809 | |||
| 810 | /** |
||
| 811 | * Return the mapping of discriminator column values to |
||
| 812 | * entity class names that are used for table inheritance. |
||
| 813 | * |
||
| 814 | * @return array |
||
| 815 | */ |
||
| 816 | public function getDiscriminatorColumnMap() : array |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Return true if the entity should be instanciated using |
||
| 823 | * the IoC Container. |
||
| 824 | * |
||
| 825 | * @return bool |
||
| 826 | */ |
||
| 827 | public function useDependencyInjection() : bool |
||
| 831 | |||
| 832 | /** |
||
| 833 | * Add a single relation method name once. |
||
| 834 | * |
||
| 835 | * @param string $relation |
||
| 836 | */ |
||
| 837 | protected function addSingleRelation($relation) |
||
| 843 | |||
| 844 | /** |
||
| 845 | * Add a foreign relation method name once. |
||
| 846 | * |
||
| 847 | * @param string $relation |
||
| 848 | */ |
||
| 849 | protected function addForeignRelation($relation) |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Add a polymorphic relation method name once. |
||
| 858 | * |
||
| 859 | * @param string $relation |
||
| 860 | */ |
||
| 861 | protected function addPolymorphicRelation($relation) |
||
| 867 | |||
| 868 | /** |
||
| 869 | * Add a non proxy relation method name once. |
||
| 870 | * |
||
| 871 | * @param string $relation |
||
| 872 | */ |
||
| 873 | protected function addNonProxyRelation($relation) |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Add a local relation method name once. |
||
| 882 | * |
||
| 883 | * @param string $relation |
||
| 884 | */ |
||
| 885 | protected function addLocalRelation($relation) |
||
| 891 | |||
| 892 | /** |
||
| 893 | * Add a many relation method name once. |
||
| 894 | * |
||
| 895 | * @param string $relation |
||
| 896 | */ |
||
| 897 | protected function addManyRelation($relation) |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Add a pivot relation method name once. |
||
| 906 | * |
||
| 907 | * @param string $relation |
||
| 908 | */ |
||
| 909 | protected function addPivotRelation($relation) |
||
| 915 | |||
| 916 | /** |
||
| 917 | * Add an embedded relation. |
||
| 918 | * |
||
| 919 | * @param string $relation |
||
| 920 | */ |
||
| 921 | protected function addEmbeddedRelation($relation) |
||
| 927 | |||
| 928 | /** |
||
| 929 | * Define an Embedded Object. |
||
| 930 | * |
||
| 931 | * @param mixed $entity |
||
|
|
|||
| 932 | * @param string $related |
||
| 933 | * |
||
| 934 | * @return EmbedsOne |
||
| 935 | */ |
||
| 936 | View Code Duplication | public function embedsOne($parent, string $relatedClass, $relation = null) : EmbedsOne |
|
| 948 | |||
| 949 | /** |
||
| 950 | * Define an Embedded Collection. |
||
| 951 | * |
||
| 952 | * @param mixed $entity |
||
| 953 | * @param string $related |
||
| 954 | * |
||
| 955 | * @return EmbedsOne |
||
| 956 | */ |
||
| 957 | View Code Duplication | public function embedsMany($parent, string $relatedClass, $relation = null) : EmbedsMany |
|
| 969 | |||
| 970 | /** |
||
| 971 | * Define a one-to-one relationship. |
||
| 972 | * |
||
| 973 | * @param mixed $entity |
||
| 974 | * @param string $related entity class |
||
| 975 | * @param string $foreignKey |
||
| 976 | * @param string $localKey |
||
| 977 | * |
||
| 978 | * @throws MappingException |
||
| 979 | * |
||
| 980 | * @return \Analogue\ORM\Relationships\HasOne |
||
| 981 | */ |
||
| 982 | public function hasOne($entity, $related, $foreignKey = null, $localKey = null) |
||
| 1009 | |||
| 1010 | /** |
||
| 1011 | * Define a polymorphic one-to-one relationship. |
||
| 1012 | * |
||
| 1013 | * @param mixed $entity |
||
| 1014 | * @param string $related |
||
| 1015 | * @param string $name |
||
| 1016 | * @param string|null $type |
||
| 1017 | * @param string|null $id |
||
| 1018 | * @param string|null $localKey |
||
| 1019 | * |
||
| 1020 | * @throws MappingException |
||
| 1021 | * |
||
| 1022 | * @return \Analogue\ORM\Relationships\MorphOne |
||
| 1023 | */ |
||
| 1024 | public function morphOne($entity, $related, $name, $type = null, $id = null, $localKey = null) |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * Define an inverse one-to-one or many relationship. |
||
| 1054 | * |
||
| 1055 | * @param mixed $entity |
||
| 1056 | * @param string $related |
||
| 1057 | * @param string|null $foreignKey |
||
| 1058 | * @param string|null $otherKey |
||
| 1059 | * @param string|null $relation |
||
| 1060 | * |
||
| 1061 | * @throws MappingException |
||
| 1062 | * |
||
| 1063 | * @return \Analogue\ORM\Relationships\BelongsTo |
||
| 1064 | */ |
||
| 1065 | public function belongsTo($entity, $related, $foreignKey = null, $otherKey = null) |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Define a polymorphic, inverse one-to-one or many relationship. |
||
| 1093 | * |
||
| 1094 | * @param mixed $entity |
||
| 1095 | * @param string|null $name |
||
| 1096 | * @param string|null $type |
||
| 1097 | * @param string|null $id |
||
| 1098 | * |
||
| 1099 | * @throws MappingException |
||
| 1100 | * |
||
| 1101 | * @return \Analogue\ORM\Relationships\MorphTo |
||
| 1102 | */ |
||
| 1103 | public function morphTo($entity, $name = null, $type = null, $id = null) |
||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * Define a one-to-many relationship. |
||
| 1160 | * |
||
| 1161 | * @param mixed $entity |
||
| 1162 | * @param string $related |
||
| 1163 | * @param string|null $foreignKey |
||
| 1164 | * @param string|null $localKey |
||
| 1165 | * |
||
| 1166 | * @throws MappingException |
||
| 1167 | * |
||
| 1168 | * @return \Analogue\ORM\Relationships\HasMany |
||
| 1169 | */ |
||
| 1170 | public function hasMany($entity, $related, $foreignKey = null, $localKey = null) |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Define a has-many-through relationship. |
||
| 1191 | * |
||
| 1192 | * @param mixed $entity |
||
| 1193 | * @param string $related |
||
| 1194 | * @param string $through |
||
| 1195 | * @param string|null $firstKey |
||
| 1196 | * @param string|null $secondKey |
||
| 1197 | * |
||
| 1198 | * @throws MappingException |
||
| 1199 | * |
||
| 1200 | * @return \Analogue\ORM\Relationships\HasManyThrough |
||
| 1201 | */ |
||
| 1202 | View Code Duplication | public function hasManyThrough($entity, $related, $through, $firstKey = null, $secondKey = null) |
|
| 1223 | |||
| 1224 | /** |
||
| 1225 | * Define a polymorphic one-to-many relationship. |
||
| 1226 | * |
||
| 1227 | * @param mixed $entity |
||
| 1228 | * @param string $related |
||
| 1229 | * @param string $name |
||
| 1230 | * @param string|null $type |
||
| 1231 | * @param string|null $id |
||
| 1232 | * @param string|null $localKey |
||
| 1233 | * |
||
| 1234 | * @return \Analogue\ORM\Relationships\MorphMany |
||
| 1235 | */ |
||
| 1236 | View Code Duplication | public function morphMany($entity, $related, $name, $type = null, $id = null, $localKey = null) |
|
| 1259 | |||
| 1260 | /** |
||
| 1261 | * Define a many-to-many relationship. |
||
| 1262 | * |
||
| 1263 | * @param mixed $entity |
||
| 1264 | * @param string $relatedClass |
||
| 1265 | * @param string|null $table |
||
| 1266 | * @param string|null $foreignKey |
||
| 1267 | * @param string|null $otherKey |
||
| 1268 | * @param string|null $relation |
||
| 1269 | * |
||
| 1270 | * @throws MappingException |
||
| 1271 | * |
||
| 1272 | * @return \Analogue\ORM\Relationships\BelongsToMany |
||
| 1273 | */ |
||
| 1274 | public function belongsToMany($entity, $related, $table = null, $foreignKey = null, $otherKey = null) |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Define a polymorphic many-to-many relationship. |
||
| 1308 | * |
||
| 1309 | * @param mixed $entity |
||
| 1310 | * @param string $related |
||
| 1311 | * @param string $name |
||
| 1312 | * @param string|null $table |
||
| 1313 | * @param string|null $foreignKey |
||
| 1314 | * @param string|null $otherKey |
||
| 1315 | * @param bool $inverse |
||
| 1316 | * |
||
| 1317 | * @throws MappingException |
||
| 1318 | * |
||
| 1319 | * @return \Analogue\ORM\Relationships\MorphToMany |
||
| 1320 | */ |
||
| 1321 | public function morphToMany($entity, $related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false) |
||
| 1345 | |||
| 1346 | /** |
||
| 1347 | * Define a polymorphic, inverse many-to-many relationship. |
||
| 1348 | * |
||
| 1349 | * @param mixed $entity |
||
| 1350 | * @param string $related |
||
| 1351 | * @param string $name |
||
| 1352 | * @param string|null $table |
||
| 1353 | * @param string|null $foreignKey |
||
| 1354 | * @param string|null $otherKey |
||
| 1355 | * |
||
| 1356 | * @throws MappingException |
||
| 1357 | * |
||
| 1358 | * @return \Analogue\ORM\Relationships\MorphToMany |
||
| 1359 | */ |
||
| 1360 | public function morphedByMany($entity, $related, $name, $table = null, $foreignKey = null, $otherKey = null) |
||
| 1379 | |||
| 1380 | /** |
||
| 1381 | * Get the joining table name for a many-to-many relation. |
||
| 1382 | * |
||
| 1383 | * @param EntityMap $relatedMap |
||
| 1384 | * |
||
| 1385 | * @return string |
||
| 1386 | */ |
||
| 1387 | public function joiningTable($relatedMap) |
||
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Get the polymorphic relationship columns. |
||
| 1408 | * |
||
| 1409 | * @param string $name |
||
| 1410 | * @param string $type |
||
| 1411 | * @param string $id |
||
| 1412 | * |
||
| 1413 | * @return string[] |
||
| 1414 | */ |
||
| 1415 | protected function getMorphs($name, $type, $id) |
||
| 1423 | |||
| 1424 | /** |
||
| 1425 | * Get the class name for polymorphic relations. |
||
| 1426 | * |
||
| 1427 | * @return string |
||
| 1428 | */ |
||
| 1429 | public function getMorphClass() |
||
| 1435 | |||
| 1436 | /** |
||
| 1437 | * Create a new Entity Collection instance. |
||
| 1438 | * |
||
| 1439 | * @param array $entities |
||
| 1440 | * |
||
| 1441 | * @return \Analogue\ORM\EntityCollection |
||
| 1442 | */ |
||
| 1443 | public function newCollection(array $entities = []) |
||
| 1449 | |||
| 1450 | /** |
||
| 1451 | * Process EntityMap parsing at initialization time. |
||
| 1452 | * |
||
| 1453 | * @return void |
||
| 1454 | */ |
||
| 1455 | public function initialize() |
||
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Parse every relationships on the EntityMap and sort |
||
| 1472 | * them by type. |
||
| 1473 | * |
||
| 1474 | * @return void |
||
| 1475 | */ |
||
| 1476 | public function boot() |
||
| 1482 | |||
| 1483 | /** |
||
| 1484 | * Get Methods that has been added in the child class. |
||
| 1485 | * |
||
| 1486 | * @return array |
||
| 1487 | */ |
||
| 1488 | protected function getCustomMethods() |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Parse user's class methods for relationships. |
||
| 1499 | * |
||
| 1500 | * @param array $customMethods |
||
| 1501 | * |
||
| 1502 | * @return array |
||
| 1503 | */ |
||
| 1504 | protected function parseMethodsForRelationship(array $customMethods) |
||
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Sort Relationships methods by type. |
||
| 1532 | * |
||
| 1533 | * TODO : replace this by direclty setting these value |
||
| 1534 | * in the corresponding methods, so we won't need |
||
| 1535 | * the correpondancy tabble |
||
| 1536 | * |
||
| 1537 | * @return void |
||
| 1538 | */ |
||
| 1539 | protected function sortRelationshipsByType() |
||
| 1550 | |||
| 1551 | /** |
||
| 1552 | * Override this method for custom entity instantiation. |
||
| 1553 | * |
||
| 1554 | * @return null |
||
| 1555 | */ |
||
| 1556 | public function activator() |
||
| 1559 | |||
| 1560 | /** |
||
| 1561 | * Magic call to dynamic relationships. |
||
| 1562 | * |
||
| 1563 | * @param string $method |
||
| 1564 | * @param array $parameters |
||
| 1565 | * |
||
| 1566 | * @throws Exception |
||
| 1567 | * |
||
| 1568 | * @return mixed |
||
| 1569 | */ |
||
| 1570 | public function __call($method, $parameters) |
||
| 1581 | } |
||
| 1582 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.