Skip to content

Commit 8fdb259

Browse files
canvuralGeniJaho
andauthored
fix: skip rule when its overriding the method (#387)
Co-authored-by: Geni Jaho <[email protected]>
1 parent 42115f0 commit 8fdb259

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/Rector/ClassMethod/MakeModelAttributesAndScopesProtectedRector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ private function shouldSkipNode(ClassMethod $classMethod, Scope $scope): bool
113113
return true;
114114
}
115115

116+
if (
117+
$classReflection->getParentClass() instanceof ClassReflection &&
118+
$classReflection->getParentClass()->hasMethod($this->getName($classMethod)) &&
119+
$classReflection->getParentClass()->getMethod($this->getName($classMethod), $scope)->isPublic()
120+
) {
121+
return true;
122+
}
123+
116124
return ! $classReflection->isTrait()
117125
&& ! $classReflection->is('Illuminate\Database\Eloquent\Model');
118126
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Rector\ClassMethod\MakeModelAttributesAndScopesProtectedRector\Fixture;
4+
5+
use Illuminate\Database\Eloquent\Casts\Attribute;
6+
use Illuminate\Database\Eloquent\Builder;
7+
use RectorLaravel\Tests\Rector\ClassMethod\MakeModelAttributesAndScopesProtectedRector\Source\ParentUser;
8+
9+
class User extends ParentUser
10+
{
11+
protected function firstName(): Attribute
12+
{
13+
return Attribute::get(fn () => ucfirst($this->first_name));
14+
}
15+
16+
public function scopeActive(Builder $query): Builder
17+
{
18+
return $query->where('active', true);
19+
}
20+
}
21+
22+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Rector\ClassMethod\MakeModelAttributesAndScopesProtectedRector\Source;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class ParentUser extends Model
9+
{
10+
public function scopeActive(Builder $query): Builder
11+
{
12+
return $query->where('active', true);
13+
}
14+
}

0 commit comments

Comments
 (0)