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 ( ab3243...c3401f )
by Stan
02:44
created

botmother.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 88.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use Teebot\Exception\Fatal;
4
use Teebot\Exception\Output;
5
6
class BotMother
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    protected $cliOptions = [
9
        'short' => 'r:b:c:t:d:h:',
10
        'long'  => ['run', 'bot', 'command', 'token', 'dir', 'help']
11
    ];
12
13
    protected $commandMethodMapper = [
14
        'create-bot' => ['commandBotCreate', ['b:bot', 't:token', 'd:dir']],
15
        'help'       => ['help', []],
16
    ];
17
18
    public function __construct()
19
    {
20
        $opts = getopt($this->cliOptions['short'], $this->cliOptions['long']);
21
22
        $help = $opts['h'] ?? $opts['help'] ?? null;
23
24
        if ($help || empty($opts)) {
25
            $this->help();
26
27
            exit;
28
        }
29
30
        $command = $opts['r'] ?? $opts['run'] ?? null;
31
32
        try {
33
            if (!$command) {
34
                throw new Fatal('Command not specified!');
35
            }
36
37
            $method = $this->getMethod($command);
38
39
            if (!$method) {
40
                throw new Fatal('Unknown command!');
41
            }
42
43
            $args = $this->getMethodArgs($method);
0 ignored issues
show
Are you sure the assignment to $args is correct as $this->getMethodArgs($method) (which targets BotMother::getMethodArgs()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
$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...
44
45
            call_user_func_array([$this, $method], ['1', '2', '3']);
46
        } catch (Fatal $e) {
47
            Output::log($e);
48
        }
49
    }
50
51
    protected function help()
52
    {
53
        echo "
54
Bot mother CLI utility will help you easily and quickly create Bot or Command for existing bot. Please use
55
the following arguments:
56
57
-r, --run [command_name] : Command name - required parameter. Could have the following values: create-bot, create-command
58
-b, --bot [bot_name]     : The name of the bot that you want to create
59
-c, --command [name]     : The name of the command that you want to create
60
-t, --token [value]      : Token for the bot creation
61
-d, --dir [dir]          : Bot's root directory (absolute path)\n\n";
62
    }
63
64
    protected function getMethod($command)
65
    {
66
        $method = $this->commandMethodMapper[$command] ?? null;
67
68
        if (!$method || !method_exists($this, $method)) {
69
            return null;
70
        }
71
72
        return $method;
73
    }
74
75
    protected function getMethodArgs($methodName)
0 ignored issues
show
The parameter $methodName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
    }
78
79
    protected function commandBotCreate($botName, $token, $dir)
80
    {
81
        echo "\nCreating a new bot.\n";
82
83
        echo $botName . " - " . $token . " - " . $dir;
84
    }
85
}
86
87
define('ROOT_DIR', realpath(__DIR__));
88
require_once ROOT_DIR . '/vendor/autoload.php';
89
90
$BotMother = new BotMother();
91