Search by

bearsunday / rector-bearsunday

koriym

Rector upgrades rules for BEAR.Sunday Framework

Package info

github.com/bearsunday/rector-bearsunday

Type:rector-extension

pkg:composer/bearsunday/rector-bearsunday

Statistics

Installs: 202

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

1.1.1 2026-09-03 23:25 UTC

This package is auto-updated.

Last update: 2026-09-04 00:44:34 UTC


README

Rector rules to migrate BEAR.Sunday and Ray.Di applications from annotations to PHP 8 attributes.

Requirements

  • PHP 8.2+
  • Rector 2.0+

Installation

composer require --dev bearsunday/rector-bearsunday

Usage

Run Rector using the provided configuration file:

# Preview changes
vendor/bin/rector process src tests -c vendor/bearsunday/rector-bearsunday/rector.php --dry-run

# Apply changes
vendor/bin/rector process src tests -c vendor/bearsunday/rector-bearsunday/rector.php

Rules

RayDiNamedAnnotationRector

Converts @Named annotations on methods to #[Named] attributes on constructor parameters.

Before:

class SomeClass
{
    /**
     * @Named("a=foo, b=bar")
     */
    public function __construct(int $a, int $b)
    {
    }
}

After:

class SomeClass
{
    public function __construct(
        #[Named('foo')] int $a,
        #[Named('bar')] int $b
    ) {
    }
}

AnnotationToAttributeRector

Converts BEAR.Sunday and Ray.Di annotations to PHP 8 attributes.

The provided rector.php configuration includes rules for:

Ray.Di:

  • @Inject → #[Inject]
  • @Named → #[Named]
  • @PostConstruct → #[PostConstruct]
  • @Assisted → #[Assisted]
  • @Set → #[Set]
  • @Qualifier → #[Qualifier]

Ray.AuraSqlModule:

  • @ReadOnlyConnection → #[ReadOnlyConnection]
  • @WriteConnection → #[WriteConnection]
  • @Transactional → #[Transactional]

Ray.PsrCacheModule:

  • @CacheNamespace → #[CacheNamespace]
  • @Local → #[Local]
  • @Shared → #[Shared]
  • @CacheDir → #[CacheDir]

Ray.WebContextParam:

  • @CookieParam → #[CookieParam]
  • @EnvParam → #[EnvParam]
  • @FilesParam → #[FilesParam]
  • @FormParam → #[FormParam]
  • @QueryParam → #[QueryParam]
  • @ServerParam → #[ServerParam]

Ray.QueryModule:

  • @Query → #[Query]

Ray.RoleModule:

  • @RequiresRoles → #[RequiresRoles]

BEAR.Resource:

  • @AppName → #[AppName]
  • @ContextScheme → #[ContextScheme]
  • @Embed → #[Embed]
  • @ImportAppConfig → #[ImportAppConfig]
  • @Link → #[Link]
  • @OptionsBody → #[OptionsBody]
  • @ResourceParam → #[ResourceParam]

BEAR.Package:

  • @ReturnCreatedResource → #[ReturnCreatedResource]

BEAR.QueryRepository:

  • @Cacheable → #[Cacheable]
  • @Purge → #[Purge]
  • @Refresh → #[Refresh]

BEAR.Accept:

  • @Available → #[Available]
  • @Produces → #[Produces]

SetterToConstructorInjectionRector

Converts setter injection with #[Inject] to constructor injection.

Before:

class SomeClass
{
    private FooInterface $foo;

    #[Inject]
    public function setFoo(FooInterface $foo): void
    {
        $this->foo = $foo;
    }
}

After:

class SomeClass
{
    public function __construct(
        private readonly FooInterface $foo
    ) {
    }
}

TraitToConstructorInjectionRector

Converts trait-based injection to constructor injection.

Supported traits:

  • BEAR\Resource\ResourceInject → ResourceInterface $resource
  • BEAR\Sunday\Inject\ResourceInject → ResourceInterface $resource
  • BEAR\Sunday\Inject\PsrLoggerInject → LoggerInterface $logger
  • Ray\Di\InjectorInject → InjectorInterface $injector

Before:

use BEAR\Resource\ResourceInject;

class SomeClass
{
    use ResourceInject;
}

After:

use BEAR\Resource\ResourceInterface;

class SomeClass
{
    public function __construct(
        private readonly ResourceInterface $resource
    ) {
    }
}

ResourceObjectReturnTypeRector

Converts ResourceObject and self return types to static in resource methods.

Before:

class Article extends ResourceObject
{
    public function onGet(int $id): ResourceObject
    {
        return $this;
    }
}

After:

class Article extends ResourceObject
{
    public function onGet(int $id): static
    {
        return $this;
    }
}

See Also