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 ( 84c3a7...ff5597 )
by Stan
02:46
created

Command::getCommandDataFromText()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 7.551
cc 7
eloc 12
nc 3
nop 1
1
<?php
2
3
namespace Teebot\Entity;
4
5
use Teebot\Command\Executor;
6
7
class Command extends AbstractEntity
8
{
9
    const ENTITY_TYPE             = 'Command';
10
11
    const PREFIX          = '/';
12
13
    const ARGS_SEPARATOR  = ' ';
14
15
    const PARTS_DELIMITER = '_';
16
17
    const PATTERN_COMMAND_ON_FIRST = '/^\/[a-zA-Z_]+.*$/';
18
19
    const PATTERN_COMMAND_ON_ANY = '/\/[a-zA-Z_]+.*$/';
20
21
    const PATTERN_COMMAND_DATA = '/.*\/(?P<name>\w+)\b(?P<args>.*)$/';
22
23
    protected $text;
24
25
    protected $name;
26
27
    protected $args;
28
29
    public function __construct(array $data)
30
    {
31
        if (isset($data['text'])) {
32
            $args    = null;
0 ignored issues
show
Unused Code introduced by
$args is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33
            $command = $this->getCommandDataFromText($data['text']);
34
35
            if ($command) {
36
                $data = [
37
                    'name' => $command['name'],
38
                    'args' => $command['args']
39
                ];
40
            }
41
        }
42
43
        parent::__construct($data);
44
    }
45
46
    /**
47
     * @return mixed
48
     */
49
    public function getName()
50
    {
51
        return $this->name;
52
    }
53
54
    /**
55
     * @return mixed
56
     */
57
    public function getArgs()
58
    {
59
        return $this->args;
60
    }
61
62
    protected function getCommandDataFromText($text)
63
    {
64
        $commandOnFirst = Executor::getInstance()->getConfig()->getCommandOnFirst();
65
        $command        = null;
66
67
        if (!is_string($text) ||
68
            !strlen($text) ||
69
            ($commandOnFirst === true && $text[0] != self::PREFIX) ||
70
            strpos($text, self::PREFIX) === false
71
        ) {
72
            return $command;
73
        }
74
75
        preg_match(self::PATTERN_COMMAND_DATA, $text, $matches);
76
77
        if ($matches) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $matches of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
78
            $matches = array_map('trim', $matches);
79
        }
80
81
        return $matches;
82
    }
83
}
84