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 |
||
| 24 | class EntityMap |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * The mapping driver to use with this entity |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $driver = 'illuminate'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The Database Connection name for the model. |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $connection; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * The table associated with the entity. |
||
| 42 | * |
||
| 43 | * @var string|null |
||
| 44 | */ |
||
| 45 | protected $table = null; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The primary key for the model. |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | protected $primaryKey = 'id'; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Name of the entity's array property that should |
||
| 56 | * contain the attributes. |
||
| 57 | * If set to null, analogue will only hydrate object's properties |
||
| 58 | * |
||
| 59 | * @var string|null |
||
| 60 | */ |
||
| 61 | protected $arrayName = 'attributes'; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Array containing the list of database columns to be mapped |
||
| 65 | * in the attributes array of the entity. |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | protected $attributes = []; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Array containing the list of database columns to be mapped |
||
| 73 | * to the entity's class properties. |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | protected $properties = []; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * The Custom Domain Class to use with this mapping |
||
| 81 | * |
||
| 82 | * @var string|null |
||
| 83 | */ |
||
| 84 | protected $class = null; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Embedded Value Objects |
||
| 88 | * |
||
| 89 | * @var array |
||
| 90 | */ |
||
| 91 | protected $embeddables = []; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Determine the relationships method used on the entity. |
||
| 95 | * If not set, mapper will autodetect them |
||
| 96 | * |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | private $relationships = []; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Relationships that should be treated as collection. |
||
| 103 | * |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | private $manyRelations = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Relationships that should be treated as single entity. |
||
| 110 | * |
||
| 111 | * @var array |
||
| 112 | */ |
||
| 113 | private $singleRelations = []; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Relationships for which the key is stored in the Entity itself |
||
| 117 | * |
||
| 118 | * @var array |
||
| 119 | */ |
||
| 120 | private $localRelations = []; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * List of local keys associated to local relation methods |
||
| 124 | * |
||
| 125 | * @var array |
||
| 126 | */ |
||
| 127 | private $localForeignKeys = []; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Relationships for which the key is stored in the Related Entity |
||
| 131 | * |
||
| 132 | * @var array |
||
| 133 | */ |
||
| 134 | private $foreignRelations = []; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Relationships which use a pivot record. |
||
| 138 | * |
||
| 139 | * @var array |
||
| 140 | */ |
||
| 141 | private $pivotRelations = []; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Dynamic relationships |
||
| 145 | * |
||
| 146 | * @var array |
||
| 147 | */ |
||
| 148 | private $dynamicRelationships = []; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Targetted class for the relationship method. value is set to `null` for |
||
| 152 | * polymorphic relations. |
||
| 153 | * |
||
| 154 | * @var array |
||
| 155 | */ |
||
| 156 | private $relatedClasses = []; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Some relation methods like embedded objects, or HasOne and MorphOne, |
||
| 160 | * will never have a proxy loaded on them. |
||
| 161 | * |
||
| 162 | * @var array |
||
| 163 | */ |
||
| 164 | private $nonProxyRelationships = []; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * The number of models to return for pagination. |
||
| 168 | * |
||
| 169 | * @var int |
||
| 170 | */ |
||
| 171 | protected $perPage = 15; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * The relations to eager load on every query. |
||
| 175 | * |
||
| 176 | * @var array |
||
| 177 | */ |
||
| 178 | protected $with = []; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * The class name to be used in polymorphic relations. |
||
| 182 | * |
||
| 183 | * @var string |
||
| 184 | */ |
||
| 185 | protected $morphClass; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Sequence name, to be used with postgreSql |
||
| 189 | * defaults to %table_name%_id_seq |
||
| 190 | * |
||
| 191 | * @var string|null |
||
| 192 | */ |
||
| 193 | protected $sequence = null; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Indicates if the entity should be timestamped. |
||
| 197 | * |
||
| 198 | * @var bool |
||
| 199 | */ |
||
| 200 | public $timestamps = false; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * The name of the "created at" column. |
||
| 204 | * |
||
| 205 | * @var string |
||
| 206 | */ |
||
| 207 | protected $createdAtColumn = 'created_at'; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * The name of the "updated at" column. |
||
| 211 | * |
||
| 212 | * @var string |
||
| 213 | */ |
||
| 214 | protected $updatedAtColumn = 'updated_at'; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Indicates if the entity uses softdeletes |
||
| 218 | * |
||
| 219 | * @var boolean |
||
| 220 | */ |
||
| 221 | public $softDeletes = false; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * The name of the "deleted at" column. |
||
| 225 | * |
||
| 226 | * @var string |
||
| 227 | */ |
||
| 228 | protected $deletedAtColumn = 'deleted_at'; |
||
| 229 | |||
| 230 | /** |
||
| 231 | * The date format to use with the current database connection |
||
| 232 | * |
||
| 233 | * @var string |
||
| 234 | */ |
||
| 235 | protected $dateFormat; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Set this property to true if the entity should be instantiated |
||
| 239 | * using the IoC Container |
||
| 240 | * |
||
| 241 | * @var boolean |
||
| 242 | */ |
||
| 243 | protected $dependencyInjection = false; |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Set the usage of inheritance, possible values are : |
||
| 247 | * "single_table" |
||
| 248 | * null |
||
| 249 | * |
||
| 250 | * @var string | null |
||
| 251 | */ |
||
| 252 | protected $inheritanceType = null; |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Discriminator column name |
||
| 256 | * |
||
| 257 | * @var string |
||
| 258 | */ |
||
| 259 | protected $discriminatorColumn = "type"; |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Allow using a string to define which entity type should be instantiated. |
||
| 263 | * If not set, analogue will uses entity's FQDN |
||
| 264 | * |
||
| 265 | * @var array |
||
| 266 | */ |
||
| 267 | protected $discriminatorColumnMap = []; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Return Domain class attributes, useful when mapping to a Plain PHP Object |
||
| 271 | * |
||
| 272 | * @return array |
||
| 273 | */ |
||
| 274 | public function getAttributes() : array |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Set the domain class attributes |
||
| 281 | * |
||
| 282 | * @param array $attributeNames |
||
| 283 | */ |
||
| 284 | public function setAttributes(array $attributeNames) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Return true if the Entity has an 'attributes' array property |
||
| 291 | * |
||
| 292 | * @return boolean |
||
| 293 | */ |
||
| 294 | public function usesAttributesArray() : bool |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Return the name of the Entity's attributes property |
||
| 301 | * |
||
| 302 | * @return string|null |
||
| 303 | */ |
||
| 304 | public function getAttributesArrayName() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Get all the attribute names for the class, including relationships, embeddables and primary key. |
||
| 311 | * |
||
| 312 | * @return array |
||
| 313 | */ |
||
| 314 | public function getCompiledAttributes() : array |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Set the date format to use with the current database connection |
||
| 329 | * |
||
| 330 | * @param string $format |
||
| 331 | */ |
||
| 332 | public function setDateFormat($format) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Get the date format to use with the current database connection |
||
| 339 | * |
||
| 340 | * @return string |
||
| 341 | */ |
||
| 342 | public function getDateFormat() : string |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Set the Driver for this mapping |
||
| 349 | * |
||
| 350 | * @param string $driver |
||
| 351 | */ |
||
| 352 | public function setDriver($driver) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Get the Driver for this mapping. |
||
| 359 | * |
||
| 360 | * @return string |
||
| 361 | */ |
||
| 362 | public function getDriver() : string |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Set the db connection to use on the table |
||
| 369 | * |
||
| 370 | * @param $connection |
||
| 371 | */ |
||
| 372 | public function setConnection($connection) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Get the Database connection the Entity is stored on. |
||
| 379 | * |
||
| 380 | * @return string | null |
||
| 381 | */ |
||
| 382 | public function getConnection() |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Get the table associated with the entity. |
||
| 389 | * |
||
| 390 | * @return string |
||
| 391 | */ |
||
| 392 | public function getTable() : string |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Set the database table name |
||
| 403 | * |
||
| 404 | * @param string $table |
||
| 405 | */ |
||
| 406 | public function setTable($table) |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Get the pgSql sequence name |
||
| 413 | * |
||
| 414 | * @return string |
||
| 415 | */ |
||
| 416 | public function getSequence() : string |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Get the custom entity class |
||
| 427 | * |
||
| 428 | * @return string namespaced class name |
||
| 429 | */ |
||
| 430 | public function getClass() : string |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Set the custom entity class |
||
| 437 | * |
||
| 438 | * @param string $class namespaced class name |
||
| 439 | */ |
||
| 440 | public function setClass($class) |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Get the embedded Value Objects |
||
| 447 | * |
||
| 448 | * @return array |
||
| 449 | */ |
||
| 450 | public function getEmbeddables() : array |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Return attributes that should be mapped to class properties |
||
| 457 | * |
||
| 458 | * @return array |
||
| 459 | */ |
||
| 460 | public function getProperties() : array |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Return the array property in which will be mapped all attributes |
||
| 467 | * that are not mapped to class properties. |
||
| 468 | * |
||
| 469 | * @return string |
||
| 470 | */ |
||
| 471 | public function getAttributesPropertyName() : string |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Set the embedded Value Objects |
||
| 478 | * |
||
| 479 | * @param array $embeddables |
||
| 480 | */ |
||
| 481 | public function setEmbeddables(array $embeddables) |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Get the relationships to map on a custom domain |
||
| 488 | * class. |
||
| 489 | * |
||
| 490 | * @return array |
||
| 491 | */ |
||
| 492 | public function getRelationships() : array |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Get the relationships that will not have a proxy |
||
| 499 | * set on them |
||
| 500 | * |
||
| 501 | * @return array |
||
| 502 | */ |
||
| 503 | public function getRelationshipsWithoutProxy() : array |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Relationships of the Entity type |
||
| 510 | * |
||
| 511 | * @return array |
||
| 512 | */ |
||
| 513 | public function getSingleRelationships() : array |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Relationships of type Collection |
||
| 520 | * |
||
| 521 | * @return array |
||
| 522 | */ |
||
| 523 | public function getManyRelationships() : array |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Relationships with foreign key in the mapped entity record. |
||
| 530 | * |
||
| 531 | * @return array |
||
| 532 | */ |
||
| 533 | public function getLocalRelationships() : array |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Return the local keys associated to the relationship |
||
| 540 | * |
||
| 541 | * @param string $relation |
||
| 542 | * @return string | array | null |
||
| 543 | */ |
||
| 544 | public function getLocalKeys($relation) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Relationships with foreign key in the related Entity record |
||
| 551 | * |
||
| 552 | * @return array |
||
| 553 | */ |
||
| 554 | public function getForeignRelationships() : array |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Relationships which keys are stored in a pivot record |
||
| 561 | * |
||
| 562 | * @return array |
||
| 563 | */ |
||
| 564 | public function getPivotRelationships() : array |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Get the targetted type for a relationship. Return null if polymorphic |
||
| 571 | * |
||
| 572 | * @param string $relation |
||
| 573 | * @return string | null |
||
| 574 | */ |
||
| 575 | public function getTargettedClass($relation) |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Add a Dynamic Relationship method at runtime. This has to be done |
||
| 582 | * by hooking the 'initializing' event, before entityMap is initialized. |
||
| 583 | * |
||
| 584 | * @param string $name Relation name |
||
| 585 | * @param \Closure $relationship |
||
| 586 | * |
||
| 587 | * @return void |
||
| 588 | */ |
||
| 589 | public function addRelationshipMethod($name, \Closure $relationship) |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Get the dynamic relationship method names. |
||
| 596 | * |
||
| 597 | * @return array |
||
| 598 | */ |
||
| 599 | public function getDynamicRelationships() : array |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Get the relationships that have to be eager loaded |
||
| 606 | * on each request. |
||
| 607 | * |
||
| 608 | * @return array |
||
| 609 | */ |
||
| 610 | public function getEagerloadedRelationships() : array |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Get the primary key attribute for the entity. |
||
| 617 | * |
||
| 618 | * @return string |
||
| 619 | */ |
||
| 620 | public function getKeyName() : string |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Set the primary key for the entity. |
||
| 627 | * |
||
| 628 | * @param $key |
||
| 629 | * @return void |
||
| 630 | */ |
||
| 631 | public function setKeyName($key) |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Get the table qualified key name. |
||
| 638 | * |
||
| 639 | * @return string |
||
| 640 | */ |
||
| 641 | public function getQualifiedKeyName() : string |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Get the number of models to return per page. |
||
| 648 | * |
||
| 649 | * @return int |
||
| 650 | */ |
||
| 651 | public function getPerPage() : int |
||
| 655 | |||
| 656 | /** |
||
| 657 | * Set the number of models to return per page. |
||
| 658 | * |
||
| 659 | * @param int $perPage |
||
| 660 | * @return void |
||
| 661 | */ |
||
| 662 | public function setPerPage($perPage) |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Determine if the entity uses get. |
||
| 669 | * |
||
| 670 | * @return bool |
||
| 671 | */ |
||
| 672 | public function usesTimestamps() : bool |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Determine if the entity uses soft deletes |
||
| 679 | * |
||
| 680 | * @return bool |
||
| 681 | */ |
||
| 682 | public function usesSoftDeletes() : bool |
||
| 686 | |||
| 687 | /** |
||
| 688 | * Get the 'created_at' column name |
||
| 689 | * |
||
| 690 | * @return string |
||
| 691 | */ |
||
| 692 | public function getCreatedAtColumn() : string |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Get the 'updated_at' column name |
||
| 699 | * |
||
| 700 | * @return string |
||
| 701 | */ |
||
| 702 | public function getUpdatedAtColumn() : string |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Get the deleted_at column |
||
| 709 | * |
||
| 710 | * @return string |
||
| 711 | */ |
||
| 712 | public function getQualifiedDeletedAtColumn() : string |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Get the default foreign key name for the model. |
||
| 719 | * |
||
| 720 | * @return string |
||
| 721 | */ |
||
| 722 | public function getForeignKey() : string |
||
| 726 | |||
| 727 | /** |
||
| 728 | * Return the inheritance type used by the entity. |
||
| 729 | * |
||
| 730 | * @return string|null |
||
| 731 | */ |
||
| 732 | public function getInheritanceType() |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Return the discriminator column name on the entity that's |
||
| 739 | * used for table inheritance. |
||
| 740 | * |
||
| 741 | * @return string |
||
| 742 | */ |
||
| 743 | public function getDiscriminatorColumn() : string |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Return the mapping of discriminator column values to |
||
| 750 | * entity class names that are used for table inheritance. |
||
| 751 | * |
||
| 752 | * @return array |
||
| 753 | */ |
||
| 754 | public function getDiscriminatorColumnMap() : array |
||
| 758 | |||
| 759 | /** |
||
| 760 | * Return true if the entity should be instanciated using |
||
| 761 | * the IoC Container |
||
| 762 | * |
||
| 763 | * @return boolean |
||
| 764 | */ |
||
| 765 | public function useDependencyInjection() : bool |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Add a single relation method name once |
||
| 772 | * |
||
| 773 | * @param string $relation |
||
| 774 | */ |
||
| 775 | protected function addSingleRelation($relation) |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Add a foreign relation method name once |
||
| 784 | * |
||
| 785 | * @param string $relation |
||
| 786 | */ |
||
| 787 | protected function addForeignRelation($relation) |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Add a non proxy relation method name once |
||
| 796 | * |
||
| 797 | * @param string $relation |
||
| 798 | */ |
||
| 799 | protected function addNonProxyRelation($relation) |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Add a local relation method name once |
||
| 808 | * |
||
| 809 | * @param string $relation |
||
| 810 | */ |
||
| 811 | protected function addLocalRelation($relation) |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Add a many relation method name once |
||
| 820 | * |
||
| 821 | * @param string $relation |
||
| 822 | */ |
||
| 823 | protected function addManyRelation($relation) |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Add a pivot relation method name once |
||
| 832 | * |
||
| 833 | * @param string $relation |
||
| 834 | */ |
||
| 835 | protected function addPivotRelation($relation) |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Define a one-to-one relationship. |
||
| 844 | * |
||
| 845 | * @param mixed $entity |
||
| 846 | * @param string $related entity class |
||
| 847 | * @param string $foreignKey |
||
| 848 | * @param string $localKey |
||
| 849 | * @throws MappingException |
||
| 850 | * @return \Analogue\ORM\Relationships\HasOne |
||
| 851 | */ |
||
| 852 | public function hasOne($entity, $related, $foreignKey = null, $localKey = null) |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Define a polymorphic one-to-one relationship. |
||
| 882 | * |
||
| 883 | * @param mixed $entity |
||
| 884 | * @param string $related |
||
| 885 | * @param string $name |
||
| 886 | * @param string|null $type |
||
| 887 | * @param string|null $id |
||
| 888 | * @param string|null $localKey |
||
| 889 | * @throws MappingException |
||
| 890 | * @return \Analogue\ORM\Relationships\MorphOne |
||
| 891 | */ |
||
| 892 | public function morphOne($entity, $related, $name, $type = null, $id = null, $localKey = null) |
||
| 919 | |||
| 920 | /** |
||
| 921 | * Define an inverse one-to-one or many relationship. |
||
| 922 | * |
||
| 923 | * @param mixed $entity |
||
| 924 | * @param string $related |
||
| 925 | * @param string|null $foreignKey |
||
| 926 | * @param string|null $otherKey |
||
| 927 | * @param string|null $relation |
||
|
|
|||
| 928 | * @throws MappingException |
||
| 929 | * @return \Analogue\ORM\Relationships\BelongsTo |
||
| 930 | */ |
||
| 931 | public function belongsTo($entity, $related, $foreignKey = null, $otherKey = null) |
||
| 956 | |||
| 957 | /** |
||
| 958 | * Define a polymorphic, inverse one-to-one or many relationship. |
||
| 959 | * |
||
| 960 | * @param mixed $entity |
||
| 961 | * @param string|null $name |
||
| 962 | * @param string|null $type |
||
| 963 | * @param string|null $id |
||
| 964 | * @throws MappingException |
||
| 965 | * @return \Analogue\ORM\Relationships\MorphTo |
||
| 966 | */ |
||
| 967 | public function morphTo($entity, $name = null, $type = null, $id = null) |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * Define a one-to-many relationship. |
||
| 1024 | * |
||
| 1025 | * @param mixed $entity |
||
| 1026 | * @param string $related |
||
| 1027 | * @param string|null $foreignKey |
||
| 1028 | * @param string|null $localKey |
||
| 1029 | * @throws MappingException |
||
| 1030 | * @return \Analogue\ORM\Relationships\HasMany |
||
| 1031 | */ |
||
| 1032 | public function hasMany($entity, $related, $foreignKey = null, $localKey = null) |
||
| 1052 | |||
| 1053 | /** |
||
| 1054 | * Define a has-many-through relationship. |
||
| 1055 | * |
||
| 1056 | * @param mixed $entity |
||
| 1057 | * @param string $related |
||
| 1058 | * @param string $through |
||
| 1059 | * @param string|null $firstKey |
||
| 1060 | * @param string|null $secondKey |
||
| 1061 | * @throws MappingException |
||
| 1062 | * @return \Analogue\ORM\Relationships\HasManyThrough |
||
| 1063 | */ |
||
| 1064 | public function hasManyThrough($entity, $related, $through, $firstKey = null, $secondKey = null) |
||
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Define a polymorphic one-to-many relationship. |
||
| 1090 | * |
||
| 1091 | * @param mixed $entity |
||
| 1092 | * @param string $related |
||
| 1093 | * @param string $name |
||
| 1094 | * @param string|null $type |
||
| 1095 | * @param string|null $id |
||
| 1096 | * @param string|null $localKey |
||
| 1097 | * @return \Analogue\ORM\Relationships\MorphMany |
||
| 1098 | */ |
||
| 1099 | public function morphMany($entity, $related, $name, $type = null, $id = null, $localKey = null) |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Define a many-to-many relationship. |
||
| 1125 | * |
||
| 1126 | * @param mixed $entity |
||
| 1127 | * @param string $relatedClass |
||
| 1128 | * @param string|null $table |
||
| 1129 | * @param string|null $foreignKey |
||
| 1130 | * @param string|null $otherKey |
||
| 1131 | * @param string|null $relation |
||
| 1132 | * @throws MappingException |
||
| 1133 | * @return \Analogue\ORM\Relationships\BelongsToMany |
||
| 1134 | */ |
||
| 1135 | public function belongsToMany($entity, $related, $table = null, $foreignKey = null, $otherKey = null) |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Define a polymorphic many-to-many relationship. |
||
| 1169 | * |
||
| 1170 | * @param mixed $entity |
||
| 1171 | * @param string $related |
||
| 1172 | * @param string $name |
||
| 1173 | * @param string|null $table |
||
| 1174 | * @param string|null $foreignKey |
||
| 1175 | * @param string|null $otherKey |
||
| 1176 | * @param bool $inverse |
||
| 1177 | * @throws MappingException |
||
| 1178 | * @return \Analogue\ORM\Relationships\MorphToMany |
||
| 1179 | */ |
||
| 1180 | public function morphToMany($entity, $related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false) |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Define a polymorphic, inverse many-to-many relationship. |
||
| 1207 | * |
||
| 1208 | * @param mixed $entity |
||
| 1209 | * @param string $related |
||
| 1210 | * @param string $name |
||
| 1211 | * @param string|null $table |
||
| 1212 | * @param string|null $foreignKey |
||
| 1213 | * @param string|null $otherKey |
||
| 1214 | * @throws MappingException |
||
| 1215 | * @return \Analogue\ORM\Relationships\MorphToMany |
||
| 1216 | */ |
||
| 1217 | public function morphedByMany($entity, $related, $name, $table = null, $foreignKey = null, $otherKey = null) |
||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * Get the joining table name for a many-to-many relation. |
||
| 1239 | * |
||
| 1240 | * @param EntityMap $relatedMap |
||
| 1241 | * @return string |
||
| 1242 | */ |
||
| 1243 | public function joiningTable($relatedMap) |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Get the polymorphic relationship columns. |
||
| 1264 | * |
||
| 1265 | * @param string $name |
||
| 1266 | * @param string $type |
||
| 1267 | * @param string $id |
||
| 1268 | * @return string[] |
||
| 1269 | */ |
||
| 1270 | protected function getMorphs($name, $type, $id) |
||
| 1278 | |||
| 1279 | /** |
||
| 1280 | * Get the class name for polymorphic relations. |
||
| 1281 | * |
||
| 1282 | * @return string |
||
| 1283 | */ |
||
| 1284 | public function getMorphClass() |
||
| 1289 | |||
| 1290 | /** |
||
| 1291 | * Create a new Entity Collection instance. |
||
| 1292 | * |
||
| 1293 | * @param array $entities |
||
| 1294 | * @return \Analogue\ORM\EntityCollection |
||
| 1295 | */ |
||
| 1296 | public function newCollection(array $entities = []) |
||
| 1301 | |||
| 1302 | /** |
||
| 1303 | * Process EntityMap parsing at initialization time |
||
| 1304 | * |
||
| 1305 | * @return void |
||
| 1306 | */ |
||
| 1307 | public function initialize() |
||
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Parse every relationships on the EntityMap and sort |
||
| 1324 | * them by type. |
||
| 1325 | * |
||
| 1326 | * @return void |
||
| 1327 | */ |
||
| 1328 | public function boot() |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * Get Methods that has been added in the child class. |
||
| 1337 | * |
||
| 1338 | * @return array |
||
| 1339 | */ |
||
| 1340 | protected function getCustomMethods() |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Parse user's class methods for relationships |
||
| 1351 | * |
||
| 1352 | * @param array $customMethods |
||
| 1353 | * @return array |
||
| 1354 | */ |
||
| 1355 | protected function parseMethodsForRelationship(array $customMethods) |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * Sort Relationships methods by type |
||
| 1383 | * |
||
| 1384 | * TODO : replace this by direclty setting these value |
||
| 1385 | * in the corresponding methods, so we won't need |
||
| 1386 | * the correpondancy tabble |
||
| 1387 | * |
||
| 1388 | * @return void |
||
| 1389 | */ |
||
| 1390 | protected function sortRelationshipsByType() |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Override this method for custom entity instantiation |
||
| 1404 | * |
||
| 1405 | * @return null |
||
| 1406 | */ |
||
| 1407 | public function activator() |
||
| 1411 | |||
| 1412 | /** |
||
| 1413 | * Magic call to dynamic relationships |
||
| 1414 | * |
||
| 1415 | * @param string $method |
||
| 1416 | * @param array $parameters |
||
| 1417 | * @throws Exception |
||
| 1418 | * @return mixed |
||
| 1419 | */ |
||
| 1420 | public function __call($method, $parameters) |
||
| 1431 | } |
||
| 1432 |
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.