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.

ContextStack   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 2
A store() 0 12 3
A getQueueHandler() 0 4 1
1
<?php
2
3
namespace Gandung\Promise\Context;
4
5
use TaskQueue\TaskQueue;
6
use TaskQueue\Invoker\FunctionInvoker;
7
use TaskQueue\Invoker\MethodInvoker;
8
use DependencyInjection\Container;
9
10
/**
11
 * @author Paulus Gandung Prakosa <[email protected]>
12
 */
13
class ContextStack
14
{
15
    /**
16
     * @var array
17
     */
18
    private static $queueHandler;
19
    
20
    /**
21
     * Statically create an instance of this class.
22
     *
23
     * @param TaskQueue
24
     */
25
    public static function create()
26
    {
27
        if (null === static::$queueHandler) {
0 ignored issues
show
Bug introduced by
Since $queueHandler is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $queueHandler 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...
28
            static::$queueHandler = new TaskQueue;
0 ignored issues
show
Bug introduced by
Since $queueHandler is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $queueHandler 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...
Documentation Bug introduced by
It seems like new \TaskQueue\TaskQueue() of type object<TaskQueue\TaskQueue> is incompatible with the declared type array of property $queueHandler.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
        }
30
31
        return new static;
32
    }
33
34
    /**
35
     * Store a value into task queueing stack.
36
     *
37
     * @param \Closure|array $handler
38
     * @param mixed $value
39
     */
40
    public function store($handler, $value = [])
41
    {
42
        $value = is_array($value)
43
            ? $value
44
            : array_slice(func_get_args(), 1);
45
46
        if ($handler instanceof \Closure) {
47
            self::$queueHandler->add(new FunctionInvoker($handler), $value);
0 ignored issues
show
Bug introduced by
The method add cannot be called on self::$queueHandler (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
48
        } else {
49
            self::$queueHandler->add(new MethodInvoker($handler), $value);
0 ignored issues
show
Bug introduced by
The method add cannot be called on self::$queueHandler (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
50
        }
51
    }
52
53
    /**
54
     * Get task queue handler.
55
     *
56
     * @return TaskQueue
57
     */
58
    public static function getQueueHandler()
59
    {
60
        return self::$queueHandler;
61
    }
62
}
63