Completed
Push — master ( ca729a...c6cc13 )
by Constantin
02:37
created

CommandTesterWithValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 33
loc 33
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A canExecuteCommand() 10 10 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
 * Copyright (c) 2017 Constantin Galbenu <[email protected]>
4
 */
5
6
namespace Gica\Cqrs\Command\CommandTester;
7
8
9
use Gica\Cqrs\Command;
10
use Gica\Cqrs\Command\CommandTester;
11
use Gica\Cqrs\Command\CommandValidator;
12
13 View Code Duplication
class CommandTesterWithValidator implements CommandTester
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
16
    /**
17
     * @var CommandTester
18
     */
19
    private $commandTester;
20
    /**
21
     * @var CommandValidator
22
     */
23
    private $commandValidator;
24
25 3
    public function __construct(
26
        CommandTester $commandTester,
27
        CommandValidator $commandValidator
28
29
    )
30
    {
31 3
        $this->commandTester = $commandTester;
32 3
        $this->commandValidator = $commandValidator;
33 3
    }
34
35 3
    public function canExecuteCommand(Command $command): bool
36
    {
37 3
        $errors = $this->commandValidator->validateCommand($command);
38
39 3
        if (!empty($errors)) {
40 2
            return false;
41
        }
42
43 1
        return $this->commandTester->canExecuteCommand($command);
44
    }
45
}