Issues (5)

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/Form.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 AnilcanCakir\Former;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\HtmlString;
7
use AnilcanCakir\Former\Fields\Field;
8
use Illuminate\Database\Eloquent\Model;
9
use AnilcanCakir\Former\Contracts\FormerHelper;
0 ignored issues
show
This use statement conflicts with another class in this namespace, AnilcanCakir\Former\FormerHelper.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
11
class Form
12
{
13
    /**
14
     * The form fields.
15
     *
16
     * @var Collection|Field[]
17
     */
18
    protected $fields;
19
20
    /**
21
     * The form model.
22
     *
23
     * @var Model
24
     */
25
    protected $model;
26
27
    /**
28
     * The form theme.
29
     *
30
     * @var string
31
     */
32
    protected $theme;
33
34
    /**
35
     * The helper of former.
36
     *
37
     * @var FormerHelper
38
     */
39
    protected $helper;
40
41
    /**
42
     * The action of form.
43
     *
44
     * @var string
45
     */
46
    protected $action;
47
48
    /**
49
     * The method of form.
50
     *
51
     * @var string
52
     */
53
    protected $method = 'POST';
54
55
    /**
56
     * Form constructor.
57
     *
58
     * @param Model|null $model
59
     * @param FormerHelper $formerHelper
60
     */
61
    public function __construct(Model $model = null, FormerHelper $formerHelper)
62
    {
63
        $this->model = $model;
64
        $this->helper = $formerHelper;
65
66
        $this->fields = new Collection();
67
    }
68
69
    /**
70
     * Get the model fields.
71
     *
72
     * @return Collection
73
     */
74
    public function getFields(): Collection
75
    {
76
        return $this->fields;
77
    }
78
79
    /**
80
     * Set the model fields.
81
     *
82
     * @param string $input
83
     * @param string $name
84
     * @param array $rules
85
     */
86
    public function addField($input, $name, array $rules)
87
    {
88
        /** @var Field $field */
89
        $field = new $input();
90
        $field->setForm($this);
91
        $field->setName($name);
92
        $field->setRules($rules);
93
94
        $this->fields->put($name, $field);
95
    }
96
97
    /**
98
     * Get the form model.
99
     *
100
     * @return Model
101
     */
102
    public function getModel(): Model
103
    {
104
        return $this->model;
105
    }
106
107
    public function getHelper(): FormerHelper
108
    {
109
        return $this->helper;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getAction(): string
116
    {
117
        return $this->action;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getMethod(): string
124
    {
125
        return $this->method;
126
    }
127
128
    /**
129
     * Set the form model.
130
     *
131
     * @param Model $model
132
     */
133
    public function setModel(Model $model)
134
    {
135
        $this->model = $model;
136
    }
137
138
    /**
139
     * Set the form theme.
140
     *
141
     * @param string|null $theme
142
     */
143
    public function setTheme($theme)
144
    {
145
        $this->theme = $theme;
146
    }
147
148
    public function setAction($action)
149
    {
150
        $this->action = $action;
151
    }
152
153
    public function setActionFromRoute($route)
154
    {
155
        $this->action = $this->helper->getUrlByRoute($route);
156
    }
157
158
    public function setMethod($method)
159
    {
160
        $this->method = $method;
161
    }
162
163
    public function start()
164
    {
165
        return new HtmlString(
166
            view($this->helper->getViewPath('form.start', $this->theme), [
167
                'form' => $this,
168
            ])
169
        );
170
    }
171
172
    public function end()
173
    {
174
        return new HtmlString(
175
            view($this->helper->getViewPath('form.start', $this->theme), [
176
                'form' => $this,
177
            ])
178
        );
179
    }
180
181 View Code Duplication
    public function field(string $name)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
182
    {
183
        /** @var Field $field */
184
        $field = $this->fields->get($name);
185
186
        return new HtmlString(
187
            view($this->helper->getViewPath($field->getTemplate(), $this->theme), [
188
                'field' => $field,
189
            ])
190
        );
191
    }
192
193 View Code Duplication
    public function fields()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
194
    {
195
        $html = '';
196
197
        foreach ($this->fields as $field) {
198
            $html .= view($this->helper->getViewPath($field->getTemplate(), $this->theme), [
199
                'field' => $field,
200
            ]);
201
        }
202
203
        return new HtmlString($html);
204
    }
205
}
206