@@ -111,7 +111,7 @@ class BeanDescriptor implements BeanDescriptorInterface
111
111
*/
112
112
private $ registry ;
113
113
/**
114
- * @var int []
114
+ * @var MethodDescriptorInterface[] []
115
115
*/
116
116
private $ descriptorsByMethodName = [];
117
117
/**
@@ -159,14 +159,7 @@ public function initBeanPropertyDescriptors(): void
159
159
160
160
//init the list of method names with regular properties names
161
161
foreach ($ this ->beanPropertyDescriptors as $ beanPropertyDescriptor ) {
162
- $ name = $ beanPropertyDescriptor ->getGetterName ();
163
- if (!isset ($ this ->descriptorsByMethodName [$ name ])) {
164
- $ this ->descriptorsByMethodName [$ name ] = 0 ;
165
- }
166
- $ this ->descriptorsByMethodName [$ name ] ++;
167
- if ($ this ->descriptorsByMethodName [$ name ] > 1 ) {
168
- $ beanPropertyDescriptor ->useAlternativeName ();
169
- }
162
+ $ this ->checkForDuplicate ($ beanPropertyDescriptor );
170
163
}
171
164
}
172
165
@@ -405,8 +398,8 @@ private function getDirectForeignKeysDescriptors(): array
405
398
$ descriptors = [];
406
399
407
400
foreach ($ fks as $ fk ) {
408
- /** @var DirectForeignKeyMethodDescriptor $desc */
409
- $ desc = $ this ->checkForDuplicate (new DirectForeignKeyMethodDescriptor ( $ fk , $ this -> table , $ this -> namingStrategy , $ this -> annotationParser , $ this -> beanNamespace ) );
401
+ $ desc = new DirectForeignKeyMethodDescriptor ( $ fk , $ this -> table , $ this -> namingStrategy , $ this -> annotationParser , $ this -> beanNamespace );
402
+ $ this ->checkForDuplicate ($ desc );
410
403
$ descriptors [] = $ desc ;
411
404
}
412
405
@@ -429,14 +422,14 @@ private function getPivotTableDescriptors(): array
429
422
430
423
if ($ fks [0 ]->getForeignTableName () === $ this ->table ->getName ()) {
431
424
list ($ localFk , $ remoteFk ) = $ fks ;
432
- /** @var PivotTableMethodsDescriptor $desc */
433
- $ desc = $ this ->checkForDuplicate (new PivotTableMethodsDescriptor ( $ table , $ localFk , $ remoteFk , $ this -> namingStrategy , $ this -> beanNamespace , $ this -> annotationParser ) );
425
+ $ desc = new PivotTableMethodsDescriptor ( $ table , $ localFk , $ remoteFk , $ this -> namingStrategy , $ this -> beanNamespace , $ this -> annotationParser );
426
+ $ this ->checkForDuplicate ($ desc );
434
427
$ descs [] = $ desc ;
435
428
}
436
429
if ($ fks [1 ]->getForeignTableName () === $ this ->table ->getName ()) {
437
430
list ($ remoteFk , $ localFk ) = $ fks ;
438
- /** @var PivotTableMethodsDescriptor $desc */
439
- $ desc = $ this ->checkForDuplicate (new PivotTableMethodsDescriptor ( $ table , $ localFk , $ remoteFk , $ this -> namingStrategy , $ this -> beanNamespace , $ this -> annotationParser ) );
431
+ $ desc = new PivotTableMethodsDescriptor ( $ table , $ localFk , $ remoteFk , $ this -> namingStrategy , $ this -> beanNamespace , $ this -> annotationParser );
432
+ $ this ->checkForDuplicate ($ desc );
440
433
$ descs [] = $ desc ;
441
434
}
442
435
}
@@ -446,25 +439,26 @@ private function getPivotTableDescriptors(): array
446
439
}
447
440
448
441
/**
449
- * Check the method name isn't already used and flag the $descriptor to use its alternative name if it is the case
442
+ * Check the method name isn't already used and flag the associated descriptors to use their alternative names if it is the case
450
443
*/
451
- public function checkForDuplicate (MethodDescriptorInterface $ descriptor ): MethodDescriptorInterface
444
+ private function checkForDuplicate (MethodDescriptorInterface $ descriptor ): void
452
445
{
453
446
$ name = $ descriptor ->getName ();
454
447
if (!isset ($ this ->descriptorsByMethodName [$ name ])) {
455
- $ this ->descriptorsByMethodName [$ name ] = 0 ;
448
+ $ this ->descriptorsByMethodName [$ name ] = [] ;
456
449
}
457
- $ this ->descriptorsByMethodName [$ name ] ++;
458
- if ($ this ->descriptorsByMethodName [$ name ] > 1 ) {
459
- $ descriptor ->useAlternativeName ();
450
+ $ this ->descriptorsByMethodName [$ name ][] = $ descriptor ;
451
+ if (count ($ this ->descriptorsByMethodName [$ name ]) > 1 ) {
452
+ foreach ($ this ->descriptorsByMethodName [$ name ] as $ duplicateDescriptor ) {
453
+ $ duplicateDescriptor ->useAlternativeName ();
454
+ }
460
455
}
461
- return $ descriptor ;
462
456
}
463
457
464
458
/**
465
459
* Returns the list of method descriptors (and applies the alternative name if needed).
466
460
*
467
- * @return MethodDescriptorInterface []
461
+ * @return RelationshipMethodDescriptorInterface []
468
462
*/
469
463
public function getMethodDescriptors (): array
470
464
{
0 commit comments