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

ElementSorterTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 116
Duplicated Lines 75.86 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 88
loc 116
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testSortElementsByFqnConstants() 21 21 1
A testSortElementsByFqnFunctions() 21 21 1
B testSortElementsByFqnMethod() 25 25 1
A testSortElementsByFqnProperties() 21 21 1
A testSortElementsByFqnNonSupportedType() 0 6 1
A testSortElementsByFqnWithEmptyArray() 0 4 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\Parser\Tests\Elements;
4
5
use ApiGen\Contracts\Parser\Reflection\Behavior\InClassInterface;
6
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface;
7
use ApiGen\Contracts\Parser\Reflection\ConstantReflectionInterface;
8
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface;
9
use ApiGen\Parser\Elements\ElementSorter;
10
use ApiGen\Parser\Reflection\TokenReflection\ReflectionInterface;
11
use PHPUnit\Framework\TestCase;
12
13
final class ElementSorterTest extends TestCase
14
{
15
    /**
16
     * @var ElementSorter
17
     */
18
    private $elementSorter;
19
20
    protected function setUp(): void
21
    {
22
        $this->elementSorter = new ElementSorter;
23
    }
24
25 View Code Duplication
    public function testSortElementsByFqnConstants(): 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...
26
    {
27
        $constantReflectionMock = $this->createMock(ConstantReflectionInterface::class);
28
        $constantReflectionMock->method('getDeclaringClassName')
29
            ->willReturn('B');
30
        $constantReflectionMock->method('getName')
31
            ->willReturn('C');
32
33
        $constantReflectionMock2 = $this->createMock(ConstantReflectionInterface::class);
34
        $constantReflectionMock2->method('getDeclaringClassName')
35
            ->willReturn('A');
36
        $constantReflectionMock2->method('getName')
37
            ->willReturn('D');
38
39
        $elements = [$constantReflectionMock, $constantReflectionMock2];
40
41
        $sortedElements = $this->elementSorter->sortElementsByFqn($elements);
42
        $this->assertNotSame($elements, $sortedElements);
43
        $this->assertSame($constantReflectionMock2, $sortedElements[0]);
44
        $this->assertSame($constantReflectionMock, $sortedElements[1]);
45
    }
46
47 View Code Duplication
    public function testSortElementsByFqnFunctions(): 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...
48
    {
49
        $reflectionFunctionMock = $this->createMock(FunctionReflectionInterface::class);
50
        $reflectionFunctionMock->method('getNamespaceName')
51
            ->willReturn('B');
52
        $reflectionFunctionMock->method('getName')
53
            ->willReturn('C');
54
55
        $reflectionFunctionMock2 = $this->createMock(FunctionReflectionInterface::class);
56
        $reflectionFunctionMock2->method('getNamespaceName')
57
            ->willReturn('A');
58
        $reflectionFunctionMock2->method('getName')
59
            ->willReturn('D');
60
61
        $elements = [$reflectionFunctionMock, $reflectionFunctionMock2];
62
63
        $sortedElements = $this->elementSorter->sortElementsByFqn($elements);
64
        $this->assertNotSame($elements, $sortedElements);
65
        $this->assertSame($reflectionFunctionMock2, $sortedElements[0]);
66
        $this->assertSame($reflectionFunctionMock, $sortedElements[1]);
67
    }
68
69 View Code Duplication
    public function testSortElementsByFqnMethod(): 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...
70
    {
71
        $reflectionMethodMock = $this->createMock(
72
            [ReflectionInterface::class, InClassInterface::class]
0 ignored issues
show
Documentation introduced by
array(\ApiGen\Parser\Ref...nClassInterface::class) is of type array<integer,?>, but the function expects a string.

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...
73
        );
74
        $reflectionMethodMock->method('getDeclaringClassName')
75
            ->willReturn('B');
76
        $reflectionMethodMock->method('getName')
77
            ->willReturn('C');
78
79
        $reflectionMethodMock2 = $this->createMock(
80
            [ReflectionInterface::class, InClassInterface::class]
0 ignored issues
show
Documentation introduced by
array(\ApiGen\Parser\Ref...nClassInterface::class) is of type array<integer,?>, but the function expects a string.

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...
81
        );
82
        $reflectionMethodMock2->method('getDeclaringClassName')
83
            ->willReturn('A');
84
        $reflectionMethodMock2->method('getName')
85
            ->willReturn('D');
86
87
        $elements = [$reflectionMethodMock, $reflectionMethodMock2];
88
89
        $sortedElements = $this->elementSorter->sortElementsByFqn($elements);
90
        $this->assertNotSame($elements, $sortedElements);
91
        $this->assertSame($reflectionMethodMock2, $sortedElements[0]);
92
        $this->assertSame($reflectionMethodMock, $sortedElements[1]);
93
    }
94
95 View Code Duplication
    public function testSortElementsByFqnProperties(): 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...
96
    {
97
        $reflectionMethodMock = $this->createMock([ReflectionInterface::class, InClassInterface::class]);
0 ignored issues
show
Documentation introduced by
array(\ApiGen\Parser\Ref...nClassInterface::class) is of type array<integer,?>, but the function expects a string.

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...
98
        $reflectionMethodMock->method('getDeclaringClassName')
99
            ->willReturn('B');
100
        $reflectionMethodMock->method('getName')
101
            ->willReturn('C');
102
103
        $reflectionMethodMock2 = $this->createMock([ReflectionInterface::class, InClassInterface::class]);
0 ignored issues
show
Documentation introduced by
array(\ApiGen\Parser\Ref...nClassInterface::class) is of type array<integer,?>, but the function expects a string.

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...
104
        $reflectionMethodMock2->method('getDeclaringClassName')
105
            ->willReturn('A');
106
        $reflectionMethodMock2->method('getName')
107
            ->willReturn('D');
108
109
        $elements = [$reflectionMethodMock, $reflectionMethodMock2];
110
111
        $sortedElements = $this->elementSorter->sortElementsByFqn($elements);
112
        $this->assertNotSame($elements, $sortedElements);
113
        $this->assertSame($reflectionMethodMock2, $sortedElements[0]);
114
        $this->assertSame($reflectionMethodMock, $sortedElements[1]);
115
    }
116
117
    public function testSortElementsByFqnNonSupportedType(): void
118
    {
119
        $reflectionClassMock = $this->createMock(ClassReflectionInterface::class);
120
        $sortedElements = $this->elementSorter->sortElementsByFqn([$reflectionClassMock]);
121
        $this->assertSame([$reflectionClassMock], $sortedElements);
122
    }
123
124
    public function testSortElementsByFqnWithEmptyArray(): void
125
    {
126
        $this->assertSame([], $this->elementSorter->sortElementsByFqn([]));
127
    }
128
}
129