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
Pull Request — master (#14)
by Brent
03:44 queued 01:16
created

resolveUseStatements()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 4
nc 4
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spatie\DataTransferObject;
6
7
use ReflectionProperty;
8
use ReflectionClass as BaseReflectionClass;
9
10
class DataTransferObjectDefinition extends BaseReflectionClass
11
{
12
    /** @var array */
13
    protected $uses = [];
14
15
    /** @var \Spatie\DataTransferObject\DataTransferObject */
16
    protected $dataTransferObject;
17
18
    public function __construct(DataTransferObject $dataTransferObject)
19
    {
20
        parent::__construct($dataTransferObject);
21
22
        $this->dataTransferObject = $dataTransferObject;
23
24
        $this->resolveUseStatements();
25
    }
26
27
    protected function resolveUseStatements()
28
    {
29
        $handle = fopen($this->getFileName(), 'r');
30
31
        while ($line = fgets($handle)) {
32
            $line = trim($line);
33
34
            if (strpos($line, 'use ') !== 0) {
35
                continue;
36
            }
37
38
            $fqcn = str_replace(['use ', ';'], '', $line);
39
40
            $classParts = explode('\\', $fqcn);
41
42
            $alias = end($classParts);
43
44
            $this->uses[$alias] = $fqcn;
45
46
            if (strpos($line, 'class') !== false) {
47
                break;
48
            }
49
        }
50
51
        fclose($handle);
52
    }
53
54
    public function hasAlias(string $alias): bool
55
    {
56
        return isset($this->uses[$alias]);
57
    }
58
59
    public function resolveAlias(string $alias): string
60
    {
61
        return $this->uses[$alias];
62
    }
63
64
    /**
65
     * @return \Spatie\DataTransferObject\DataTransferObjectProperty[]
66
     */
67
    public function getDataTransferObjectProperties(): array
68
    {
69
        $properties = [];
70
71
        foreach (parent::getProperties(ReflectionProperty::IS_PUBLIC) as $reflectionProperty) {
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getProperties() instead of getDataTransferObjectProperties()). Are you sure this is correct? If so, you might want to change this to $this->getProperties().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
72
            $properties[$reflectionProperty->getName()] = DataTransferObjectProperty::fromReflection(
73
                $this->dataTransferObject,
74
                $this,
75
                $reflectionProperty
76
            );
77
        }
78
79
        return $properties;
80
    }
81
}
82