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

getReflectionFactory()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 1
nop 0
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Parser\Tests\Reflection\ReflectionClass;
4
5
use ApiGen\Contracts\Configuration\ConfigurationInterface;
6
use ApiGen\Contracts\Parser\ParserStorageInterface;
7
use ApiGen\Contracts\Parser\Reflection\TokenReflection\ReflectionFactoryInterface;
8
use ApiGen\Parser\Broker\Backend;
9
use ApiGen\Parser\Reflection\ReflectionClass;
10
use ApiGen\Parser\Reflection\TokenReflection\ReflectionFactory;
11
use PHPUnit\Framework\TestCase;
12
use ReflectionProperty;
13
use TokenReflection\Broker;
14
15
abstract class AbstractReflectionClassTestCase extends TestCase
16
{
17
    /**
18
     * @var ReflectionClass
19
     */
20
    protected $reflectionClass;
21
22
    /**
23
     * @var ReflectionClass
24
     */
25
    protected $reflectionClassOfParent;
26
27
    /**
28
     * @var ReflectionClass
29
     */
30
    protected $reflectionClassOfTrait;
31
32
    /**
33
     * @var ReflectionClass
34
     */
35
    protected $reflectionClassOfInterface;
36
37
    protected function setUp(): void
38
    {
39
        $backend = new Backend($this->getReflectionFactory());
40
        $broker = new Broker($backend);
41
        $broker->processDirectory(__DIR__ . '/../ReflectionClassSource');
42
        $this->reflectionClass = $backend->getClasses()['Project\AccessLevels'];
0 ignored issues
show
Documentation Bug introduced by
$backend->getClasses()['Project\\AccessLevels'] is of type object<ApiGen\Contracts\...assReflectionInterface>, but the property $reflectionClass was declared to be of type object<ApiGen\Parser\Reflection\ReflectionClass>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
43
        $this->reflectionClassOfParent = $backend->getClasses()['Project\ParentClass'];
0 ignored issues
show
Documentation Bug introduced by
$backend->getClasses()['Project\\ParentClass'] is of type object<ApiGen\Contracts\...assReflectionInterface>, but the property $reflectionClassOfParent was declared to be of type object<ApiGen\Parser\Reflection\ReflectionClass>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
44
        $this->reflectionClassOfTrait = $backend->getClasses()['Project\SomeTrait'];
0 ignored issues
show
Documentation Bug introduced by
$backend->getClasses()['Project\\SomeTrait'] is of type object<ApiGen\Contracts\...assReflectionInterface>, but the property $reflectionClassOfTrait was declared to be of type object<ApiGen\Parser\Reflection\ReflectionClass>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
45
        $this->reflectionClassOfInterface = $backend->getClasses()['Project\RichInterface'];
0 ignored issues
show
Documentation Bug introduced by
$backend->getClasses()['Project\\RichInterface'] is of type object<ApiGen\Contracts\...assReflectionInterface>, but the property $reflectionClassOfInterface was declared to be of type object<ApiGen\Parser\Reflection\ReflectionClass>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
46
    }
47
48
    private function getReflectionFactory(): ReflectionFactoryInterface
49
    {
50
        // @todo: use $parserStorage from DI
51
        $parserStorageMock = $this->createMock(ParserStorageInterface::class);
52
        $parserStorageMock->method('getDirectImplementersOfInterface')->willReturn([1]);
53
        $parserStorageMock->method('getIndirectImplementersOfInterface')->willReturn([]);
54
        $parserStorageMock->method('getElementsByType')->willReturnCallback(function ($arg) {
55
            if ($arg) {
56
                return [
57
                    'Project\AccessLevels' => $this->reflectionClass,
58
                    'Project\ParentClass' => $this->reflectionClassOfParent,
59
                    'Project\SomeTrait' => $this->reflectionClassOfTrait,
60
                    'Project\RichInterface' => $this->reflectionClassOfInterface
61
                ];
62
            }
63
        });
64
65
        $configurationMock = $this->createMock(ConfigurationInterface::class);
66
        $configurationMock->method('getVisibilityLevel')
67
            ->willReturn(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
68
69
        return new ReflectionFactory($configurationMock, $parserStorageMock);
70
    }
71
}
72