Issues (4)

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/MakeViewCommand.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
2
3
namespace Ngtfkx\Laradeck\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Str;
7
8
class MakeViewCommand extends Command
9
{
10
    protected $signature = 'laradeck:view 
11
                            {name : View name with dot syntax} 
12
                            {--F|force : Rewrite exists view} 
13
                            {--extends= : Extends directive} 
14
                            {--section=* : Section directive} 
15
                            {--stack=* : Push directive} 
16
                            {--component=* : Component directive}
17
                            ';
18
19
    protected $description = 'Create a new view';
20
21
    /**
22
     * @var string
23
     */
24
    protected $view;
25
26
    /**
27
     * @var bool
28
     */
29
    protected $force;
30
31
    /**
32
     * @var string
33
     */
34
    protected $extends;
35
36
    /**
37
     * @var array
38
     */
39
    protected $sections;
40
41
    /**
42
     * @var array
43
     */
44
    protected $stacks;
45
46
    /**
47
     * @var array
48
     */
49
    protected $components;
50
51
    public function __construct()
52
    {
53
        parent::__construct();
54
    }
55
56
    public function handle()
57
    {
58
        $this->view = $this->argument('name');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->argument('name') can also be of type array. However, the property $view is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
59
60
        $this->force = $this->option('force');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->option('force') of type string or array is incompatible with the declared type boolean of property $force.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
62
        $this->extends = $this->option('extends');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->option('extends') can also be of type array. However, the property $extends is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
63
64
        $this->sections = $this->parse($this->option('section'));
65
66
        $this->stacks = $this->parse($this->option('stack'));
67
68
        $this->components = $this->parse($this->option('component'));
69
70
        $path = $this->path();
71
72
        $content = $this->content();
73
74
        $this->create($path, $content);
75
    }
76
77
    /**
78
     * Get path of view file and create directories for it
79
     *
80
     * @return string
81
     */
82
    protected function path(): string
83
    {
84
        $path = resource_path('views' . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $this->view) . '.blade.php');
85
86
        $directory = dirname($path);
87
88
        if (!is_dir($directory)) {
89
            \File::makeDirectory($directory, 0755, true);
90
        }
91
92
        return $path;
93
    }
94
95
    /**
96
     * Generate content of a view
97
     *
98
     * @return string
99
     */
100
    protected function content(): string
101
    {
102
        $content = '';
103
104
        if ($this->extends) {
105
            $content .= "@extends('" . $this->extends . "')";
106
        }
107
108
        $types = [
109
            'section' => $this->sections,
110
            'component' => $this->components,
111
            'push' => $this->stacks,
112
        ];
113
114
        foreach ($types as $key => $values) {
115
            $content .= $this->blocks($key, $values);
116
        }
117
118
        return $content;
119
    }
120
121
    /**
122
     * Write content to a view
123
     *
124
     * @param string $path
125
     * @param string $content
126
     */
127
    protected function create(string $path, string $content)
128
    {
129
        if ($this->force || !file_exists($path)) {
130
            \File::put($path, $content);
131
            $this->info('View created successfully.');
132
        } else {
133
            $this->error('View already exists!');
134
        }
135
    }
136
137
    /**
138
     * @param $value
139
     * @return array
140
     */
141
    protected function parse($value): array
142
    {
143
        $values = [];
144
145
        foreach ($value as $item) {
146
            if (Str::contains($item, ',')) {
147
                $values = array_merge($values, explode(',', $item));
148
            } else {
149
                $values[] = $item;
150
            }
151
        }
152
153
        return $values;
154
    }
155
156
    /**
157
     * @param $name
158
     * @param $type
159
     * @return string
160
     */
161
    protected function block($name, $type): string
162
    {
163
        $content = PHP_EOL . PHP_EOL . "@" . $type . "('" . $name . "')" . PHP_EOL;
164
        $content .= "@end" . $type;
165
166
        return $content;
167
    }
168
169
    /**
170
     * @param string $key
171
     * @param array $values
172
     * @return string
173
     */
174
    protected function blocks(string $key, array $values): string
175
    {
176
        $content = '';
177
178
        foreach ($values as $item) {
179
            $content .= $this->block($item, $key);
180
        }
181
182
        return $content;
183
    }
184
}
185