Passed
Push — master ( 4ca145...e39a6b )
by Jakub
02:24
created

MockCommandExtractor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extractFromRequest() 0 9 2
A willReturn() 0 10 2
A andThen() 0 4 1
A forArguments() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Eps\Req2CmdBundle\CommandExtractor;
5
6
use Symfony\Component\HttpFoundation\Request;
7
8
class MockCommandExtractor implements CommandExtractorInterface
9
{
10
    private $toReturn;
11
    private $toReturnForArgs;
12
    private $lastArgsHash;
13
14
    /**
15
     * MockCommandExtractor constructor.
16
     */
17
    public function __construct()
18
    {
19
        $this->toReturnForArgs = [];
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function extractFromRequest(Request $request, string $commandClass, array $additionalProps = [])
26
    {
27
        $paramsHash = serialize(func_get_args());
28
        if (array_key_exists($paramsHash, $this->toReturnForArgs)) {
29
            return $this->toReturnForArgs[$paramsHash];
30
        }
31
32
        return $this->toReturn;
33
    }
34
35
    public function willReturn($command): self
36
    {
37
        if ($this->lastArgsHash !== null) {
38
            $this->toReturnForArgs[$this->lastArgsHash] = $command;
39
        } else {
40
            $this->toReturn = $command;
41
        }
42
43
        return $this;
44
    }
45
46
    public function andThen(): self
47
    {
48
        return $this;
49
    }
50
51
    public function forArguments(Request $request, string $cmdClass, array $additionalProps = []): self
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $cmdClass is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $additionalProps is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        $this->lastArgsHash = serialize(func_get_args());
54
55
        return $this;
56
    }
57
}
58