@@ -570,11 +570,11 @@ public function getPropertiesFromTable($model)
570
570
public function getPropertiesFromMethods ($ model )
571
571
{
572
572
$ reflectionClass = new ReflectionClass ($ model );
573
- $ methodReflections = $ reflectionClass ->getMethods ();
574
- if ($ methodReflections ) {
573
+ $ reflections = $ reflectionClass ->getMethods ();
574
+ if ($ reflections ) {
575
575
// Filter out private methods because they can't be used to generate magic properties and HasAttributes'
576
576
// methods that resemble mutators but aren't.
577
- $ methodReflections = array_filter ($ methodReflections , function (\ReflectionMethod $ methodReflection ) {
577
+ $ reflections = array_filter ($ reflections , function (\ReflectionMethod $ methodReflection ) {
578
578
return !$ methodReflection ->isPrivate () && !(
579
579
in_array (
580
580
\Illuminate \Database \Eloquent \Concerns \HasAttributes::class,
@@ -585,11 +585,11 @@ public function getPropertiesFromMethods($model)
585
585
)
586
586
);
587
587
});
588
- sort ($ methodReflections );
589
- foreach ($ methodReflections as $ methodReflection ) {
590
- $ type = $ this ->getReturnTypeFromReflection ($ methodReflection );
588
+ sort ($ reflections );
589
+ foreach ($ reflections as $ reflection ) {
590
+ $ type = $ this ->getReturnTypeFromReflection ($ reflection );
591
591
$ isAttribute = is_a ($ type , '\Illuminate\Database\Eloquent\Casts\Attribute ' , true );
592
- $ method = $ methodReflection ->getName ();
592
+ $ method = $ reflection ->getName ();
593
593
if (
594
594
Str::startsWith ($ method , 'get ' ) && Str::endsWith (
595
595
$ method ,
@@ -599,15 +599,15 @@ public function getPropertiesFromMethods($model)
599
599
//Magic get<name>Attribute
600
600
$ name = Str::snake (substr ($ method , 3 , -9 ));
601
601
if (!empty ($ name )) {
602
- $ type = $ this ->getReturnType ($ methodReflection );
602
+ $ type = $ this ->getReturnType ($ reflection );
603
603
$ type = $ this ->getTypeInModel ($ model , $ type );
604
- $ comment = $ this ->getCommentFromDocBlock ($ methodReflection );
604
+ $ comment = $ this ->getCommentFromDocBlock ($ reflection );
605
605
$ this ->setProperty ($ name , $ type , true , null , $ comment );
606
606
}
607
607
} elseif ($ isAttribute ) {
608
608
$ name = Str::snake ($ method );
609
- $ types = $ this ->getAttributeReturnType ($ model , $ methodReflection );
610
- $ comment = $ this ->getCommentFromDocBlock ($ methodReflection );
609
+ $ types = $ this ->getAttributeReturnType ($ model , $ reflection );
610
+ $ comment = $ this ->getCommentFromDocBlock ($ reflection );
611
611
612
612
if ($ types ->has ('get ' )) {
613
613
$ type = $ this ->getTypeInModel ($ model , $ types ['get ' ]);
@@ -626,24 +626,24 @@ public function getPropertiesFromMethods($model)
626
626
//Magic set<name>Attribute
627
627
$ name = Str::snake (substr ($ method , 3 , -9 ));
628
628
if (!empty ($ name )) {
629
- $ comment = $ this ->getCommentFromDocBlock ($ methodReflection );
629
+ $ comment = $ this ->getCommentFromDocBlock ($ reflection );
630
630
$ this ->setProperty ($ name , null , null , true , $ comment );
631
631
}
632
632
} elseif (Str::startsWith ($ method , 'scope ' ) && $ method !== 'scopeQuery ' ) {
633
633
//Magic set<name>Attribute
634
634
$ name = Str::camel (substr ($ method , 5 ));
635
635
if (!empty ($ name )) {
636
- $ comment = $ this ->getCommentFromDocBlock ($ methodReflection );
637
- $ args = $ this ->getParameters ($ methodReflection );
636
+ $ comment = $ this ->getCommentFromDocBlock ($ reflection );
637
+ $ args = $ this ->getParameters ($ reflection );
638
638
//Remove the first ($query) argument
639
639
array_shift ($ args );
640
640
$ builder = $ this ->getClassNameInDestinationFile (
641
- $ methodReflection ->getDeclaringClass (),
641
+ $ reflection ->getDeclaringClass (),
642
642
get_class ($ model ->newModelQuery ())
643
643
);
644
644
$ modelName = $ this ->getClassNameInDestinationFile (
645
- $ methodReflection ->getDeclaringClass (),
646
- $ methodReflection ->getDeclaringClass ()->getName ()
645
+ $ reflection ->getDeclaringClass (),
646
+ $ reflection ->getDeclaringClass ()->getName ()
647
647
);
648
648
$ this ->setMethod ($ name , $ builder . '| ' . $ modelName , $ args , $ comment );
649
649
}
@@ -663,20 +663,20 @@ public function getPropertiesFromMethods($model)
663
663
&& !Str::startsWith ($ method , 'get ' )
664
664
) {
665
665
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
666
- if ($ returnType = $ methodReflection ->getReturnType ()) {
666
+ if ($ returnType = $ reflection ->getReturnType ()) {
667
667
$ type = $ returnType instanceof ReflectionNamedType
668
668
? $ returnType ->getName ()
669
669
: (string )$ returnType ;
670
670
} else {
671
671
// php 7.x type or fallback to docblock
672
- $ type = (string )$ this ->getReturnTypeFromDocBlock ($ methodReflection );
672
+ $ type = (string )$ this ->getReturnTypeFromDocBlock ($ reflection );
673
673
}
674
674
675
- $ file = new \SplFileObject ($ methodReflection ->getFileName ());
676
- $ file ->seek ($ methodReflection ->getStartLine () - 1 );
675
+ $ file = new \SplFileObject ($ reflection ->getFileName ());
676
+ $ file ->seek ($ reflection ->getStartLine () - 1 );
677
677
678
678
$ code = '' ;
679
- while ($ file ->key () < $ methodReflection ->getEndLine ()) {
679
+ while ($ file ->key () < $ reflection ->getEndLine ()) {
680
680
$ code .= $ file ->current ();
681
681
$ file ->next ();
682
682
}
@@ -690,20 +690,20 @@ public function getPropertiesFromMethods($model)
690
690
$ search = '$this-> ' . $ relation . '( ' ;
691
691
if (stripos ($ code , $ search ) || ltrim ($ impl , '\\' ) === ltrim ((string )$ type , '\\' )) {
692
692
//Resolve the relation's model to a Relation object.
693
- if ($ methodReflection ->getNumberOfParameters ()) {
693
+ if ($ reflection ->getNumberOfParameters ()) {
694
694
continue ;
695
695
}
696
696
697
- $ comment = $ this ->getCommentFromDocBlock ($ methodReflection );
697
+ $ comment = $ this ->getCommentFromDocBlock ($ reflection );
698
698
// Adding constraints requires reading model properties which
699
699
// can cause errors. Since we don't need constraints we can
700
700
// disable them when we fetch the relation to avoid errors.
701
- $ relationObj = Relation::noConstraints (function () use ($ model , $ methodReflection ) {
701
+ $ relationObj = Relation::noConstraints (function () use ($ model , $ reflection ) {
702
702
try {
703
- $ methodName = $ methodReflection ->getName ();
703
+ $ methodName = $ reflection ->getName ();
704
704
return $ model ->$ methodName ();
705
705
} catch (Throwable $ e ) {
706
- $ this ->warn (sprintf ('Error resolving relation model of %s:%s() : %s ' , get_class ($ model ), $ methodReflection ->getName (), $ e ->getMessage ()));
706
+ $ this ->warn (sprintf ('Error resolving relation model of %s:%s() : %s ' , get_class ($ model ), $ reflection ->getName (), $ e ->getMessage ()));
707
707
708
708
return null ;
709
709
}
0 commit comments