Issues (10)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/BaseApplication.php (4 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
2
/*
3
 * Copyright (c) 2015 Juan José Torroglosa Ramón
4
 *
5
 * This file is part of the Cliphar package.
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
11
namespace Cliphar;
12
13
use Cliphar\Command\CommandFactory;
14
use Cliphar\Container\ContainerFactory;
15
use Cliphar\Exception\InvalidCommandException;
16
use Cliphar\Exception\InvalidServiceProviderException;
17
use Cliphar\InputDefinition\Exception\InputDefinitionParsingException;
18
use Cliphar\InputDefinition\InputDefinitionParser;
19
use Cliphar\ServiceProvider;
20
use Cliphar\Symfony\SymfonyConsoleApplication;
21
use Exception;
22
use Interop\Container\ContainerInterface;
23
use Symfony\Component\Console\Command\Command;
24
use Symfony\Component\Console\Input\ArgvInput;
25
use Symfony\Component\Console\Output\ConsoleOutput;
26
27
/**
28
 * Class BaseApplication
29
 */
30
abstract class BaseApplication
31
{
32
    private static $instance;
33
34
    /**
35
     * @var ContainerInterface
36
     */
37
    protected $container;
38
39
    /**
40
     * @var Binder
41
     */
42
    protected $binder;
43
44
    /**
45
     * @var SymfonyConsoleApplication
46
     */
47
    private $symfonyApplication;
48
49
    /**
50
     * @var Command[]
51
     */
52
    private $commands;
53
54
    /**
55
     * @return static
56
     */
57
    public static function getInstance()
58
    {
59
        if (self::$instance === null) {
60
            self::$instance = new static();
61
        }
62
63
        return self::$instance;
64
    }
65
66
    protected final function __construct()
67
    {
68
        $factory = new ContainerFactory();
69
        $this->container = $factory->createLaravelContainer();
70
        $this->binder = $this->container->get('Cliphar\Binder');
71
        $this->symfonyApplication = new SymfonyConsoleApplication($this->getName(), $this->getVersion(), $this->binder);
72
        $this->symfonyApplication->setAutoExit(false);
73
        $this->commandFactory = $this->container->get('Cliphar\Command\CommandFactory');
0 ignored issues
show
The property commandFactory 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...
74
        $this->input = new ArgvInput();
0 ignored issues
show
The property input 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...
75
        $this->output = new ConsoleOutput();
0 ignored issues
show
The property output 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...
76
        $this->symfonyApplication->registerIO($this->input, $this->output);
77
        $this->commands = array();
78
    }
79
80
    /**
81
     * Runs the application
82
     * @throws \Exception
83
     */
84
    public final function run()
85
    {
86
        $this->registerServices();
87
        $this->registerCommands();
88
        return $this->symfonyApplication->run($this->input, $this->output);
89
    }
90
91
    /**
92
     * @param $name
93
     * @param $definition
94
     * @param $callable
95
     */
96
    public function addCommand($name, $definition, $callable)
97
    {
98
        try {
99
            $command = $this->commandFactory->createCommand($name, $definition, $callable);
100
            $this->commands[$command->getName()] = $command;
101
        } catch (InputDefinitionParsingException $e) {
102
            $this->symfonyApplication->renderException(
103
                $e,
104
                $this->container->get('Symfony\Component\Console\Output\OutputInterface')
105
            );
106
            exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method addCommand() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
107
        }
108
    }
109
110
    private function registerServices()
111
    {
112
        foreach ($this->getProviders() as $p) {
113
            /** @var ServiceProvider $provider */
114
            $provider = $this->resolveServiceProvider($p);
115
116
            $provider->register();
117
        }
118
    }
119
120
    private function registerCommands()
121
    {
122
        foreach ($this->getAllCommands() as $c) {
123
            /** @var Command $command */
124
            $command = $this->resolveCommand($c);
125
126
            $this->symfonyApplication->add($command);
127
        }
128
    }
129
130
    /**
131
     * @param string|ServiceProvider $provider
132
     * @return ServiceProvider
133
     * @throws InvalidServiceProviderException
134
     */
135
    private function resolveServiceProvider($provider)
136
    {
137
        if (is_string($provider)) {
138
            $provider = $this->container->get($provider);
139
        }
140
141
        if (! ($provider instanceof ServiceProvider)) {
142
            throw new InvalidServiceProviderException();
143
        }
144
145
        return $provider;
146
    }
147
148
    /**
149
     * @param $command
150
     * @return Command
151
     * @throws InvalidCommandException
152
     */
153
    private function resolveCommand($command)
154
    {
155
        if (is_string($command)) {
156
            $command = $this->container->get($command);
157
        }
158
159
        if (!($command instanceof Command)) {
160
            throw new InvalidCommandException();
161
        }
162
163
        return $command;
164
    }
165
166
    /**
167
     * @return string[]
168
     */
169
    protected function getAllCommands()
170
    {
171
        return array_merge($this->commands, $this->getCommands());
172
    }
173
174
    /**
175
     * @return string[]
176
     */
177
    abstract protected function getCommands();
178
179
    /**
180
     * @return string[]
181
     */
182
    abstract protected function getProviders();
183
184
    /**
185
     * @return string
186
     */
187
    abstract protected function getVersion();
188
189
    /**
190
     * @return string
191
     */
192
    abstract protected function getName();
193
}