Skip to content

Commit 3f923d4

Browse files
committed
Reintroduce method variable to reduce PR clutter
1 parent 80d8864 commit 3f923d4

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/Console/ModelsCommand.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -589,22 +589,23 @@ public function getPropertiesFromMethods($model)
589589
foreach ($methodReflections as $methodReflection) {
590590
$type = $this->getReturnTypeFromReflection($methodReflection);
591591
$isAttribute = is_a($type, '\Illuminate\Database\Eloquent\Casts\Attribute', true);
592+
$method = $methodReflection->getName();
592593
if (
593-
Str::startsWith($methodReflection->getName(), 'get') && Str::endsWith(
594-
$methodReflection->getName(),
594+
Str::startsWith($method, 'get') && Str::endsWith(
595+
$method,
595596
'Attribute'
596-
) && $methodReflection->getName() !== 'getAttribute'
597+
) && $method !== 'getAttribute'
597598
) {
598599
//Magic get<name>Attribute
599-
$name = Str::snake(substr($methodReflection->getName(), 3, -9));
600+
$name = Str::snake(substr($method, 3, -9));
600601
if (!empty($name)) {
601602
$type = $this->getReturnType($methodReflection);
602603
$type = $this->getTypeInModel($model, $type);
603604
$comment = $this->getCommentFromDocBlock($methodReflection);
604605
$this->setProperty($name, $type, true, null, $comment);
605606
}
606607
} elseif ($isAttribute) {
607-
$name = Str::snake($methodReflection->getName());
608+
$name = Str::snake($method);
608609
$types = $this->getAttributeReturnType($model, $methodReflection);
609610
$comment = $this->getCommentFromDocBlock($methodReflection);
610611

@@ -617,20 +618,20 @@ public function getPropertiesFromMethods($model)
617618
$this->setProperty($name, null, null, true, $comment);
618619
}
619620
} elseif (
620-
Str::startsWith($methodReflection->getName(), 'set') && Str::endsWith(
621-
$methodReflection->getName(),
621+
Str::startsWith($method, 'set') && Str::endsWith(
622+
$method,
622623
'Attribute'
623-
) && $methodReflection->getName() !== 'setAttribute'
624+
) && $method !== 'setAttribute'
624625
) {
625626
//Magic set<name>Attribute
626-
$name = Str::snake(substr($methodReflection->getName(), 3, -9));
627+
$name = Str::snake(substr($method, 3, -9));
627628
if (!empty($name)) {
628629
$comment = $this->getCommentFromDocBlock($methodReflection);
629630
$this->setProperty($name, null, null, true, $comment);
630631
}
631-
} elseif (Str::startsWith($methodReflection->getName(), 'scope') && $methodReflection->getName() !== 'scopeQuery') {
632+
} elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery') {
632633
//Magic set<name>Attribute
633-
$name = Str::camel(substr($methodReflection->getName(), 5));
634+
$name = Str::camel(substr($method, 5));
634635
if (!empty($name)) {
635636
$comment = $this->getCommentFromDocBlock($methodReflection);
636637
$args = $this->getParameters($methodReflection);
@@ -646,20 +647,20 @@ public function getPropertiesFromMethods($model)
646647
);
647648
$this->setMethod($name, $builder . '|' . $modelName, $args, $comment);
648649
}
649-
} elseif (in_array($methodReflection->getName(), ['query', 'newQuery', 'newModelQuery'])) {
650+
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
650651
$builder = $this->getClassNameInDestinationFile($model, get_class($model->newModelQuery()));
651652

652653
$this->setMethod(
653-
$methodReflection->getName(),
654+
$method,
654655
$builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model))
655656
);
656657

657658
if ($this->write_model_external_builder_methods) {
658659
$this->writeModelExternalBuilderMethods($model);
659660
}
660661
} elseif (
661-
!method_exists('Illuminate\Database\Eloquent\Model', $methodReflection->getName())
662-
&& !Str::startsWith($methodReflection->getName(), 'get')
662+
!method_exists('Illuminate\Database\Eloquent\Model', $method)
663+
&& !Str::startsWith($method, 'get')
663664
) {
664665
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
665666
if ($returnType = $methodReflection->getReturnType()) {
@@ -727,15 +728,15 @@ public function getPropertiesFromMethods($model)
727728
);
728729
$collectionTypeHint = $this->getCollectionTypeHint($collectionClassNameInModel, $relatedModel);
729730
$this->setProperty(
730-
$methodReflection->getName(),
731+
$method,
731732
$collectionTypeHint,
732733
true,
733734
null,
734735
$comment
735736
);
736737
if ($this->write_model_relation_count_properties) {
737738
$this->setProperty(
738-
Str::snake($methodReflection->getName()) . '_count',
739+
Str::snake($method) . '_count',
739740
'int|null',
740741
true,
741742
false
@@ -748,7 +749,7 @@ public function getPropertiesFromMethods($model)
748749
) {
749750
// Model isn't specified because relation is polymorphic
750751
$this->setProperty(
751-
$methodReflection->getName(),
752+
$method,
752753
$this->getClassNameInDestinationFile($model, Model::class) . '|\Eloquent',
753754
true,
754755
null,
@@ -757,7 +758,7 @@ public function getPropertiesFromMethods($model)
757758
} else {
758759
//Single model is returned
759760
$this->setProperty(
760-
$methodReflection->getName(),
761+
$method,
761762
$relatedModel,
762763
true,
763764
null,

0 commit comments

Comments
 (0)