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

NamespaceSorterTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 6

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testSort() 0 9 1
A testSortNoneOnly() 0 6 1
A testIsNoneOnly() 0 5 1
A testAddMissingParentNamespaces() 0 12 1
A testAddMissingElementTypes() 0 14 1
A testCompareNamespaces() 0 7 1
A getCompareNamespacesData() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Parser\Tests\Elements;
4
5
use ApiGen\Contracts\Configuration\ConfigurationInterface;
6
use ApiGen\Contracts\Parser\Elements\NamespaceSorterInterface;
7
use ApiGen\Parser\Elements\Elements;
8
use ApiGen\Parser\Elements\NamespaceSorter;
9
use ApiGen\Tests\MethodInvoker;
10
use PHPUnit\Framework\Assert;
11
use PHPUnit\Framework\TestCase;
12
13
final class NamespaceSorterTest extends TestCase
14
{
15
    /**
16
     * @var NamespaceSorterInterface
17
     */
18
    private $namespaceSorter;
19
20
    protected function setUp(): void
21
    {
22
        $configurationMock = $this->createMock(ConfigurationInterface::class);
23
24
        $this->namespaceSorter = new NamespaceSorter(new Elements, $configurationMock);
0 ignored issues
show
Unused Code introduced by
The call to NamespaceSorter::__construct() has too many arguments starting with $configurationMock.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
25
    }
26
27
    public function testSort(): void
28
    {
29
        $groups = ['OneGroup' => [], 'OtherGroup' => [], 'OneMoreGroup' => []];
30
        $sortedGroups = $this->namespaceSorter->sort($groups);
31
        $this->assertCount(3, $sortedGroups);
32
        $this->assertArrayHasKey('OneGroup', $sortedGroups);
33
        $this->assertArrayHasKey('OtherGroup', $sortedGroups);
34
        $this->assertArrayHasKey('OneMoreGroup', $sortedGroups);
35
    }
36
37
    public function testSortNoneOnly(): void
38
    {
39
        $groups = ['None' => []];
40
        $sortedGroups = $this->namespaceSorter->sort($groups);
41
        $this->assertSame([], $sortedGroups);
42
    }
43
44
    public function testIsNoneOnly(): void
45
    {
46
        $groups['None'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$groups was never initialized. Although not strictly required by PHP, it is generally a good practice to add $groups = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
47
        $this->assertTrue(MethodInvoker::callMethodOnObject($this->namespaceSorter, 'isNoneOnly', [$groups]));
48
    }
49
50
    public function testAddMissingParentNamespaces(): void
51
    {
52
        $this->assertNull(Assert::getObjectAttribute($this->namespaceSorter, 'namespaces'));
53
        MethodInvoker::callMethodOnObject(
54
            $this->namespaceSorter, 'addMissingParentNamespaces', ['Some\Group\Name']
55
        );
56
57
        $groups = Assert::getObjectAttribute($this->namespaceSorter, 'namespaces');
58
        $this->assertArrayHasKey('Some\Group\Name', $groups);
59
        $this->assertArrayHasKey('Some\Group', $groups);
60
        $this->assertArrayHasKey('Some', $groups);
61
    }
62
63
    public function testAddMissingElementTypes(): void
64
    {
65
        MethodInvoker::callMethodOnObject($this->namespaceSorter, 'addMissingElementTypes', ['Some\Group']);
66
        $groups = Assert::getObjectAttribute($this->namespaceSorter, 'namespaces');
67
        $this->assertArrayHasKey('Some\Group', $groups);
68
69
        $someGroup = $groups['Some\Group'];
70
        $this->assertArrayHasKey('classes', $someGroup);
71
        $this->assertArrayHasKey('constants', $someGroup);
72
        $this->assertArrayHasKey('exceptions', $someGroup);
73
        $this->assertArrayHasKey('functions', $someGroup);
74
        $this->assertArrayHasKey('interfaces', $someGroup);
75
        $this->assertArrayHasKey('traits', $someGroup);
76
    }
77
78
    /**
79
     * @dataProvider getCompareNamespacesData()
80
     */
81
    public function testCompareNamespaces(string $one, string $two, int $expected): void
82
    {
83
        $this->assertSame(
84
            $expected,
85
            MethodInvoker::callMethodOnObject($this->namespaceSorter, 'compareNamespaceNames', [$one, $two])
86
        );
87
    }
88
89
    /**
90
     * @return mixed[]
91
     */
92
    public function getCompareNamespacesData(): array
93
    {
94
        return [
95
            ['GroupOne', 'OtherGroup', -8],
96
            ['One', 'Two', -5],
97
        ];
98
    }
99
}
100