Skip to content

Commit 2e996b6

Browse files
committed
Change variable name to reduce PR clutter
1 parent 3f923d4 commit 2e996b6

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/Console/ModelsCommand.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,11 @@ public function getPropertiesFromTable($model)
570570
public function getPropertiesFromMethods($model)
571571
{
572572
$reflectionClass = new ReflectionClass($model);
573-
$methodReflections = $reflectionClass->getMethods();
574-
if ($methodReflections) {
573+
$reflections = $reflectionClass->getMethods();
574+
if ($reflections) {
575575
// Filter out private methods because they can't be used to generate magic properties and HasAttributes'
576576
// methods that resemble mutators but aren't.
577-
$methodReflections = array_filter($methodReflections, function (\ReflectionMethod $methodReflection) {
577+
$reflections = array_filter($reflections, function (\ReflectionMethod $methodReflection) {
578578
return !$methodReflection->isPrivate() && !(
579579
in_array(
580580
\Illuminate\Database\Eloquent\Concerns\HasAttributes::class,
@@ -585,11 +585,11 @@ public function getPropertiesFromMethods($model)
585585
)
586586
);
587587
});
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);
591591
$isAttribute = is_a($type, '\Illuminate\Database\Eloquent\Casts\Attribute', true);
592-
$method = $methodReflection->getName();
592+
$method = $reflection->getName();
593593
if (
594594
Str::startsWith($method, 'get') && Str::endsWith(
595595
$method,
@@ -599,15 +599,15 @@ public function getPropertiesFromMethods($model)
599599
//Magic get<name>Attribute
600600
$name = Str::snake(substr($method, 3, -9));
601601
if (!empty($name)) {
602-
$type = $this->getReturnType($methodReflection);
602+
$type = $this->getReturnType($reflection);
603603
$type = $this->getTypeInModel($model, $type);
604-
$comment = $this->getCommentFromDocBlock($methodReflection);
604+
$comment = $this->getCommentFromDocBlock($reflection);
605605
$this->setProperty($name, $type, true, null, $comment);
606606
}
607607
} elseif ($isAttribute) {
608608
$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);
611611

612612
if ($types->has('get')) {
613613
$type = $this->getTypeInModel($model, $types['get']);
@@ -626,24 +626,24 @@ public function getPropertiesFromMethods($model)
626626
//Magic set<name>Attribute
627627
$name = Str::snake(substr($method, 3, -9));
628628
if (!empty($name)) {
629-
$comment = $this->getCommentFromDocBlock($methodReflection);
629+
$comment = $this->getCommentFromDocBlock($reflection);
630630
$this->setProperty($name, null, null, true, $comment);
631631
}
632632
} elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery') {
633633
//Magic set<name>Attribute
634634
$name = Str::camel(substr($method, 5));
635635
if (!empty($name)) {
636-
$comment = $this->getCommentFromDocBlock($methodReflection);
637-
$args = $this->getParameters($methodReflection);
636+
$comment = $this->getCommentFromDocBlock($reflection);
637+
$args = $this->getParameters($reflection);
638638
//Remove the first ($query) argument
639639
array_shift($args);
640640
$builder = $this->getClassNameInDestinationFile(
641-
$methodReflection->getDeclaringClass(),
641+
$reflection->getDeclaringClass(),
642642
get_class($model->newModelQuery())
643643
);
644644
$modelName = $this->getClassNameInDestinationFile(
645-
$methodReflection->getDeclaringClass(),
646-
$methodReflection->getDeclaringClass()->getName()
645+
$reflection->getDeclaringClass(),
646+
$reflection->getDeclaringClass()->getName()
647647
);
648648
$this->setMethod($name, $builder . '|' . $modelName, $args, $comment);
649649
}
@@ -663,20 +663,20 @@ public function getPropertiesFromMethods($model)
663663
&& !Str::startsWith($method, 'get')
664664
) {
665665
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
666-
if ($returnType = $methodReflection->getReturnType()) {
666+
if ($returnType = $reflection->getReturnType()) {
667667
$type = $returnType instanceof ReflectionNamedType
668668
? $returnType->getName()
669669
: (string)$returnType;
670670
} else {
671671
// php 7.x type or fallback to docblock
672-
$type = (string)$this->getReturnTypeFromDocBlock($methodReflection);
672+
$type = (string)$this->getReturnTypeFromDocBlock($reflection);
673673
}
674674

675-
$file = new \SplFileObject($methodReflection->getFileName());
676-
$file->seek($methodReflection->getStartLine() - 1);
675+
$file = new \SplFileObject($reflection->getFileName());
676+
$file->seek($reflection->getStartLine() - 1);
677677

678678
$code = '';
679-
while ($file->key() < $methodReflection->getEndLine()) {
679+
while ($file->key() < $reflection->getEndLine()) {
680680
$code .= $file->current();
681681
$file->next();
682682
}
@@ -690,20 +690,20 @@ public function getPropertiesFromMethods($model)
690690
$search = '$this->' . $relation . '(';
691691
if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) {
692692
//Resolve the relation's model to a Relation object.
693-
if ($methodReflection->getNumberOfParameters()) {
693+
if ($reflection->getNumberOfParameters()) {
694694
continue;
695695
}
696696

697-
$comment = $this->getCommentFromDocBlock($methodReflection);
697+
$comment = $this->getCommentFromDocBlock($reflection);
698698
// Adding constraints requires reading model properties which
699699
// can cause errors. Since we don't need constraints we can
700700
// 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) {
702702
try {
703-
$methodName = $methodReflection->getName();
703+
$methodName = $reflection->getName();
704704
return $model->$methodName();
705705
} 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()));
707707

708708
return null;
709709
}

0 commit comments

Comments
 (0)