Code Duplication    Length = 33-34 lines in 2 locations

src/CommandBus/Resolver/InteropContainerResolver.php 1 location

@@ 21-53 (lines=33) @@
18
/**
19
 * Class InteropContainerResolver.
20
 */
21
class InteropContainerResolver implements CommandHandlerResolver
22
{
23
    /** @var ContainerInterface */
24
    protected $container;
25
26
    /**
27
     * InteropContainerResolver constructor.
28
     *
29
     * @param ContainerInterface $container
30
     */
31
    public function __construct(ContainerInterface $container)
32
    {
33
        $this->container = $container;
34
    }
35
36
    /**
37
     * Given a string to identify the Command Handler, return the instance.
38
     *
39
     * @param string $handler
40
     *
41
     * @return CommandHandler
42
     */
43
    public function instantiate(string $handler) : CommandHandler
44
    {
45
        if (false === $this->container->has($handler)) {
46
            throw new InvalidArgumentException(
47
                sprintf('Handler %s could not be found. Did you register it?', $handler)
48
            );
49
        }
50
51
        return $this->container->get($handler);
52
    }
53
}
54

src/CommandBus/Resolver/SymfonyContainerResolver.php 1 location

@@ 21-54 (lines=34) @@
18
/**
19
 * Class SymfonyContainerResolver.
20
 */
21
class SymfonyContainerResolver implements CommandHandlerResolver
22
{
23
    /** @var ContainerInterface */
24
    protected $container;
25
26
    /**
27
     * SymfonyContainerResolver constructor.
28
     *
29
     * @param ContainerInterface $container
30
     */
31
    public function __construct(ContainerInterface $container)
32
    {
33
        $this->container = $container;
34
    }
35
36
    /**
37
     * Given a string to identify the Command Handler, return the instance.
38
     *
39
     * @param string $handler
40
     *
41
     * @return CommandHandler
42
     */
43
    public function instantiate(string $handler) : CommandHandler
44
    {
45
        $handler = ltrim($handler, '\\');
46
        if (false === $this->container->has($handler)) {
47
            throw new InvalidArgumentException(
48
                sprintf('Handler %s could not be found. Did you register it?', $handler)
49
            );
50
        }
51
52
        return $this->container->get($handler);
53
    }
54
}
55