Issues (9)

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/Console/EnumMakeCommand.php (1 issue)

Labels
Severity

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
namespace MadWeb\Enum\Console;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
8
class EnumMakeCommand extends GeneratorCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'make:enum';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a new enum class';
23
24
    /**
25
     * The type of class being generated.
26
     *
27
     * @var string
28
     */
29
    protected $type = 'Enum';
30
31
    /**
32
     * Get the stub file for the generator.
33
     *
34
     * @return string
35
     */
36 12
    protected function getStub()
37
    {
38 12
        return __DIR__.'/stubs/enum.stub';
39
    }
40
41
    /**
42
     * Get the default namespace for the class.
43
     *
44
     * @param string $rootNamespace
45
     *
46
     * @return string
47
     */
48 12
    protected function getDefaultNamespace($rootNamespace)
49
    {
50 12
        return $rootNamespace.'\Enums';
51
    }
52
53
    /**
54
     * Build the class with the given name.
55
     *
56
     * @param  string  $name
57
     * @return string
58
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
59
     */
60 12
    protected function buildClass($name)
61
    {
62 12
        $stub = $this->files->get($this->getStub());
63
64
        return $this
65 12
          ->replaceDocblock($stub)
66 12
          ->replaceConstants($stub)
67 12
          ->replaceNamespace($stub, $name)
68 12
          ->replaceClass($stub, $name);
69
    }
70
71
    /**
72
     * Get the console command arguments.
73
     *
74
     * @return array
75
     */
76 12
    protected function getArguments()
77
    {
78 12
        return array_merge(parent::getArguments(), [
79 12
            ['values', InputArgument::IS_ARRAY, 'The const maps e.g. ACTIVE=active DELETED=deleted; or FOO BAR BAZ for FOO=0 BAR=1 BAZ=2'],
80
        ]);
81
    }
82
83
    /**
84
     * Get the constants for the enum.
85
     *
86
     * @return array
87
     */
88 12
    protected function getConstants()
89
    {
90 12
        $inputValues = $this->argument('values');
91 12
        if (empty($inputValues)) {
92 3
            $inputValues = ['FOO', 'BAR', 'BAZ'];
93
        }
94
95 12
        $outputValues = [];
96 12
        $mapIndex = 0;
97
98 12
        foreach ($inputValues as $inputValue) {
0 ignored issues
show
The expression $inputValues of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
99 12
            $parts = explode('=', $inputValue);
100 12
            $outputValues[$parts[0]] = ($parts[1] ?? $mapIndex++);
101
        }
102
103 12
        return $outputValues;
104
    }
105
106
    /**
107
     * Replace the docblock for the given stub.
108
     *
109
     * @param string $stub
110
     *
111
     * @return $this
112
     */
113 12
    protected function replaceDocblock(&$stub)
114
    {
115 12
        $docBlock = [];
116 12
        foreach ($this->getConstants() as $const => $value) {
117 12
            $docBlock[] = " * @method static DummyClass {$const}()";
118
        }
119
120 12
        $stub = str_replace('DOCBLOCK', implode(PHP_EOL, $docBlock), $stub);
121
122 12
        return $this;
123
    }
124
125
    /**
126
     * Replace the constants for the given stub.
127
     *
128
     * @param string $stub
129
     *
130
     * @return $this
131
     */
132 12
    protected function replaceConstants(&$stub)
133
    {
134 12
        $constList = [];
135 12
        foreach ($this->getConstants() as $const => $value) {
136 12
            $constList[] = is_int($value) ? "    const {$const} = {$value};" : "    const {$const} = '{$value}';";
137
        }
138
139 12
        $stub = str_replace(['DEFAULTVALUE', 'CONSTLIST'], [array_keys($this->getConstants())[0], implode(PHP_EOL, $constList)], $stub);
140
141 12
        return $this;
142
    }
143
}
144