Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"spiral/code-style": "^2.2.2",
"spiral/testing": "^2.9",
"rector/rector": "^2.0",
"vimeo/psalm": "^6.0"
"vimeo/psalm": "^6.0",
"savinmikhail/add_named_arguments_rector": "^0.1.19"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use SavinMikhail\AddNamedArgumentsRector\AddNamedArgumentsRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
Expand All @@ -22,4 +23,8 @@
$rectorConfig->skip([
__DIR__ . '/vendor',
]);

$rectorConfig->rules([
AddNamedArgumentsRector::class,
]);
};
3 changes: 1 addition & 2 deletions src/Application/Bootloader/ConfigurationBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function addLoader(string $ext, FileLoaderInterface $loader): void
private function createConfigManager(): ConfigManager
{
return new ConfigManager(
new DirectoryLoader($this->directories->get('config'), $this->loaders),
true,
loader: new DirectoryLoader(directory: $this->directories->get('config'), loaders: $this->loaders),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Application/Bootloader/ConsoleBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
public function init(AbstractKernel $kernel, BinderInterface $binder, Application $app): void
{
$kernel->bootstrapped(static function (AbstractKernel $kernel): void {
$kernel->addDispatcher(ConsoleDispatcher::class);
$kernel->addDispatcher(dispatcher: ConsoleDispatcher::class);
});

// Registering necessary scope bindings
Expand All @@ -53,7 +53,7 @@ public function addInterceptor(string ...$interceptors): void
foreach ($interceptors as $interceptor) {
$this->config->modify(
ConsoleConfig::CONFIG,
new Append('interceptors', null, $interceptor),
new Append(position: 'interceptors', key: null, value: $interceptor),
);
}
}
Expand All @@ -66,7 +66,7 @@ public function addCommand(string ...$commands): void
foreach ($commands as $command) {
$this->config->modify(
ConsoleConfig::CONFIG,
new Append('commands', null, $command),
new Append(position: 'commands', key: null, value: $command),
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Application/Bootloader/CoreBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface: \Butschster\ContextGenerator\DirectoriesInterface::class,

public function init(DirectoriesInterface $dirs, EnvironmentInterface $env): void
{
$this->loadEnvVariables($dirs, $env);
$this->loadEnvVariables(dirs: $dirs, env: $env);
}

public function boot(ConsoleBootloader $console): void
Expand All @@ -70,14 +70,14 @@ public function loadEnvVariables(DirectoriesInterface $dirs, EnvironmentInterfac

$dotenvPath = $env->get('DOTENV_PATH', $dirs->get('root') . '.env');

if (!\file_exists($dotenvPath)) {
if (!\file_exists(filename: $dotenvPath)) {
return;
}

$path = \dirname((string) $dotenvPath);
$file = \basename((string) $dotenvPath);
$path = \dirname(path: (string) $dotenvPath);
$file = \basename(path: (string) $dotenvPath);

foreach (Dotenv::createImmutable($path, $file)->load() as $key => $value) {
foreach (Dotenv::createImmutable(paths: $path, names: $file)->load() as $key => $value) {
$env->set($key, $value);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Bootloader/LoggerBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public function boot(BinderInterface $binder, ExceptionHandler $handler, FileSna
// Register injectable class
$binder->bindInjector(LoggerInterface::class, self::class);
$handler->addReporter(
new readonly class($snapshot) implements ExceptionReporterInterface {
reporter: new readonly class($snapshot) implements ExceptionReporterInterface {
public function __construct(
private FileSnapshot $fileSnapshot,
) {}

public function report(\Throwable $exception): void
{
$this->fileSnapshot->create($exception);
$this->fileSnapshot->create(e: $exception);
}
},
);
Expand All @@ -77,7 +77,7 @@ public function createInjection(\ReflectionClass $class, mixed $context = null):

$prefix = null;
if ($context instanceof \ReflectionParameter) {
$prefix = $this->findAttribute($context)?->prefix ?? $context->getDeclaringClass()->getShortName();
$prefix = $this->findAttribute(parameter: $context)?->prefix ?? $context->getDeclaringClass()->getShortName();
}

if (!$prefix) {
Expand All @@ -89,7 +89,7 @@ public function createInjection(\ReflectionClass $class, mixed $context = null):

private function findAttribute(\ReflectionParameter $parameter): ?LoggerPrefix
{
foreach ($parameter->getAttributes(LoggerPrefix::class) as $attribute) {
foreach ($parameter->getAttributes(name: LoggerPrefix::class) as $attribute) {
return $attribute->newInstance();
}

Expand Down
10 changes: 5 additions & 5 deletions src/Application/Directories.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ public function __construct(
private array $directories = [],
) {
foreach ($directories as $name => $directory) {
$this->set($name, $directory);
$this->set(name: $name, path: $directory);
}
}

public function has(string $name): bool
{
return \array_key_exists($name, $this->directories);
return \array_key_exists(key: $name, array: $this->directories);
}

public function set(string $name, string $path): DirectoriesInterface
{
$this->directories[$name] = \rtrim($path, '/') . '/';
$this->directories[$name] = \rtrim(string: $path, characters: '/') . '/';

return $this;
}

public function get(string $name): string
{
if (!$this->has($name)) {
throw new DirectoryException("Undefined directory '{$name}'");
if (!$this->has(name: $name)) {
throw new DirectoryException(message: "Undefined directory '{$name}'");
}

return $this->directories[$name];
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Dispatcher/ConsoleDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public function serve(?InputInterface $input = null, ?OutputInterface $output =
{
$input ??= new ArgvInput();
// On demand to save some memory.
$output ??= new SymfonyStyle($input, new ConsoleOutput());
$output ??= new SymfonyStyle(input: $input, output: new ConsoleOutput());

return $this->container->runScope(
bindings: new Scope(
name: 'console',
),
scope: function (Container $container) use ($input, $output) {
$console = $container->get(Console::class);
$console = $container->get(id: Console::class);

try {
return $console->run(
Expand All @@ -51,7 +51,7 @@ public function serve(?InputInterface $input = null, ?OutputInterface $output =
$output,
)->getCode();
} catch (\Throwable $e) {
$this->handleException($e, $output);
$this->handleException(exception: $e, output: $output);

return 255;
} finally {
Expand All @@ -67,7 +67,7 @@ protected function handleException(\Throwable $exception, OutputInterface $outpu
$output->write(
$this->errorHandler->render(
$exception,
verbosity: $this->mapVerbosity($output),
verbosity: $this->mapVerbosity(output: $output),
format: 'cli',
),
);
Expand Down
22 changes: 11 additions & 11 deletions src/Application/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ final class ExceptionHandler implements ExceptionHandlerInterface, LoggerAwareIn
public function __construct(
#[Proxy] LoggerInterface $logger,
) {
$this->setLogger($logger);
$this->setLogger(logger: $logger);
$this->handler = new \Spiral\Exceptions\ExceptionHandler();
$this->bootBasicHandlers();
}

public function getRenderer(?string $format = null): ?ExceptionRendererInterface
{
return $this->handler->getRenderer($format);
return $this->handler->getRenderer(format: $format);
}

public function setLogger(LoggerInterface $logger): void {}
Expand All @@ -46,58 +46,58 @@ public function render(
?Verbosity $verbosity = Verbosity::BASIC,
?string $format = null,
): string {
return $this->handler->render($exception, $verbosity, $format);
return $this->handler->render(exception: $exception, verbosity: $verbosity, format: $format);
}

public function canRender(string $format): bool
{
return $this->handler->canRender($format);
return $this->handler->canRender(format: $format);
}

public function report(\Throwable $exception): void
{
$this->handler->report($exception);
$this->handler->report(exception: $exception);
}

public function handleGlobalException(\Throwable $e): void
{
$this->handler->handleGlobalException($e);
$this->handler->handleGlobalException(e: $e);
}

/**
* Add renderer to the beginning of the renderers list
*/
public function addRenderer(ExceptionRendererInterface $renderer): void
{
$this->handler->addRenderer($renderer);
$this->handler->addRenderer(renderer: $renderer);
}

/**
* @param class-string<\Throwable> $exception
*/
public function dontReport(string $exception): void
{
$this->handler->dontReport($exception);
$this->handler->dontReport(exception: $exception);
}

/**
* @param ExceptionReporterInterface|\Closure(\Throwable):void $reporter
*/
public function addReporter(ExceptionReporterInterface|\Closure $reporter): void
{
$this->handler->addReporter($reporter);
$this->handler->addReporter(reporter: $reporter);
}

/**
* @param resource $output
*/
public function setOutput(mixed $output): void
{
$this->handler->setOutput($output);
$this->handler->setOutput(output: $output);
}

protected function bootBasicHandlers(): void
{
$this->addRenderer(new ConsoleRenderer());
$this->addRenderer(renderer: new ConsoleRenderer());
}
}
Loading
Loading