Completed
Pull Request — master (#6)
by Alberto
04:09
created

AbstractMockingStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 38
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setMockType() 0 4 1
A checkMockType() 0 16 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Strategy;
5
6
use Moka\Exception\InvalidArgumentException;
7
use Moka\Exception\NotImplementedException;
8
9
/**
10
 * Class AbstractMockingStrategy
11
 * @package Moka\Strategy
12
 */
13
abstract class AbstractMockingStrategy implements MockingStrategyInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $mockType;
19
20
    /**
21
     * @param string $fqcn
22
     */
23 13
    final protected function setMockType(string $fqcn)
24
    {
25 13
        $this->mockType = $fqcn;
26
    }
27
28
    /**
29
     * @param object $mock
30
     *
31
     * @throws NotImplementedException
32
     * @throws InvalidArgumentException
33
     */
34 20
    final protected function checkMockType($mock)
35
    {
36 20
        if (!$this->mockType) {
37 1
            throw new NotImplementedException();
38
        }
39
40 19
        if (!is_a($mock, $this->mockType)) {
41 4
            throw new InvalidArgumentException(
42 4
                sprintf(
43 4
                    'Mock must be of type %s, %s given',
44 4
                    $this->mockType,
45 4
                    gettype($mock)
46
                )
47
            );
48
        }
49
    }
50
}
51