Skip to content

Commit 7b2d339

Browse files
committed
Change method visibility to protected for scope methods
1 parent e7beaf1 commit 7b2d339

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

docs/rector_rules_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ Changes model scope methods to use the scope attribute
13621362
{
13631363
- public function scopeActive($query)
13641364
+ #[\Illuminate\Database\Eloquent\Attributes\Scope]
1365-
+ public function active($query)
1365+
+ protected function active($query)
13661366
{
13671367
return $query->where('active', 1);
13681368
}

src/Rector/ClassMethod/ScopeNamedClassMethodToScopeAttributedClassMethodRector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace RectorLaravel\Rector\ClassMethod;
66

7+
use PhpParser\Modifiers;
78
use PhpParser\Node;
89
use PhpParser\Node\Attribute;
910
use PhpParser\Node\AttributeGroup;
@@ -98,6 +99,7 @@ public function refactor(Node $node): ?Node
9899
continue;
99100
}
100101

102+
$classMethod->flags = Modifiers::PROTECTED;
101103
$classMethod->name = new Identifier($newName);
102104
$classMethod->attrGroups[] = new AttributeGroup([new Attribute(new FullyQualified(self::SCOPE_ATTRIBUTE))]);
103105
$changes = true;

tests/Rector/ClassMethod/ScopeNamedClassMethodToScopeAttributedClassMethodRector/Fixture/fixture.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use Illuminate\Database\Eloquent\Model;
2323
class SomeClass extends Model
2424
{
2525
#[\Illuminate\Database\Eloquent\Attributes\Scope]
26-
public function someMethod()
26+
protected function someMethod()
2727
{
2828

2929
}

tests/Rector/ClassMethod/ScopeNamedClassMethodToScopeAttributedClassMethodRector/Fixture/non_duplicate_nodes.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
77
class NonDuplicateAttributeNodes extends Model
88
{
99
#[\Illuminate\Database\Eloquent\Attributes\Scope]
10-
public function scopeSomeMethod()
10+
protected function scopeSomeMethod()
1111
{
1212

1313
}

0 commit comments

Comments
 (0)