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

BackendTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Parser\Tests\Broker;
4
5
use ApiGen\Contracts\Configuration\ConfigurationInterface;
6
use ApiGen\Contracts\Parser\Broker\BackendInterface;
7
use ApiGen\Contracts\Parser\ParserStorageInterface;
8
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface;
9
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface;
10
use ApiGen\Contracts\Parser\Reflection\TokenReflection\ReflectionFactoryInterface;
11
use ApiGen\Parser\Broker\Backend;
12
use ApiGen\Parser\Reflection\TokenReflection\ReflectionFactory;
13
use PHPUnit\Framework\Assert;
14
use PHPUnit\Framework\TestCase;
15
use TokenReflection\Broker;
16
17
final class BackendTest extends TestCase
18
{
19
    /**
20
     * @var BackendInterface
21
     */
22
    private $backend;
23
24
    /**
25
     * @var Broker
26
     */
27
    private $broker;
28
29
    protected function setUp(): void
30
    {
31
        $this->backend = new Backend($this->getReflectionFactory());
32
        $this->broker = new Broker($this->backend);
33
    }
34
35 View Code Duplication
    public function testGetClasses(): 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...
36
    {
37
        $this->broker->processDirectory(__DIR__ . '/BackendSource');
38
        $classes = $this->backend->getClasses();
39
        $this->assertCount(1, $classes);
40
41
        $class = array_pop($classes);
42
        $this->assertInstanceOf(ClassReflectionInterface::class, $class);
43
44
        $this->checkLoadedProperties($class);
0 ignored issues
show
Bug introduced by
It seems like $class defined by array_pop($classes) on line 41 can be null; however, ApiGen\Parser\Tests\Brok...checkLoadedProperties() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
45
    }
46
47 View Code Duplication
    public function testGetFunctions(): 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
        $this->broker->processDirectory(__DIR__ . '/BackendSource');
50
        $functions = $this->backend->getFunctions();
51
        $this->assertCount(1, $functions);
52
53
        $function = array_pop($functions);
54
        $this->assertInstanceOf(FunctionReflectionInterface::class, $function);
55
56
        $this->checkLoadedProperties($function);
0 ignored issues
show
Bug introduced by
It seems like $function defined by array_pop($functions) on line 53 can be null; however, ApiGen\Parser\Tests\Brok...checkLoadedProperties() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
57
    }
58
59 View Code Duplication
    public function testGetConstants(): 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...
60
    {
61
        $this->broker->processDirectory(__DIR__ . '/BackendSource');
62
        $constants = $this->backend->getConstants();
63
        $this->assertCount(1, $constants);
64
65
        $constant = array_pop($constants);
66
        $this->assertInstanceOf('ApiGen\Parser\Reflection\ReflectionConstant', $constant);
67
68
        $this->checkLoadedProperties($constant);
0 ignored issues
show
Bug introduced by
It seems like $constant defined by array_pop($constants) on line 65 can be null; however, ApiGen\Parser\Tests\Brok...checkLoadedProperties() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
69
    }
70
71
    /**
72
     * @param object $object
73
     */
74 View Code Duplication
    private function checkLoadedProperties($object): 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...
75
    {
76
        $this->assertInstanceOf(
77
            ConfigurationInterface::class,
78
            Assert::getObjectAttribute($object, 'configuration')
79
        );
80
81
        $this->assertInstanceOf(
82
            ParserStorageInterface::class,
83
            Assert::getObjectAttribute($object, 'parserStorage')
84
        );
85
86
        $this->assertInstanceOf(
87
            ReflectionFactoryInterface::class,
88
            Assert::getObjectAttribute($object, 'reflectionFactory')
89
        );
90
    }
91
92 View Code Duplication
    private function getReflectionFactory(): ReflectionFactory
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...
93
    {
94
        $parserStoragetMock = $this->createMock(ParserStorageInterface::class);
95
        $configurationMock = $this->createMock(ConfigurationInterface::class);
96
        $configurationMock->method('getVisibilityLevel')
97
            ->willReturn(1);
98
99
        return new ReflectionFactory($configurationMock, $parserStoragetMock);
100
    }
101
}
102