Issues (140)

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/Generators/ClassGenerator.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 namespace Savannabits\JetstreamInertiaGenerator\Generators;
2
3
use Savannabits\JetstreamInertiaGenerator\Generators\Traits\Helpers;
4
use Savannabits\JetstreamInertiaGenerator\Generators\Traits\Names;
5
use Savannabits\JetstreamInertiaGenerator\Generators\Traits\Columns;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\Schema;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Illuminate\Support\Str;
10
use Illuminate\Filesystem\Filesystem;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
abstract class ClassGenerator extends Command {
15
16
    use Helpers, Columns, Names;
17
18
    public string $classBaseName;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
19
    public string $classFullName;
20
    public string $classNamespace;
21
22
    /**
23
     * @var Filesystem
24
     */
25
    protected Filesystem $files;
26
27
    /**
28
     * Relations
29
     *
30
     * @var string
31
     */
32
    protected $relations = [];
33
34
    /**
35
     * Create a new controller creator command instance.
36
     *
37
     * @param Filesystem $files
38
     */
39
    public function __construct(Filesystem $files)
40
    {
41
        parent::__construct();
42
43
        $this->files = $files;
44
    }
45
46
    protected function getArguments(): array
47
    {
48
        return [
49
            ['table_name', InputArgument::REQUIRED, 'Name of the existing table'],
50
            ['class_name', InputArgument::OPTIONAL, 'Name of the generated class'],
51
        ];
52
    }
53
54
    /**
55
     * Generate default class name (for case if not passed as argument) from table name
56
     *
57
     * @param $tableName
58
     * @return mixed
59
     */
60
    abstract public function generateClassNameFromTable($tableName);
61
62
    /**
63
     * Build the class with the given name.
64
     *
65
     * @return string
66
     */
67
    abstract protected function buildClass(): string;
68
69
    public function getPathFromClassName($name) {
70
        $path = str_replace('\\', '/', $name).".php";
71
72
        return preg_replace('|^App/|', 'app/', $path);
73
    }
74
75
    /**
76
     * Get the full namespace for a given class, without the class name.
77
     *
78
     * @param string $name
79
     * @return string
80
     */
81
    protected function getNamespace(string $name): string
82
    {
83
        return trim(implode('\\', array_slice(explode('\\', $name), 0, -1)), '\\');
84
    }
85
86
    /**
87
     * Get the root namespace for the class.
88
     *
89
     * @return string
90
     */
91
    public function rootNamespace(): string
92
    {
93
        return $this->laravel->getNamespace();
94
    }
95
96
    /**
97
     * Parse the class name and format according to the root namespace.
98
     *
99
     * @param string $name
100
     * @return string
101
     */
102
    public function qualifyClass(string $name): string
103
    {
104
        $name = str_replace('/', '\\', $name);
105
106
        $rootNamespace = $this->rootNamespace();
107
108
        if (Str::startsWith($name, $rootNamespace)) {
109
            return $name;
110
        }
111
112
        return $this->qualifyClass(
113
            $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name
114
        );
115
    }
116
117
    /**
118
     * Get the default namespace for the class.
119
     *
120
     * @param string $rootNamespace
121
     * @return string
122
     */
123
    protected function getDefaultNamespace(string $rootNamespace): string
124
    {
125
        return $rootNamespace;
126
    }
127
128
    protected function generateClass($force = false): bool
129
    {
130
        $path = base_path($this->getPathFromClassName($this->classFullName));
131
        if ($this->alreadyExists($path)) {
132
            if($force) {
133
                $this->warn('File '.$path.' already exists! File will be deleted.');
134
                $this->files->delete($path);
135
            } else {
136
                //TODO: Backup the class then generate a new one... for recovery purposes.
137
                $this->error('File '.$path.' already exists!');
138
                return false;
139
            }
140
        }
141
142
        $this->makeDirectory($path);
143
        $this->files->put($path, $this->buildClass());
144
        return true;
145
    }
146
147
    /**
148
     * Execute the console command.
149
     *
150
     * @param InputInterface $input
151
     * @param OutputInterface $output
152
     * @return int
153
     */
154
    protected function execute(InputInterface $input, OutputInterface $output): int
155
    {
156
        if ($this instanceof Model) {
157
            $this->initCommonNames($this->argument('table_name'), $this->argument('class_name'), null, $this->option('model-with-full-namespace'));
158
        } else {
159
            $this->initCommonNames($this->argument('table_name'), $this->option('model-name'), null, $this->option('model-with-full-namespace'));
160
        }
161
162
        $this->initClassNames($this->argument('class_name'));
163
164
        return parent::execute($input, $output);
165
    }
166
167
    protected function initClassNames($className = null) {
168
        if (empty($className)) {
169
            $className = $this->generateClassNameFromTable($this->tableName);
170
        }
171
172
        $this->classFullName = $this->qualifyClass($className);
173
        $this->classBaseName = class_basename($this->classFullName);
174
        $this->classNamespace = Str::replaceLast("\\".$this->classBaseName, '', $this->classFullName);
175
    }
176
177
}
178