Passed
Branch master (df1ab7)
by Thanos
01:48
created

StubConfiguration   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 50
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getInitialStub() 0 10 2
A getMockClassName() 0 3 1
A setStubConfigurationArray() 0 4 1
A getStub() 0 14 3
1
<?php
2
3
namespace Amock;
4
5
use PHPUnit\Framework\TestCase;
6
7
class StubConfiguration
8
{
9
    private $stubConfiguration;
10
11
    private $testCase;
12
13
    private $className;
14
15 19
    public function __construct(TestCase $testCase)
16
    {
17 19
        $this->testCase = $testCase;
18 19
    }
19
20 19
    public function setStubConfigurationArray(array $stubConfiguration): void
21
    {
22 19
        $this->stubConfiguration = $stubConfiguration;
23 19
        $this->className = $this->getMockClassName($stubConfiguration);
0 ignored issues
show
Unused Code introduced by
The call to Amock\StubConfiguration::getMockClassName() has too many arguments starting with $stubConfiguration. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        /** @scrutinizer ignore-call */ 
24
        $this->className = $this->getMockClassName($stubConfiguration);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
24 19
    }
25
26 19
    public function getStub()
27
    {
28 19
        if (empty($this->stubConfiguration)) {
29 1
            throw new Parser\Exception\ParseException();
30
        }
31
32 18
        $stub = $this->getInitialStub();
33
34 18
        foreach ($this->stubConfiguration[$this->className]['mockMethods'] as $methodName => $methodMockConfig) {
35 18
            (new MockMethod\Resolver($this->testCase, $stub, $methodName, $methodMockConfig))
36 18
                ->resolveAndModifyStub();
37
        }
38
39 18
        return $stub;
40
    }
41
42 18
    private function getInitialStub()
43
    {
44 18
        if ($this->stubConfiguration[$this->className]['disableConstructor'] == true) {
45 18
            return $this->testCase->getMockBuilder($this->className)
46 18
                ->disableOriginalConstructor()
47 18
                ->getMock();
48
        }
49
50
        return $this->testCase->getMockBuilder($this->className)
51
            ->getMock();
52
    }
53
54 19
    private function getMockClassName()
55
    {
56 19
        return key($this->stubConfiguration);
57
    }
58
}
59
60