diff --git a/rector.php b/rector.php index 83f6fd650..437e3d36f 100644 --- a/rector.php +++ b/rector.php @@ -17,6 +17,7 @@ use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; +use Rector\Php81\Rector\ClassMethod\NewInInitializerRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; return RectorConfig::configure() @@ -80,6 +81,7 @@ RemoveUnusedPublicMethodParameterRector::class, RemoveEmptyClassMethodRector::class, RemoveUnusedPromotedPropertyRector::class, + NewInInitializerRector::class, // start with short open tag __DIR__ . '/src/Views/tests/fixtures/other/var.php', diff --git a/src/Queue/src/Interceptor/Consume/Handler.php b/src/Queue/src/Interceptor/Consume/Handler.php index 3d86114f2..b09a94a3c 100644 --- a/src/Queue/src/Interceptor/Consume/Handler.php +++ b/src/Queue/src/Interceptor/Consume/Handler.php @@ -19,12 +19,14 @@ */ final class Handler { + private readonly TracerFactoryInterface $tracerFactory; private readonly bool $isLegacy; public function __construct( private readonly HandlerInterface|CoreInterface $core, - private readonly TracerFactoryInterface $tracerFactory = new NullTracerFactory(new Container()), + ?TracerFactoryInterface $tracerFactory = null, ) { + $this->tracerFactory = $tracerFactory ?? new NullTracerFactory(new Container()); $this->isLegacy = !$core instanceof HandlerInterface; } diff --git a/src/Router/src/Router.php b/src/Router/src/Router.php index 5199601f5..7905df506 100644 --- a/src/Router/src/Router.php +++ b/src/Router/src/Router.php @@ -44,14 +44,16 @@ final class Router implements RouterInterface private array $routes = []; private ?RouteInterface $default = null; + private readonly TracerInterface $tracer; public function __construct( string $basePath, private readonly UriHandler $uriHandler, private readonly ContainerInterface $container, private readonly ?EventDispatcherInterface $eventDispatcher = null, - private readonly TracerInterface $tracer = new NullTracer(), + ?TracerInterface $tracer = null, ) { + $this->tracer = $tracer ?? new NullTracer(); $this->basePath = '/' . \ltrim($basePath, '/'); } diff --git a/src/Router/src/UriHandler.php b/src/Router/src/UriHandler.php index 3ad70e9fc..9630bd498 100644 --- a/src/Router/src/UriHandler.php +++ b/src/Router/src/UriHandler.php @@ -34,6 +34,8 @@ final class UriHandler ]; private ?string $pattern = null; + + private readonly RoutePatternRegistryInterface $patternRegistry; private array $constrains = []; private array $defaults = []; private bool $matchHost = false; @@ -54,8 +56,10 @@ final class UriHandler public function __construct( private readonly UriFactoryInterface $uriFactory, SlugifyInterface $slugify = null, - private readonly RoutePatternRegistryInterface $patternRegistry = new DefaultPatternRegistry(), + ?RoutePatternRegistryInterface $patternRegistry = null, ) { + $this->patternRegistry = $patternRegistry ?? new DefaultPatternRegistry(); + $slugify ??= new Slugify(); $this->pathSegmentEncoder = static fn (string $segment): string => $slugify->slugify($segment); } diff --git a/src/Views/src/ViewManager.php b/src/Views/src/ViewManager.php index cf038ad6e..3ec28752b 100644 --- a/src/Views/src/ViewManager.php +++ b/src/Views/src/ViewManager.php @@ -12,6 +12,7 @@ final class ViewManager implements ViewsInterface { private readonly LoaderInterface $loader; private ?ViewCache $cache = null; + private ContextInterface $context; /** @var EngineInterface[] */ private array $engines = []; @@ -20,8 +21,9 @@ public function __construct( private readonly ViewsConfig $config, private readonly GlobalVariablesInterface $globalVariables, FactoryInterface $factory, - private ContextInterface $context = new ViewContext() + ?ContextInterface $context = null ) { + $this->context = $context ?? new ViewContext(); $this->loader = $factory->make(LoaderInterface::class, [ 'namespaces' => $config->getNamespaces(), ]);