MockCommandExtractor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extractFromRequest() 0 9 2
A willReturn() 0 11 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([$request, $commandClass, $additionalProps]);
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
            return $this;
40
        }
41
42
        $this->toReturn = $command;
43
44
        return $this;
45
    }
46
47
    public function andThen(): self
48
    {
49
        return $this;
50
    }
51
52
    public function forArguments(Request $request, string $cmdClass, array $additionalProps = []): self
53
    {
54
        $this->lastArgsHash = serialize([$request, $cmdClass, $additionalProps]);
55
56
        return $this;
57
    }
58
}
59