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.

TryCatchTask::offsetSet()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * See class comment
4
 *
5
 * PHP Version 5
6
 *
7
 * @category   Netresearch
8
 * @package    Netresearch\Kite
9
 * @subpackage Task
10
 * @author     Christian Opitz <[email protected]>
11
 * @license    http://www.netresearch.de Netresearch Copyright
12
 * @link       http://www.netresearch.de
13
 */
14
15
namespace Netresearch\Kite\Task;
16
use Netresearch\Kite\Exception;
17
use Netresearch\Kite\Task;
18
19
20
/**
21
 * Catch exceptions while executing tasks
22
 *
23
 * @category   Netresearch
24
 * @package    Netresearch\Kite
25
 * @subpackage Task
26
 * @author     Christian Opitz <[email protected]>
27
 * @license    http://www.netresearch.de Netresearch Copyright
28
 * @link       http://www.netresearch.de
29
 */
30
class TryCatchTask extends SubTask
31
{
32
    /**
33
     * @var \Netresearch\Kite\Task
34
     */
35
    protected $catchTask;
36
37
    /**
38
     * @var bool If the next fetched task should be the catch task
39
     */
40
    protected $catch = false;
41
42
    /**
43
     * Configure the options
44
     *
45
     * @return array
46
     */
47 View Code Duplication
    protected function configureVariables()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        return array(
50
            'onCatch' => array(
51
                'type' => 'array',
52
                'label' => 'Task to execute when an exception was catched'
53
            ),
54
            'errorMessage' => array(
55
                'type' => 'string',
56
                'label' => 'Message to display on error'
57
            ),
58
            '--'
59
        ) + parent::configureVariables();
60
    }
61
62
    /**
63
     * Set a variable or it's value
64
     *
65
     * @param string $name  The name
66
     * @param mixed  $value The value
67
     *
68
     * @return void
69
     */
70
    public function offsetSet($name, $value)
71
    {
72
        if ($name === 'onCatch') {
73
            $this->catchTask = $this->factory->createTask($value, $this);
0 ignored issues
show
Documentation introduced by
$value is of type *, but the function expects a callable.

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...
74
            return;
75
        }
76
        parent::offsetSet($name, $value);
77
    }
78
79
80
    /**
81
     * Set task as catchTask if $this->catch
82
     *
83
     * @param \Netresearch\Kite\Task $task The task
84
     *
85
     * @return $this|mixed $this or the task return value when this is running
86
     */
87
    public function addTask(Task $task)
88
    {
89
        if ($this->catch) {
90
            $this->catchTask = $task;
91
            $this->catch = false;
92
            return $task;
93
        }
94
        return parent::addTask($task);
95
    }
96
97
    /**
98
     * Fetch the next task as that task to execute when an exception occured while
99
     * executing the other tasks
100
     *
101
     * @return $this
102
     */
103
    public function onCatch()
104
    {
105
        if ($this->catchTask) {
106
            throw new Exception('Only one task may be executed on catch');
107
        }
108
        $this->catch = true;
109
        return $this;
110
    }
111
112
    /**
113
     * Run an array of tasks
114
     *
115
     * @return mixed The ran tasks return value
116
     */
117
    public function run()
118
    {
119
        try {
120
            return parent::run();
121
        } catch (\Exception $e) {
122
            $message = $this->get('errorMessage');
123
            if ($message) {
124
                $this->console->output($message);
125
            }
126
            if ($this->catchTask) {
127
                return $this->addTask($this->catchTask);
128
            }
129
            return null;
130
        }
131
    }
132
}
133
?>
134