Completed
Push — refactor-04-parser-tests ( 553ee6...bce951 )
by John
03:05 queued 47s
created

SimpleXmlElementChainMocker::generateMockId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Graze\CiffRenderer\Test;
4
5
use Mockery as m;
6
use Mockery\MockInterface;
7
use Graze\CiffRenderer\Test\SimpleXmlElementMock;
8
9
class SimpleXmlElementChainMocker
10
{
11
    /**
12
     * Create a chain of SimpleXmlElement mocks.
13
     * @param string[] $properties
14
     * @param mixed $finalValue
15
     * @return MockInterface
16
     */
17
    public static function mock(array $properties = [], $finalValue = null)
18
    {
19
        $mock = m::mock(SimpleXmlElementMock::class.'[__get]');
20
        if (empty($properties)) {
21
            return $mock;
22
        }
23
24
        return self::addChain($mock, $properties, $finalValue);
25
    }
26
27
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$finalValue" missing
Loading history...
28
     * @param MockInterface $rootMock
29
     * @param string[] $properties
30
     * @param mixed $returnValue
0 ignored issues
show
Coding Style introduced by
Doc comment for parameter $returnValue does not match actual variable name $finalValue
Loading history...
31
     * @return \Mockery\MockInterface
32
     */
33
    public static function addChain(MockInterface $rootMock, array $properties, $finalValue)
0 ignored issues
show
Unused Code introduced by
The parameter $rootMock is not used and could be removed. ( Ignorable by Annotation )

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

33
    public static function addChain(/** @scrutinizer ignore-unused */ MockInterface $rootMock, array $properties, $finalValue)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $finalValue is not used and could be removed. ( Ignorable by Annotation )

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

33
    public static function addChain(MockInterface $rootMock, array $properties, /** @scrutinizer ignore-unused */ $finalValue)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        $countProperties = count($properties);
36
        if ($countProperties < 2) {
37
            throw new \RuntimeException('chains must have at least two links, consider using the [mock] method');
38
        }
39
40
        // start with the final call in the chain
41
        for ($i = $countProperties - 1; $i > 0; $i--) {
42
            $mock = self::mock($properties, $i)
43
                ->shouldReceive('__get')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with '__get'. ( Ignorable by Annotation )

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

43
                ->/** @scrutinizer ignore-call */ shouldReceive('__get')

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...
44
                ->with($properties[$i])
45
                ->once()
46
                ->andReturn($returnValue)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $returnValue does not seem to be defined for all execution paths leading up to this point.
Loading history...
47
                ->getMock();
48
49
            $returnValue = $mock;
50
        }
51
52
        return $mock;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $mock does not seem to be defined for all execution paths leading up to this point.
Loading history...
53
    }
54
}
55