Completed
Push — master ( 3e1af8...d54861 )
by Akihito
02:18
created

Task   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 70
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A serialize() 0 5 2
A unserialize() 0 5 2
A getCallable() 0 4 1
A getArgs() 0 4 2
A getTag() 0 4 1
A isClosure() 0 4 2
1
<?php
2
namespace Ackintosh\Snidel;
3
use Opis\Closure\SerializableClosure;
4
5
class Task
6
{
7
    /** @var callable */
8
    private $callable;
9
10
    /** @var array */
11
    private $args;
12
13
    /** @var string */
14
    private $tag;
15
16
    /**
17
     * @param   callable    $callable
18
     * @param   array       $args
19
     * @param   string      $string
0 ignored issues
show
Bug introduced by
There is no parameter named $string. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
20
     */
21
    public function __construct($callable, $args, $tag)
22
    {
23
        $this->callable     = $callable;
24
        $this->args         = $args;
25
        $this->tag          = $tag;
26
    }
27
28
    /**
29
     * @return  string
30
     */
31
    public function serialize()
32
    {
33
        $serializedCallable = $this->isClosure($this->callable) ? new SerializableClosure($this->callable) : serialize($this->callable);
0 ignored issues
show
Unused Code introduced by
The call to Task::isClosure() has too many arguments starting with $this->callable.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Documentation introduced by
$this->callable is of type callable, but the function expects a object<Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
        return serialize(new self($serializedCallable, $this->args, $this->tag));
35
    }
36
37
    /**
38
     * @return  \Ackintosh\Snidel\Task
39
     */
40
    public function unserialize()
41
    {
42
        $unserializedCallable = $this->isClosure($this->callable) ? $this->callable->getClosure() : unserialize($this->callable);
0 ignored issues
show
Unused Code introduced by
The call to Task::isClosure() has too many arguments starting with $this->callable.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
The method getClosure cannot be called on $this->callable (of type callable).

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...
43
        return new self($unserializedCallable, $this->args, $this->tag);
44
    }
45
46
    /**
47
     * @return  callable
48
     */
49
    public function getCallable()
50
    {
51
        return $this->callable;
52
    }
53
54
    /**
55
     * @return  array
56
     */
57
    public function getArgs()
58
    {
59
        return is_array($this->args) ? $this->args : array($this->args);
60
    }
61
62
    /**
63
     * @return  string|null
64
     */
65
    public function getTag()
66
    {
67
        return $this->tag;
68
    }
69
70
    private function isClosure()
71
    {
72
        return is_object($this->callable) && is_callable($this->callable);
73
    }
74
}
75