Issues (808)

src/midcom/console/application.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * @package midcom.console
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
namespace midcom\console;
10
11
use Symfony\Component\Console\Application as base_application;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use midcom;
16
17
/**
18
 * OpenPSA CLI command runner
19
 *
20
 * @package midcom.console
21
 */
22
class application extends base_application
23
{
24
    /**
25
     * @inheritDoc
26
     */
27
    public function __construct($name = 'midcom\console', $version = midcom::VERSION)
28
    {
29
        parent::__construct($name, $version);
30
31
        $this->getDefinition()
32
            ->addOption(new InputOption('--servername', '-s', InputOption::VALUE_REQUIRED, 'HTTP server name', 'localhost'));
33
        $this->getDefinition()
34
            ->addOption(new InputOption('--port', '-p', InputOption::VALUE_REQUIRED, 'HTTP server port', '80'));
35
36
        $this->add_commands();
37
    }
38
39
    private function add_commands()
40
    {
41
        midcom::get()->boot();
42
        $container = midcom::get()->getContainer();
43
        if ($container->has('console.command_loader')) {
44
            $this->setCommandLoader($container->get('console.command_loader'));
0 ignored issues
show
It seems like $container->get('console.command_loader') can also be of type null; however, parameter $commandLoader of Symfony\Component\Consol...ion::setCommandLoader() does only seem to accept Symfony\Component\Consol...\CommandLoaderInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            $this->setCommandLoader(/** @scrutinizer ignore-type */ $container->get('console.command_loader'));
Loading history...
45
        }
46
47
        if ($container->hasParameter('console.command.ids')) {
48
            foreach ($container->getParameter('console.command.ids') as $id) {
49
                $this->add($container->get($id));
0 ignored issues
show
It seems like $container->get($id) can also be of type null; however, parameter $command of Symfony\Component\Console\Application::add() does only seem to accept Symfony\Component\Console\Command\Command, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
                $this->add(/** @scrutinizer ignore-type */ $container->get($id));
Loading history...
50
            }
51
        }
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function doRun(InputInterface $input, OutputInterface $output) : int
58
    {
59
        $GLOBALS['midcom_config_local']['cache_module_content_uncached'] = true;
60
61
        $port = $input->getParameterOption(['--port', '-p'], '80');
62
        $servername = $input->getParameterOption(['--servername', '-s'], md5(__FILE__));
63
64
        $server_defaults = [
65
            'HTTP_HOST' => $servername,
66
            'SERVER_NAME' => $servername,
67
            'SERVER_SOFTWARE' => __CLASS__,
68
            'HTTP_USER_AGENT' => $this->getName(),
69
            'SERVER_PORT' => $port,
70
            'REMOTE_ADDR' => '127.0.0.1',
71
            'REQUEST_URI' => '/',
72
            'REQUEST_TIME' => time(),
73
            'REMOTE_PORT' => $port
74
        ];
75
        $_SERVER = array_merge($server_defaults, $_SERVER);
76
77
        if ($_SERVER['SERVER_PORT'] == 443) {
78
            $_SERVER['HTTPS'] = 'on';
79
        }
80
81
        return parent::doRun($input, $output);
82
    }
83
}
84