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.

SeleniumSetup::run()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 36
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 36
rs 8.8571
cc 2
eloc 16
nc 1
nop 0
1
<?php
2
namespace SeleniumSetup;
3
4
use SeleniumSetup\Controller\StartServer;
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\Console\ConsoleEvents;
7
use Symfony\Component\Console\Event\ConsoleCommandEvent;
8
use Symfony\Component\EventDispatcher\EventDispatcher;
9
10
class SeleniumSetup
11
{
12
    const APP_NAME = 'Selenium Setup';
13
    const APP_VERSION = '4.0.0';
14
    const APP_DEFAULT_COMMAND = 'list';
15
    public static $APP_ROOT_PATH;
16
    public static $APP_CONF_PATH;
17
    public static $APP_PROCESS_ENV;
18
    
19
    const SSL_CERT_FILENAME = 'cacert.pem';
20
    const DEFAULT_LOCK_FILENAME = 'selenium-servers.lock';
21
22
    public static $BANNER = <<<'BANNER'
23
 ____            ___
24
/\  _`\         /\_ \                  __
25
\ \,\L\_\     __\//\ \      __    ___ /\_\  __  __    ___ ___
26
 \/_\__ \   /'__`\\ \ \   /'__`\/' _ `\/\ \/\ \/\ \ /' __` __`\
27
   /\ \L\ \/\  __/ \_\ \_/\  __//\ \/\ \ \ \ \ \_\ \/\ \/\ \/\ \
28
   \ `\____\ \____\/\____\ \____\ \_\ \_\ \_\ \____/\ \_\ \_\ \_\
29
    \/_____/\/____/\/____/\/____/\/_/\/_/\/_/\/___/  \/_/\/_/\/_/
30
    Selenium Environment on Windows, Linux and Mac
31
    by Bogdan Anton and contributors.
32
33
BANNER;
34
    
35
    public function __construct()
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
__construct uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
36
    {
37
        self::$APP_ROOT_PATH = realpath(dirname(__FILE__) . '/../');
38
        self::$APP_CONF_PATH = realpath(dirname(__FILE__) . '/../config/');
39
        self::$APP_PROCESS_ENV = array_merge($_SERVER, $_ENV);
40
    }
41
    
42
    public function run()
43
    {
44
        $console = new Application(self::APP_NAME, self::APP_VERSION);
45
        $console->setDefaultCommand(self::APP_DEFAULT_COMMAND);
46
47
        $dispatcher = new EventDispatcher();
48
        $dispatcher->addListener(ConsoleEvents::COMMAND, function(ConsoleCommandEvent $event) {
49
            // get the input instance
50
            // $input = $event->getInput();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
52
            // get the output instance
53
            $output = $event->getOutput();
54
55
            // get the command to be executed
56
            $command = $event->getCommand();
57
58
            // write something about the command
59
            //$output->writeln(sprintf('Before running command <info>%s</info>', $command->getName()));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
            if ($command->getName() == StartServer::CLI_COMMAND) {
61
                $output->write(self::$BANNER);
62
            }
63
64
            // get the application
65
            // $application = $command->getApplication();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
        });
67
        $console->setDispatcher($dispatcher);
68
69
        $console->addCommands([
70
            new Controller\StartServer,
71
            new Controller\StopServer,
72
            new Controller\ListServers,
73
            new Controller\RegisterServer,
74
        ]);
75
76
        $console->run();
77
    }
78
}