CommandBus   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 26.87 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 18
loc 67
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 3
A handleCommand() 0 4 1
A handlePostMiddleWares() 9 9 3

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->preMiddleWareHasCommands($commandName)) {
48
            foreach ($this->optionsResolver->getPreMiddleWareOptions($commandName) as $preMiddleWareOption) {
49
                $this->container->get($preMiddleWareOption)->handle($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
        $commandName = '\\' . get_class($command);
68
        if (true === $this->optionsResolver->postMiddleWareHasCommands($commandName)) {
69
            foreach ($this->optionsResolver->getPostMiddleWareOptions($commandName) as $postMiddleWareOption) {
70
                $this->container->get($postMiddleWareOption)->handle($command);
71
            }
72
        }
73
    }
74
}
75