Skip to content

[Bug] Undefined constant Rector\ValueObject\Visibility::PROTECTED #423

Description

@emresasy

When running Rector with driftingly/rector-laravel, I encounter a fatal error on several model and trait files that contain protected static function boot() methods.

[ERROR] Could not process "app/Models/Type.php" file, due to:
"System error: "Undefined constant Rector\ValueObject\Visibility::PROTECTED"
Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 96

Environment

  • PHP Version: 8.3.22
  • Laravel Version: 12.x
  • Rector Version: 2.2.8
  • RectorLaravel Version: 2.1.3

Rector Configuration

`<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use RectorLaravel\Set\LaravelSetList;
use RectorLaravel\Set\LaravelSetProvider;

return RectorConfig::configure()
->withSetProviders(LaravelSetProvider::class)
->withComposerBased(laravel: true)
->withSets([
LaravelSetList::LARAVEL_CODE_QUALITY,
])
->withPaths([
DIR . '/app',
DIR . '/config',
DIR . '/routes',
DIR . '/tests',
]);`

How to Reproduce

  1. Install driftingly/rector-laravel: ^2.1
  2. Create a trait or model with a protected static function boot*() method:

`<?php

namespace App\Traits;

use Illuminate\Database\Eloquent\Builder;

trait HasActive
{
protected static function bootHasActive(): void
{
static::addGlobalScope('active', function (Builder $builder) {
$builder->where('is_active', true);
});
}
}`

  1. Run: ./vendor/bin/rector process --dry-run

Affected Files

The error occurs on files containing protected static methods:

  • app/Models/Type.php
  • app/Models/TypeGroup.php
  • app/Models/UserPlatformAuthorization.php
  • app/Models/AdvertiserPlatformAccount.php
  • app/Traits/HasActive.php
  • app/Traits/ResultType.php

All errors occur around line 96 where protected static function boot() methods are defined.

Expected Behavior

Rector should analyze these files without errors.

Actual Behavior

Rector fails with Undefined constant Rector\ValueObject\Visibility::PROTECTED error when processing files with protected static methods.

Additional Context

  • Other files (75 files) are processed successfully
  • The error seems to be related to method visibility detection
  • Possibly a version incompatibility between Rector 2.2.8 and RectorLaravel 2.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions