Completed
Push — master ( 9466a4...206d9f )
by Pablo
04:08
created

CommandBus   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 25.76 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 17
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 6 1
A handlePreMiddleWares() 9 9 2
A handleCommand() 0 4 1
A handlePostMiddleWares() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Bruli\EventBusBundle\CommandBus;
4
5
use Bruli\EventBusBundle\BusOptionsResolver;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
8
class CommandBus
9
{
10
    /**
11
     * @var ContainerInterface
12
     */
13
    private $container;
14
    /**
15
     * @var BusOptionsResolver
16
     */
17
    private $optionsResolver;
18
19
    /**
20
     * CommandBus constructor.
21
     *
22
     * @param ContainerInterface $container
23
     * @param BusOptionsResolver $optionsResolver
24
     */
25
    public function __construct(ContainerInterface $container, BusOptionsResolver $optionsResolver)
26
    {
27
        $this->container = $container;
28
        $this->optionsResolver = $optionsResolver;
29
    }
30
31
    /**
32
     * @param CommandInterface $command
33
     */
34
    public function handle(CommandInterface $command)
35
    {
36
        $this->handlePreMiddleWares($command);
37
        $this->handleCommand($command);
38
        $this->handlePostMiddleWares($command);
39
    }
40
41
    /**
42
     * @param CommandInterface $command
43
     */
44 View Code Duplication
    private function handlePreMiddleWares(CommandInterface $command)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $commandName = '\\' . get_class($command);
47
        if (true === $this->optionsResolver->preMiddleWareHasCommand($commandName)) {
48
            $this->container->get($this->optionsResolver->getPreMiddleWareOption($commandName))->handle(
49
                $command
50
            );
51
        }
52
    }
53
54
    /**
55
     * @param CommandInterface $command
56
     */
57
    private function handleCommand(CommandInterface $command)
58
    {
59
        $this->container->get($this->optionsResolver->getOption('\\' . get_class($command)))->handle($command);
60
    }
61
62
    /**
63
     * @param CommandInterface $command
64
     */
65 View Code Duplication
    private function handlePostMiddleWares(CommandInterface $command)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        if (true === $this->optionsResolver->postMiddleWareHasCommand(get_class($command))) {
68
            $this->container->get($this->optionsResolver->getPostMiddleWareOption('\\' . get_class($command)))->handle(
69
                $command
70
            );
71
        }
72
    }
73
}
74