Skip to content

Commit

Permalink
Split default value extension and apply PER-2
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Oct 17, 2023
1 parent 831ed0a commit 859b9cc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 252 deletions.
38 changes: 25 additions & 13 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Railt\Foundation\Event\Connection\ConnectionEstablished;
use Railt\Foundation\Event\Schema\SchemaCompiled;
use Railt\Foundation\Event\Schema\SchemaCompiling;
use Railt\Foundation\Extension\DefaultValueResolverExtension;
use Railt\Foundation\Extension\ExtensionInterface;
use Railt\Foundation\Extension\Repository;
use Railt\Http\Middleware\MutablePipelineInterface;
Expand All @@ -36,31 +35,44 @@ final class Application implements ApplicationInterface

/**
* @param iterable<array-key, MiddlewareInterface>|MutablePipelineInterface $middleware
* @param iterable<array-key, ExtensionInterface>|Repository $extensions
* @param iterable<array-key, ExtensionInterface> $extensions
*/
public function __construct(
private readonly ExecutorInterface $executor,
private readonly CompilerInterface $compiler = new Compiler(),
iterable|MutablePipelineInterface $middleware = [],
iterable|Repository $extensions = [],
iterable $extensions = [],
?EventDispatcherInterface $dispatcher = null,
) {
$this->pipeline = !$middleware instanceof MutablePipelineInterface
? new Pipeline($middleware)
: $middleware;
$this->extensions = !$extensions instanceof Repository
? new Repository($extensions)
: $extensions;
$this->dispatcher = new EventDispatcher($dispatcher);
/** @psalm-suppress PropertyTypeCoercion */
$this->connections = new \WeakMap();
$this->dispatcher = new EventDispatcher($dispatcher);
$this->extensions = $this->bootExtensions($extensions);
$this->pipeline = $this->bootPipeline($middleware);
}

$this->bootDefaultExtensions();
/**
* @param iterable<array-key, MiddlewareInterface>|MutablePipelineInterface $middleware
*/
private function bootPipeline(iterable|MutablePipelineInterface $middleware): MutablePipelineInterface
{
if ($middleware instanceof MutablePipelineInterface) {
return $middleware;
}

return new Pipeline($middleware);
}

private function bootDefaultExtensions(): void
/**
* @param iterable<array-key, ExtensionInterface> $extensions
*/
private function bootExtensions(iterable $extensions): Repository
{
$this->extensions->register(new DefaultValueResolverExtension());
if ($extensions instanceof Repository) {
return $extensions;
}

return new Repository($extensions);
}

public function extend(ExtensionInterface $extension): void
Expand Down
236 changes: 0 additions & 236 deletions src/Extension/DefaultValueResolverExtension.php

This file was deleted.

4 changes: 1 addition & 3 deletions tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
use PHPUnit\Framework\TestCase as BaseTestCase;

#[Group('railt/foundation')]
abstract class TestCase extends BaseTestCase
{
}
abstract class TestCase extends BaseTestCase {}

0 comments on commit 859b9cc

Please sign in to comment.