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
Pull Request — master (#19)
by Barry vd.
02:30
created

SignatureHandler::getArguments()   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 Illuminate\Support\Str;
7
use Spatie\SlashCommand\Exceptions\InvalidHandler;
8
use Spatie\SlashCommand\Exceptions\InvalidInput;
9
use Spatie\SlashCommand\Request;
10
use Symfony\Component\Console\Exception\RuntimeException;
11
use Symfony\Component\Console\Input\InputDefinition;
12
use Symfony\Component\Console\Input\StringInput;
13
14
abstract class SignatureHandler extends BaseHandler
15
{
16
    /** @var string */
17
    protected $name;
18
19
    /** @var \Symfony\Component\Console\Input\StringInput */
20
    protected $input;
21
22
    /** @var bool */
23
    protected $signatureIsBound;
24
25
    public function __construct(Request $request)
26
    {
27
        parent::__construct($request);
28
29
        if (empty($this->signature)) {
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist. Did you mean signatureIsBound?

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...
30
            throw InvalidHandler::signatureIsRequired(static::class);
31
        }
32
33
        $this->signatureIsBound = $this->bindSignature($this->signature);
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist. Did you mean signatureIsBound?

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...
Unused Code introduced by
The call to SignatureHandler::bindSignature() has too many arguments starting with $this->signature.

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...
34
    }
35
36
    public function getArgument($foo)
37
    {
38
        return $this->input->getArgument($foo);
39
    }
40
41
    public function getOption($foo)
42
    {
43
        return $this->input->getOption($foo);
44
    }
45
46
    public function getArguments(): array
47
    {
48
        return $this->input->getArguments();
49
    }
50
51
    public function getOptions(): array
52
    {
53
        return $this->input->getOptions();
54
    }
55
56
    public function canHandle(Request $request): bool
57
    {
58
        if (! $this->signatureIsBound) {
59
            return false;
60
        }
61
62
        $signatureParts = new SignatureParts($this->signature);
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist. Did you mean signatureIsBound?

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...
63
64
65
        if (! Str::is($signatureParts->getSlashCommandName(), $request->command)) {
66
            return false;
67
        }
68
69
        if (explode(' ', $request->text)[0] != $signatureParts->getHandlerName()) {
70
            return false;
71
        }
72
73
        return true;
74
    }
75
76
    protected function bindSignature()
77
    {
78
        $signatureParts = new SignatureParts($this->signature);
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist. Did you mean signatureIsBound?

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...
79
80
        $signature = $signatureParts->getSignatureWithoutCommandName();
81
82
        list($name, $arguments, $options) = Parser::parse($signature);
83
84
        $this->name = $name;
85
86
        $inputDefinition = new InputDefinition();
87
88
        foreach ($arguments as $argument) {
89
            $inputDefinition->addArgument($argument);
90
        }
91
92
        foreach ($options as $option) {
93
            $inputDefinition->addOption($option);
94
        }
95
96
        $inputWithoutHandlerName = explode(' ', $this->request->text, 2)[1] ?? '';
97
98
        $this->input = new StringInput($inputWithoutHandlerName);
99
100
        try {
101
            $this->input->bind($inputDefinition);
102
        } catch (RuntimeException $exception) {
103
            return false;
104
        }
105
106
        return true;
107
    }
108
109
    protected function validate()
110
    {
111
        try {
112
            $this->input->validate();
113
        } catch (RuntimeException $e) {
114
            throw new InvalidInput($e->getMessage(), $this, $e);
115
        }
116
    }
117
}
118