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.
Completed
Push — master ( 440f9f...c814ca )
by Freek
02:36
created

SignatureHandler::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\SlashCommand\Handlers;
4
5
use Illuminate\Console\Parser;
6
use Spatie\SlashCommand\Exceptions\InvalidHandler;
7
use Spatie\SlashCommand\Request;
8
use Symfony\Component\Console\Exception\RuntimeException;
9
use Symfony\Component\Console\Input\InputDefinition;
10
use Symfony\Component\Console\Input\StringInput;
11
12
abstract class SignatureHandler extends BaseHandler
13
{
14
    /** @var string */
15
    protected $name;
16
17
    /** @var \Symfony\Component\Console\Input\StringInput */
18
    protected $input;
19
20
    /** @var bool */
21
    protected $couldBindSignature = false;
22
23
    public function __construct(Request $request)
24
    {
25
        parent::__construct($request);
26
27
        if (empty($this->signature)) {
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist. Did you mean couldBindSignature?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
28
            throw InvalidHandler::signatureIsRequired(static::class);
29
        }
30
31
        $this->parseSignature();
32
    }
33
34
    protected function parseSignature()
35
    {
36
        list($name, $arguments, $options) = Parser::parse($this->signature);
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist. Did you mean couldBindSignature?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
37
38
        $this->name = $name;
39
40
        $inputDefinition = new InputDefinition();
41
42
        foreach ($arguments as $argument) {
43
            $inputDefinition->addArgument($argument);
44
        }
45
46
        foreach ($options as $option) {
47
            $inputDefinition->addOption($option);
48
        }
49
50
        $this->input = new StringInput($this->request->text);
51
52
        try {
53
            $this->input->bind($inputDefinition);
54
            $this->couldBindSignature = true;
55
        }
56
        catch(RuntimeException $exception)
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
57
        {
58
59
        }
60
    }
61
62
    public function getArgument($foo)
63
    {
64
        return $this->input->getArgument($foo);
65
    }
66
67
    public function getOption($foo)
68
    {
69
        return $this->input->getOption($foo);
70
    }
71
72
    public function getArguments(): array
73
    {
74
        return $this->input->getArguments();
75
    }
76
77
    public function getOptions(): array
78
    {
79
        return $this->input->getOptions();
80
    }
81
82
    public function canHandle(Request $request): bool
83
    {
84
        if (! $this->couldBindSignature) {
85
            return false;
86
        }
87
88
        $commandName = explode(' ', $this->signature)[0];
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist. Did you mean couldBindSignature?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
89
90
        return strtolower($request->command) === strtolower($commandName);
91
    }
92
}
93