Code Duplication    Length = 39-39 lines in 2 locations

src/Resolver/MiddlewareResolver.php 1 location

@@ 9-47 (lines=39) @@
6
use N1215\Jugoya\Wrapper\CallableMiddleware;
7
use Psr\Container\ContainerInterface;
8
9
final class MiddlewareResolver implements MiddlewareResolverInterface
10
{
11
    use ResolverTrait;
12
13
    /**
14
     * @var ContainerInterface
15
     */
16
    protected $container;
17
18
    /**
19
     * @param ContainerInterface $container
20
     */
21
    public function __construct(ContainerInterface $container)
22
    {
23
        $this->container = $container;
24
    }
25
26
    /**
27
     * @param string|callable|MiddlewareInterface $ref
28
     * @return MiddlewareInterface
29
     * @throws UnresolvedException
30
     */
31
    public function resolve($ref): MiddlewareInterface
32
    {
33
        if ($ref instanceof MiddlewareInterface) {
34
            return $ref;
35
        }
36
37
        if (is_callable($ref)) {
38
            return new CallableMiddleware($ref);
39
        }
40
41
        if (!is_string($ref)) {
42
            throw new \InvalidArgumentException('Argument 1 $ref must be one of an instance of MiddlewareInterface, a callable or string.');
43
        }
44
45
        return $this->resolveByContainer($ref, $this->container, MiddlewareInterface::class);
46
    }
47
}
48

src/Resolver/RequestHandlerResolver.php 1 location

@@ 9-47 (lines=39) @@
6
use N1215\Jugoya\Wrapper\CallableHandler;
7
use Psr\Container\ContainerInterface;
8
9
final class RequestHandlerResolver implements RequestHandlerResolverInterface
10
{
11
    use ResolverTrait;
12
13
    /**
14
     * @var ContainerInterface
15
     */
16
    protected $container;
17
18
    /**
19
     * @param ContainerInterface $container
20
     */
21
    public function __construct(ContainerInterface $container)
22
    {
23
        $this->container = $container;
24
    }
25
26
    /**
27
     * @param string|callable|RequestHandlerInterface $ref
28
     * @return RequestHandlerInterface
29
     * @throws UnresolvedException
30
     */
31
    public function resolve($ref): RequestHandlerInterface
32
    {
33
        if ($ref instanceof RequestHandlerInterface) {
34
            return $ref;
35
        }
36
37
        if (is_callable($ref)) {
38
            return new CallableHandler($ref);
39
        }
40
41
        if (!is_string($ref)) {
42
            throw new \InvalidArgumentException('Argument 1 $ref must be one of an instance of HandlerInterface, a callable or string.');
43
        }
44
45
        return $this->resolveByContainer($ref, $this->container, RequestHandlerInterface::class);
46
    }
47
}
48