Issues (85)

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/Fields/FieldFactory.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 namespace Mascame\Artificer\Fields;
2
3
use Mascame\Artificer\Model\Model;
4
use Mascame\Artificer\Options\AdminOption;
5
use Mascame\Artificer\Options\FieldOption;
6
use \Illuminate\Support\Str as Str;
7
8
class FieldFactory
9
{
10
11
    public $fieldClass;
12
    public $fields;
13
    public $related_fields = null;
14
    public $custom_fields = null;
15
16
    /**
17
     * @var FieldParser
18
     */
19
    public $parser;
20
21
    /**
22
     * @var Model
23
     */
24
    public $modelObject;
25
    public $data;
26
27
    public $namespace = '\Mascame\Artificer\Fields\Types\\';
28
29
    public $classMap = array();
30
31
    /**
32
     * @param Model $model
33
     */
34
    public function __construct(Model $model)
35
    {
36
        $this->classMap = AdminOption::get('classmap');
0 ignored issues
show
Documentation Bug introduced by
It seems like \Mascame\Artificer\Optio...Option::get('classmap') of type * is incompatible with the declared type array of property $classMap.

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...
37
        $this->modelObject = $model;
38
        $this->parser = new FieldParser(AdminOption::get('fields.types'));
39
    }
40
41
    /**
42
     * @param $type
43
     * @param $field
44
     * @param $value
45
     * @return mixed
46
     * @throws \Exception
47
     */
48
    public function make($type, $field, $value)
49
    {
50
        $fieldClass = $this->getFieldTypeClass($type);
51
52
        return new $fieldClass($field, $value, $this->isRelation($field));
53
    }
54
55
    /**
56
     * @param $type
57
     * @throws \Exception
58
     */
59
    public function getFieldTypeClass($type)
60
    {
61
        if (isset($this->classMap[$type])) {
62
            return $this->classMap[$type];
63
        }
64
65
        if (class_exists($this->namespace . Str::studly($type))) {
66
            return $this->namespace . Str::studly($type);
67
        }
68
69
        throw new \Exception("No supported Field type [{$type}]");
70
    }
71
72
    /**
73
     * @param $data
74
     * @return mixed
75
     */
76
    public function makeFields($data)
77
    {
78
        $this->data = $data;
79
80
        $this->withCustomFields();
81
82
        foreach ($this->withRelated() as $field) {
83
84
            $fieldType = $this->getTypeFromConfig($field);
85
86
            if (!$fieldType) $fieldType = $this->parser->parse($field);
87
88
            $this->fields[$field] = $this->make(
89
                $fieldType,
90
                $field,
91
                $this->fieldValue($field)
92
            );
93
        }
94
95
        return $this->fields;
96
    }
97
98
    /**
99
     * @param $name
100
     * @return bool|mixed
101
     */
102
    protected function getTypeFromConfig($name) {
103
        if (FieldOption::has('type', $name) || FieldOption::has('relationship.type', $name)) {
104
            return (FieldOption::has('type', $name)) ? FieldOption::get('type',
105
                $name) : FieldOption::get('relationship.type', $name);
106
        }
107
108
        return false;
109
    }
110
111
    /**
112
     * @param $name
113
     * @return bool
114
     */
115
    protected function isRelation($name)
116
    {
117
        return in_array($name, $this->related_fields);
118
    }
119
120
    /**
121
     * @return array|null
122
     */
123
    public function getRelated()
124
    {
125
        if ($this->related_fields != null) {
126
            return $this->related_fields;
127
        }
128
129
        if (null == $fields = FieldOption::all()) {
130
            return $this->related_fields = array();
131
        }
132
133
        /*
134
         * We compare columns with config array to determine if there are new fields
135
         */
136
        $this->related_fields = array_diff(array_keys($fields), $this->modelObject->columns);
137
138
        return $this->related_fields;
139
    }
140
141
    /**
142
     * @return array
143
     */
144
    protected function addRelated()
145
    {
146
        $related = $this->getRelated();
147
148
        if (!empty($related)) {
149
            foreach ($related as $field) {
150
                $this->modelObject->columns[] = $field;
151
            }
152
        }
153
154
        return $this->modelObject->columns;
155
    }
156
157
    /**
158
     * @return array
159
     */
160
    protected function withRelated()
161
    {
162
        return $this->addRelated();
163
    }
164
165
    /**
166
     * @return array
167
     */
168
    protected function addCustomFields()
169
    {
170
        if (isset($this->modelObject->options['fields'])) {
171
            foreach ($this->modelObject->options['fields'] as $name => $data) {
172
                if (!in_array($name, $this->modelObject->columns)) {
173
                    $this->modelObject->columns[] = $name;
174
                }
175
            }
176
        }
177
178
        return $this->modelObject->columns;
179
    }
180
181
    /**
182
     * @return array
183
     */
184
    protected function withCustomFields()
185
    {
186
        return $this->addCustomFields();
187
    }
188
189
    /**
190
     * @param $field
191
     * @return null
192
     */
193
    public function fieldValue($field)
194
    {
195
        return (isset($this->data->$field)) ? $this->data->$field : null;
196
    }
197
198
}