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 (#18)
by Barry vd.
02:12
created

SignatureHandler::bindSignature()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 32
rs 8.5806
cc 4
eloc 17
nc 8
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\Request;
9
use Symfony\Component\Console\Exception\RuntimeException;
10
use Symfony\Component\Console\Input\InputDefinition;
11
use Symfony\Component\Console\Input\StringInput;
12
13
abstract class SignatureHandler extends BaseHandler
14
{
15
    /** @var string */
16
    protected $name;
17
18
    /** @var \Symfony\Component\Console\Input\StringInput */
19
    protected $input;
20
21
    /** @var bool */
22
    protected $signatureIsBound;
23
24
    public function __construct(Request $request)
25
    {
26
        parent::__construct($request);
27
28
        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...
29
            throw InvalidHandler::signatureIsRequired(static::class);
30
        }
31
32
        $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...
33
    }
34
35
    public function getArgument($foo)
36
    {
37
        return $this->input->getArgument($foo);
38
    }
39
40
    public function getOption($foo)
41
    {
42
        return $this->input->getOption($foo);
43
    }
44
45
    public function getArguments(): array
46
    {
47
        return $this->input->getArguments();
48
    }
49
50
    public function getOptions(): array
51
    {
52
        return $this->input->getOptions();
53
    }
54
55
    public function canHandle(Request $request): bool
56
    {
57
        if (! $this->signatureIsBound) {
58
            return false;
59
        }
60
61
        $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...
62
63
64
        if (! Str::is($signatureParts->getSlashCommandName(), $request->command)) {
65
            return false;
66
        }
67
68
        if (explode(' ', $request->text)[0] != $signatureParts->getHandlerName()) {
69
            return false;
70
        }
71
72
        return true;
73
    }
74
75
    protected function bindSignature()
76
    {
77
        $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...
78
79
        $signature = $signatureParts->getSignatureWithoutCommandName();
80
81
        list($name, $arguments, $options) = Parser::parse($signature);
82
83
        $this->name = $name;
84
85
        $inputDefinition = new InputDefinition();
86
87
        foreach ($arguments as $argument) {
88
            $inputDefinition->addArgument($argument);
89
        }
90
91
        foreach ($options as $option) {
92
            $inputDefinition->addOption($option);
93
        }
94
95
        $inputWithoutHandlerName = explode(' ', $this->request->text, 2)[1] ?? '';
96
97
        $this->input = new StringInput($inputWithoutHandlerName);
98
99
        try {
100
            $this->input->bind($inputDefinition);
101
        } catch (RuntimeException $exception) {
102
            return false;
103
        }
104
105
        return true;
106
    }
107
    
108
        /**
109
     * @return Response|null
110
     */
111
    protected function validate()
112
    {
113
        try {
114
            $this->input->validate();
115
        } catch (RuntimeException $e) {
116
            return $this->respondToSlack('')->withAttachment(
117
                Attachment::create()
118
                    ->setColor('danger')
119
                    ->setText($e->getMessage())
120
                )
121
                ->withAttachment(
122
                    Attachment::create()
123
                    ->setText($this->getHelpDescription())
0 ignored issues
show
Bug introduced by
The method getHelpDescription() does not seem to exist on object<Spatie\SlashComma...dlers\SignatureHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
                );
125
        }
126
    }
127
}
128