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

AbstractMockingStrategy::checkMockType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
crap 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