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 ( a6da30...91246b )
by Freek
02:10
created

SignatureHandler::bind()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 29
rs 8.5806
cc 4
eloc 15
nc 8
nop 1
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
    public function __construct(Request $request)
21
    {
22
        parent::__construct($request);
23
24
        if (empty($this->signature)) {
0 ignored issues
show
Bug introduced by
The property signature does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
            throw InvalidHandler::signatureIsRequired(static::class);
26
        }
27
    }
28
29
30
31
    public function getArgument($foo)
32
    {
33
        return $this->input->getArgument($foo);
34
    }
35
36
    public function getOption($foo)
37
    {
38
        return $this->input->getOption($foo);
39
    }
40
41
    public function getArguments(): array
42
    {
43
        return $this->input->getArguments();
44
    }
45
46
    public function getOptions(): array
47
    {
48
        return $this->input->getOptions();
49
    }
50
51
    public function canHandle(Request $request): bool
52
    {
53
        $signatureParts = new SignatureParts($this->signature);
54
55
        if (! $this->bind($signatureParts->getSignatureWithoutCommandName())) {
56
            return false;
57
        };
58
59
        if ($request->command != $signatureParts->getSlashCommandName()) {
60
            return false;
61
        }
62
63
        if (explode(' ', $request->text)[0] = $signatureParts->getHandlerName()) {
64
            return false;
65
        }
66
67
        return true;
68
    }
69
70
    protected function bind(string $signature)
71
    {
72
        list($name, $arguments, $options) = Parser::parse($signature);
73
74
        $this->name = $name;
75
76
        $inputDefinition = new InputDefinition();
77
78
        foreach ($arguments as $argument) {
79
            $inputDefinition->addArgument($argument);
80
        }
81
82
        foreach ($options as $option) {
83
            $inputDefinition->addOption($option);
84
        }
85
86
        $this->input = new StringInput($this->request->text);
87
88
        try {
89
            $this->input->bind($inputDefinition);
90
91
        } catch (RuntimeException $exception) {
92
93
            throw $exception;
94
            return false;
0 ignored issues
show
Unused Code introduced by
return false; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
95
        }
96
97
        return true;
98
    }
99
}
100