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

AbstractMockingStrategy::setMockType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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