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 — develop (#1)
by Hugues
03:07
created

ReflectionClass.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Reflection;
5
6
use Innmind\Reflection\InjectionStrategy\DefaultInjectionStrategies;
7
use Innmind\Reflection\InjectionStrategy\InjectionStrategies;
8
use Innmind\Reflection\Instanciator\ReflectionInstanciator;
9
use Innmind\Immutable\Collection;
10
use Innmind\Immutable\CollectionInterface;
11
use Innmind\Immutable\TypedCollectionInterface;
12
13
class ReflectionClass
14
{
15
    private $class;
16
    private $properties;
17
    private $injectionStrategies;
18
    private $instanciator;
19
20 5
    public function __construct(
21
        string $class,
22
        CollectionInterface $properties = null,
23
        InjectionStrategies $injectionStrategies = null,
24
        InstanciatorInterface $instanciator = null
25
    ) {
26 5
        $injectionStrategies = $injectionStrategies ?? new DefaultInjectionStrategies();
27
28 5
        $this->class = $class;
29 5
        $this->properties = $properties ?? new Collection([]);
30 5
        $this->injectionStrategies = $injectionStrategies;
31 5
        $this->instanciator = $instanciator ?? new ReflectionInstanciator;
32 5
    }
33
34
    /**
35
     * Add a property to be injected in the new object
36
     *
37
     * @param string $property
38
     * @param mixed $value
39
     *
40
     * @return self
41
     */
42 2
    public function withProperty(string $property, $value): self
43
    {
44 2
        return new self(
45 2
            $this->class,
46 2
            $this->properties->set($property, $value),
47 2
            $this->injectionStrategies,
48 2
            $this->instanciator
49
        );
50
    }
51
52
    /**
53
     * Add a set of properties that need to be injected
54
     *
55
     * @param array $properties
56
     *
57
     * @return self
58
     */
59 1
    public function withProperties(array $properties): self
60
    {
61 1
        return new self(
62 1
            $this->class,
63 1
            $this->properties->merge(new Collection($properties)),
64 1
            $this->injectionStrategies,
65 1
            $this->instanciator
66
        );
67
    }
68
69
    /**
70
     * Return the collection of properties that will be injected in the object
71
     *
72
     * @return CollectionInterface
73
     */
74 1
    public function getProperties(): CollectionInterface
75
    {
76 1
        return $this->properties;
77
    }
78
79
    /**
80
     * Return the list of injection strategies used
81
     *
82
     * @return InjectionStrategies
83
     */
84 1
    public function getInjectionStrategies(): InjectionStrategies
85
    {
86 1
        return $this->injectionStrategies;
87
    }
88
89
    /**
90
     * Return the object instanciator
91
     *
92
     * @return InstanciatorInterface
93
     */
94 1
    public function getInstanciator(): InstanciatorInterface
95
    {
96 1
        return $this->instanciator;
97
    }
98
99
    /**
100
     * Return a new instance of the class
101
     *
102
     * @return object
103
     */
104 2
    public function buildObject()
105
    {
106 2
        $object = $this->instanciator->build($this->class, $this->properties);
107 2
        $parameters = $this->instanciator->getParameters($this->class);
108
109
        //avoid injecting the properties already used in the constructor
110
        $properties = $this
111 2
            ->properties
112 2
            ->filter(function($value, $property) use ($parameters) {
113 1
                return !$parameters->contains($property);
0 ignored issues
show
The method contains() does not seem to exist on object<Innmind\Immutable\CollectionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114 2
            });
115 2
        $refl = new ReflectionObject(
116
            $object,
117
            $properties,
118 2
            $this->injectionStrategies
119
        );
120
121 2
        return $refl->buildObject();
122
    }
123
}
124