Issues (41)

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.

sources/lib/Command/SchemaAwareCommand.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
 * This file is part of Pomm's Cli package.
4
 *
5
 * (c) 2014 - 2015 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Cli\Command;
11
12
use PommProject\Cli\Exception\CliException;
13
use PommProject\Foundation\Inflector;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * SchemaAwareCommand
22
 *
23
 * Base class for generator commands.
24
 *
25
 * @abstract
26
 * @package   Cli
27
 * @copyright 2014 - 2015 Grégoire HUBERT
28
 * @author    Grégoire HUBERT
29
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
30
 * @see       PommAwareCommand
31
 */
32
abstract class SchemaAwareCommand extends SessionAwareCommand
33
{
34
    protected $schema;
35
    protected $prefix_dir;
36
    protected $prefix_ns;
37
    protected $pathFile;
38
    protected $namespace;
39
    protected $flexible_container;
40
41
    /**
42
     * configure
43
     *
44
     * @see PommAwareCommand
45
     */
46
    protected function configureRequiredArguments()
47
    {
48
        parent::configureRequiredArguments()
49
            ->addOption(
50
                'prefix-dir',
51
                'd',
52
                InputOption::VALUE_REQUIRED,
53
                'Indicate a directory prefix.',
54
                '.'
55
            )
56
            ->addOption(
57
                'prefix-ns',
58
                'a',
59
                InputOption::VALUE_REQUIRED,
60
                'Indicate a namespace prefix.',
61
                ''
62
            )
63
        ;
64
65
        return $this;
66
    }
67
68
    /**
69
     * configureOptionals
70
     *
71
     * @see PommAwareCommand
72
     */
73
    protected function configureOptionals()
74
    {
75
        parent::configureOptionals()
76
            ->addArgument(
77
                'schema',
78
                InputArgument::OPTIONAL,
79
                'Schema of the relation.',
80
                'public'
81
            )
82
            ->addOption(
83
                'flexible-container',
84
                null,
85
                InputOption::VALUE_REQUIRED,
86
                'Use an alternative flexible entity container',
87
                'PommProject\ModelManager\Model\FlexibleEntity'
88
            )
89
        ;
90
91
        return $this;
92
    }
93
    /**
94
     * execute
95
     *
96
     * @see Command
97
     */
98
    protected function execute(InputInterface $input, OutputInterface $output)
99
    {
100
        parent::execute($input, $output);
101
        $this->schema   = $input->getArgument('schema');
102
103
        if (!$this->schema) {
104
            $this->schema = 'public';
105
        }
106
107
        $this->prefix_dir = $input->getOption('prefix-dir');
108
        $this->prefix_ns  = $input->getOption('prefix-ns');
109
        $this->flexible_container = $input->getOption('flexible-container');
110
    }
111
112
    /**
113
     * getPathFile
114
     *
115
     * Create path file from parameters and namespace.
116
     *
117
     * @access protected
118
     * @param  string $config_name
119
     * @param  string $file_suffix
120
     * @param  string $extra_dir
121
     * @param  string $file_name
122
     * @param  bool   $format_psr4
123
     * @return string
124
     */
125
    protected function getPathFile(
126
        $config_name,
0 ignored issues
show
The parameter $config_name 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...
127
        $file_name,
128
        $file_suffix = '',
129
        $extra_dir = '',
130
        $format_psr4 = null,
131
        $path_pattern = '{session}/{schema}Schema'
132
    ) {
133
134
        $format_psr4 = $format_psr4 === null ? false : (bool) $format_psr4;
135
        $prefix_ns = "";
136
137
        if (!$format_psr4) {
138
            $prefix_ns = str_replace('\\', '/', trim($this->prefix_ns, '\\'));
139
        }
140
141
        $elements =
142
            [
143
                rtrim($this->prefix_dir, '/'),
144
                $prefix_ns,
145
                $this->expandPath($path_pattern),
146
                $extra_dir,
147
                sprintf("%s%s.php", Inflector::studlyCaps($file_name), $file_suffix)
148
            ];
149
150
        return join('/', array_filter($elements, function ($val) {
151
            return $val != null;
152
        }));
153
    }
154
155
    /**
156
     * expandPath
157
     *
158
     * Expand path pattern with the context values
159
     *
160
     * @param   string $pattern
161
     * @return  string
162
     */
163
    protected function expandPath($pattern)
164
    {
165
        return trim(
166
            strtr(
167
                $pattern,
168
                [
169
                    '{session}' => Inflector::studlyCaps($this->config_name),
0 ignored issues
show
It seems like $this->config_name can also be of type array<integer,string>; however, PommProject\Foundation\Inflector::studlyCaps() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
170
                    '{schema}'  => Inflector::studlyCaps($this->schema),
0 ignored issues
show
It seems like $this->schema can also be of type array<integer,string>; however, PommProject\Foundation\Inflector::studlyCaps() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
171
                ]
172
            ),
173
            '/'
174
        );
175
    }
176
177
    /**
178
     * getNamespace
179
     *
180
     * Create namespace from parameters.
181
     *
182
     * @access protected
183
     * @param  string $config_name
184
     * @param  string $extra_ns
185
     * @return string
186
     */
187
    protected function getNamespace($config_name, $extra_ns = '', $path_pattern = '{session}/{schema}Schema')
0 ignored issues
show
The parameter $config_name 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...
188
    {
189
        $elements =
190
            [
191
                $this->prefix_ns,
192
                str_replace('/', '\\', $this->expandPath($path_pattern)),
193
                $extra_ns
194
            ];
195
196
        return join('\\', array_filter($elements, function ($val) {
197
            return $val != null;
198
        }));
199
    }
200
201
    /**
202
     * fetchSchemaOid
203
     *
204
     * Get the schema Oid from database.
205
     *
206
     * @access protected
207
     * @return int $oid
208
     * @throws CliException
209
     */
210
    protected function fetchSchemaOid()
211
    {
212
        $schema_oid = $this
213
            ->getSession()
214
            ->getInspector()
215
            ->getSchemaOid($this->schema)
216
            ;
217
218
        if ($schema_oid === null) {
219
            throw new CliException(
220
                sprintf(
221
                    "Could not find schema '%s'.",
222
                    $this->schema
223
                )
224
            );
225
        }
226
227
        return $schema_oid;
228
    }
229
}
230