Issues (14)

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/LimoncelloCommand.php (3 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 declare(strict_types=1);
2
3
namespace Limoncello\Commands;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Composer\Command\BaseCommand;
22
use Exception;
23
use Limoncello\Commands\Traits\CommandSerializationTrait;
24
use Limoncello\Commands\Traits\CommandTrait;
25
use Limoncello\Commands\Wrappers\DataArgumentWrapper;
26
use Limoncello\Commands\Wrappers\DataOptionWrapper;
27
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
28
use Limoncello\Contracts\Exceptions\ThrowableHandlerInterface;
29
use Symfony\Component\Console\Input\InputInterface;
30
use Symfony\Component\Console\Output\OutputInterface;
31
use function assert;
32
33
/**
34
 * @package Limoncello\Commands
35
 *
36
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
37
 */
38
class LimoncelloCommand extends BaseCommand
39
{
40
    use CommandTrait, CommandSerializationTrait, ExecuteCommandTrait;
41
42
    /**
43
     * @var string
44
     */
45
    private $description;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
46
47
    /**
48
     * @var string
49
     */
50
    private $help;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
51
52
    /**
53
     * @var array
54
     */
55
    private $arguments;
56
57
    /**
58
     * @var array
59
     */
60
    private $options;
61
62
    /**
63
     * @var callable|array
64
     */
65
    private $callable;
66
67
    /**
68
     * @param string $name
69
     * @param string $description
70
     * @param string $help
71
     * @param array  $arguments
72 4
     * @param array  $options
73
     * @param array  $callable
74
     */
75
    public function __construct(
76
        string $name,
77
        string $description,
78
        string $help,
79
        array $arguments,
80 4
        array $options,
81 4
        array $callable
82 4
    ) {
83 4
        $this->description = $description;
84 4
        $this->help        = $help;
85
        $this->arguments   = $arguments;
86
        $this->options     = $options;
87
        $this->callable    = $callable;
88 4
89
        // it is important to call the parent constructor after
90
        // data init as it calls `configure` method.
91
        parent::__construct($name);
92
    }
93
94 4
    /**
95
     * @inheritdoc
96 4
     */
97
    public function configure()
98
    {
99 4
        parent::configure();
100 4
101
        $this
102 4
            ->setDescription($this->description)
103 3
            ->setHelp($this->help);
104 3
105
        foreach ($this->arguments as $data) {
106
            $arg = new DataArgumentWrapper($data);
107 4
            $this->addArgument($arg->getName(), $arg->getMode(), $arg->getDescription(), $arg->getDefault());
108 3
        }
109 3
110 3
        foreach ($this->options as $data) {
111 3
            $opt = new DataOptionWrapper($data);
112 3
            $this->addOption(
113 3
                $opt->getName(),
114 3
                $opt->getShortcut(),
115
                $opt->getMode(),
116
                $opt->getDescription(),
117
                $opt->getDefault()
118
            );
119
        }
120
    }
121
122
    /** @noinspection PhpMissingParentCallCommonInspection
123
     * @inheritdoc
124
     *
125
     * @throws Exception
126 3
     *
127
     * @SuppressWarnings(PHPMD.ElseExpression)
128 3
     */
129
    public function execute(InputInterface $input, OutputInterface $output)
130
    {
131
        $container = null;
132 3
        try {
133 2
            // There is a tiny hack here. We need editable container and we know that at this point
134
            // container still can be edited so we cast it to `LimoncelloContainerInterface`.
135 2
            $container = $this->createContainer($this->getComposer());
0 ignored issues
show
It seems like $this->getComposer() can be null; however, createContainer() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
136 2
            assert($container instanceof LimoncelloContainerInterface);
137 2
138
            $this->executeCommand($this->getName(), $this->callable, $this->wrapIo($input, $output), $container);
139 1
        } catch (Exception $exception) {
140 1
            if ($container !== null && $container->has(ThrowableHandlerInterface::class) === true) {
141
                /** @var ThrowableHandlerInterface $handler */
142 1
                $handler  = $container->get(ThrowableHandlerInterface::class);
143
                $response = $handler->createResponse($exception, $container);
144 1
145 1
                $output->writeln((string)$response->getBody());
146 1
            } else {
147 1
                $message = $exception->getMessage();
148
                $file    = $exception->getFile();
149 1
                $line    = $exception->getLine();
150
                $trace   = $exception->getTraceAsString();
151
152 2
                $output->writeln("$message at $file#$line" . PHP_EOL . $trace);
153
            }
154
155
            throw $exception;
156
        }
157
    }
158
}
159