Issues (29)

Security Analysis    not enabled

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/Commands/ModuleMake.php (1 issue)

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 Mnabialek\LaravelModular\Console\Commands;
4
5
use Mnabialek\LaravelModular\Models\Module;
6
use Mnabialek\LaravelModular\Traits\Replacer;
7
use Mnabialek\LaravelModular\Console\Traits\ModuleCreator;
8
9
class ModuleMake extends BaseCommand
10
{
11
    use Replacer;
12
    use ModuleCreator;
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'module:make 
19
    {module* : Module name (or multiple module names space separated)} 
20
    {--group= : Stub group name that will be used for creating this module}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Generates new module structure.';
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function proceed()
33
    {
34
        $moduleNames = collect($this->argument('module'))->unique();
35
36
        $stubGroup = $this->getStubGroup();
37
38
        // verify whether stub directory exists
39
        $this->verifyStubGroup($stubGroup);
40
41
        $moduleNames->each(function ($moduleName) use ($stubGroup) {
42
            $module = $this->createModuleObject($moduleName);
43
44
            // module added to configuration or module directory exists
45
            if ($this->laravel['modular']->exists($module->name())
46
                || $this->exists($module->directory())
47
            ) {
48
                $this->warn("[Module {$module->name()}] Module already exists - ignoring");
49
            } else {
50
                // module does not exist - let's create it
51
                $this->createModule($module, $stubGroup);
52
                $this->info("[Module {$module->name()}] Module was generated");
53
            }
54
        });
55
    }
56
57
    /**
58
     * Create module object (it does not mean module exists)
59
     *
60
     * @param string $moduleName
61
     *
62
     * @return Module
63
     */
64
    protected function createModuleObject($moduleName)
65
    {
66
        return new Module($moduleName, $this->laravel);
67
    }
68
69
    /**
70
     * Create module
71
     *
72
     * @param Module $module
73
     * @param string $stubGroup
74
     */
75
    protected function createModule(Module $module, $stubGroup)
76
    {
77
        // first create directories
78
        $this->createModuleDirectories($module, $stubGroup);
79
80
        // now create files
81
        $this->createModuleFiles($module, $stubGroup);
82
83
        // finally add module to configuration (if not disabled in config)
84
        $this->addModuleToConfigurationFile($module);
85
    }
86
87
    /**
88
     * Add module to configuration file
89
     *
90
     * @param $module
91
     */
92
    protected function addModuleToConfigurationFile(Module $module)
93
    {
94
        $configFile = $this->laravel['modular.config']->configPath();
95
96
        if (!$this->laravel['modular.config']->autoAdd()) {
97
            $this->info("[Module {$module->name()}] - auto-adding to config file turned off\n" .
98
                "Please add this module manually into {$configFile} file if you want to use it");
99
100
            return;
101
        }
102
103
        // getting modified content of config file
104
        $result =
105
            preg_replace_callback($this->laravel['modular.config']->autoAddPattern(),
106
                function ($matches) use ($module, $configFile) {
107
                    return $matches[1] . $matches[2] .
108
                    $this->replace($this->laravel['modular.config']->autoAddTemplate(),
109
                        $module) .
110
                    $matches[3];
111
                },
112
                $this->laravel['files']->get($configFile), -1, $count);
113
114
        if ($count) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $count of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
115
            // found place where new module should be added into config file
116
            $this->laravel['files']->put($configFile, $result);
117
            $this->comment("[Module {$module->name()}] Added into config file {$configFile}");
118
        } else {
119
            // cannot add module to config file automatically
120
            $this->warn("[Module {$module->name()}] It was impossible to add module into {$configFile}" .
121
                " file.\n Please make sure you haven't changed structure of this file. " .
122
                "At the moment add <info>{$module->name()}</info> to this file manually");
123
        }
124
    }
125
}
126