GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 4.2-to-master ( ed215f )
by E
06:47
created

CorrectContextForFunctionParameterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 58.49 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 31
loc 53
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test() 20 20 1
A createReflectionParameterInFunctionMock() 0 11 1
A createFunctionReflectionMock() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Tests\Generator\Resolvers\ElementResolver;
4
5
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface;
6
use ApiGen\Contracts\Parser\Reflection\ParameterReflectionInterface;
7
use ApiGen\Tests\MethodInvoker;
8
use PHPUnit_Framework_MockObject_MockObject;
9
10
final class CorrectContextForFunctionParameterTest extends AbstractElementResolverTest
11
{
12 View Code Duplication
    public function test(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    {
14
        $functionReflectionMock = $this->createFunctionReflectionMock();
15
16
        $this->parserStorage->setFunctions([
0 ignored issues
show
Documentation introduced by
array('SomeFunction' => $functionReflectionMock) is of type array<string,object<PHPU...ReflectionInterface>"}>, but the function expects a array<integer,object<Api...onReflectionInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
            'SomeFunction' => $functionReflectionMock
18
        ]);
19
20
        $reflectionParameterMock = $this->createReflectionParameterInFunctionMock();
21
22
        $resolvedElement = MethodInvoker::callMethodOnObject(
23
            $this->elementResolver,
24
            'correctContextForParameterOrClassMember',
25
            [$reflectionParameterMock]
26
        );
27
28
29
        $this->assertInstanceOf(FunctionReflectionInterface::class, $resolvedElement);
30
        $this->assertSame($functionReflectionMock, $resolvedElement);
31
    }
32
33
    /**
34
     * @return PHPUnit_Framework_MockObject_MockObject|ParameterReflectionInterface
35
     */
36
    private function createReflectionParameterInFunctionMock()
37
    {
38
        $reflectionParameterMock = $this->createMock(ParameterReflectionInterface::class);
39
        $reflectionParameterMock->method('getDeclaringClassName')
40
            ->willReturn('');
41
42
        $reflectionParameterMock->method('getDeclaringFunctionName')
43
            ->willReturn('SomeFunction');
44
45
        return $reflectionParameterMock;
46
    }
47
48
    /**
49
     * @return PHPUnit_Framework_MockObject_MockObject|FunctionReflectionInterface
50
     */
51 View Code Duplication
    private function createFunctionReflectionMock()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $functionReflectionMock = $this->createMock(FunctionReflectionInterface::class);
54
        $functionReflectionMock->method('getName')
55
            ->willReturn('SomeFunction');
56
57
        $functionReflectionMock->method('isDocumented')
58
            ->willReturn(true);
59
60
        return $functionReflectionMock;
61
    }
62
}
63