Completed
Pull Request — master (#2)
by Brad
26:51 queued 11:51
created

TransitionFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Transitions;
4
5
use Illuminate\Contracts\Container\Container;
6
7
/**
8
 * Class TransitionFactory
9
 */
10
class TransitionFactory
11
{
12
13
    /**
14
     * @var array
15
     */
16
    private static $transitions = [];
17
18
    /**
19
     * @var Container
20
     */
21
    private $container;
22
23
    /**
24
     * TransitionFactory constructor.
25
     * @param Container $container
26
     */
27
    public function __construct(Container $container)
28
    {
29
30
        $this->container = $container;
31
    }
32
33
    /**
34
     * @param string $transition
35
     * @return Transition
36
     */
37
    public function create(string $transition) : Transition
38
    {
39
40
        if (! isset(static::$transitions[$transition])) {
0 ignored issues
show
Bug introduced by
Since $transitions is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $transitions to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
41
            static::$transitions[$transition] = $this->container->make($transition);
0 ignored issues
show
Bug introduced by
Since $transitions is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $transitions to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
42
        }
43
        return static::$transitions[$transition];
0 ignored issues
show
Bug introduced by
Since $transitions is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $transitions to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
44
    }
45
}
46