Skip to content

Commit

Permalink
Attribute methods can be protected
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Nov 16, 2022
1 parent cac79bb commit a412308
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function execute(Model $model): void
*/
private function findAttributeMethods(Model $model): array
{
return collect((new ReflectionClass($model->fqcn))->getMethods(ReflectionMethod::IS_PUBLIC))
return collect((new ReflectionClass($model->fqcn))->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED))
->filter(fn (ReflectionMethod $method): bool => !$method->isStatic())
->filter(fn (ReflectionMethod $method): bool => $this->isAttributeMethod($method))
->all();
Expand All @@ -86,7 +86,7 @@ private function isAttributeMethod(ReflectionMethod $method): bool
*/
private function getAttributeGetterAndSetter(Model $model, string $attributeMethod): array
{
$attribute = $model->instance()->{$attributeMethod}();
$attribute = (fn () => $this->{$attributeMethod}())->call($model->instance());

return [
$attribute->get !== null ? new ReflectionFunction($attribute->get) : null,
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/User.stub
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class User extends Model
return $this->hasMany(Post::class);
}

public function city(): Attribute
protected function city(): Attribute
{
return new Attribute(
get: fn (): ?string => $this->address->city()
Expand Down

0 comments on commit a412308

Please sign in to comment.