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.

Context::push()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Task;
9
10
use Deployer\Configuration\Configuration;
11
use Deployer\Exception\Exception;
12
use Deployer\Host\Host;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
class Context
17
{
18
    /**
19
     * @var Host
20
     */
21
    private $host;
22
23
    /**
24
     * @var InputInterface
25
     */
26
    private $input;
27
28
    /**
29
     * @var OutputInterface
30
     */
31
    private $output;
32
33
    /**
34
     * @var Context[]
35
     */
36
    private static $contexts = [];
37
38
    /**
39
     * @param Host $host
40
     * @param InputInterface $input
41
     * @param OutputInterface $output
42
     */
43 17
    public function __construct($host, InputInterface $input = null, OutputInterface $output = null)
44
    {
45 17
        $this->host = $host;
46 17
        $this->input = $input;
47 17
        $this->output = $output;
48 17
    }
49
50
    /**
51
     * @param Context $context
52
     */
53 19
    public static function push(Context $context)
54
    {
55 19
        self::$contexts[] = $context;
56 19
    }
57
58
    /**
59
     * @return bool
60
     */
61 14
    public static function has()
62
    {
63 14
        return !empty(self::$contexts);
64
    }
65
66
    /**
67
     * @return Context|false
68
     * @throws Exception
69
     */
70 12
    public static function get()
71
    {
72 12
        if (empty(self::$contexts)) {
73
            throw new Exception('Context was required, but there\'s nothing there.');
74
        }
75 12
        return end(self::$contexts);
76
    }
77
78
    /**
79
     * @return Context
80
     */
81 19
    public static function pop()
82
    {
83 19
        return array_pop(self::$contexts);
84
    }
85
86
    /**
87
     * Throws a Exception when not called within a task-context and therefore no Context is available.
88
     *
89
     * This method provides a useful error to the end-user to make him/her aware
90
     * to use a function in the required task-context.
91
     *
92
     * @param string $callerName
93
     * @throws Exception
94
     */
95 1
    public static function required($callerName)
96
    {
97 1
        if (empty(self::$contexts)) {
98
            throw new Exception("'$callerName' can only be used within a task.");
99
        }
100 1
    }
101
102
    /**
103
     * @return Configuration
104
     */
105 11
    public function getConfig()
106
    {
107 11
        return $this->host->config();
108
    }
109
110
    /**
111
     * @return InputInterface
112
     */
113 6
    public function getInput()
114
    {
115 6
        return $this->input;
116
    }
117
118
    /**
119
     * @return OutputInterface
120
     */
121 9
    public function getOutput()
122
    {
123 9
        return $this->output;
124
    }
125
126
    /**
127
     * @return Host
128
     */
129 10
    public function getHost()
130
    {
131 10
        return $this->host;
132
    }
133
}
134