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/Model/ModelSchema.php (2 issues)

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 Mascame\Artificer\Model;
2
3
use Schema;
4
5
// Todo: get column type http://stackoverflow.com/questions/18562684/how-to-get-database-field-type-in-laravel
6
class ModelSchema
7
{
8
9
    /**
10
     * @var array
11
     */
12
    public $tables;
13
14
    /**
15
     * @var array
16
     */
17
    public $models;
18
19
    /**
20
     * @var string
21
     */
22
    public $class;
23
24
25
    /**
26
     * @var array
27
     */
28
    public $columns;
29
30
    /**
31
     * @param ModelObtainer $modelObtainer
32
     */
33
    public function __construct(ModelObtainer $modelObtainer)
34
    {
35
        $this->models = $modelObtainer->models;
36
        $this->tables = $this->getTables($this->models);
37
    }
38
39
    /**
40
     * @param $column
41
     * @return bool
42
     */
43
    public function hasColumn($column)
44
    {
45
        return (is_array($column) && in_array($column, $this->columns)) ? true : false;
46
    }
47
48
    /**
49
     * @param $table
50
     * @return bool
51
     */
52
    public function hasTable($table)
53
    {
54
        return Schema::hasTable($table);
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60
    public function getTable($modelName)
61
    {
62
        if (!$modelName) {
63
            $modelName = Model::getCurrent();
0 ignored issues
show
Are you sure the assignment to $modelName is correct as \Mascame\Artificer\Model\Model::getCurrent() (which targets Mascame\Artificer\Model\Model::getCurrent()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
64
        }
65
66
        if (isset($this->models[$modelName]['table'])) {
67
            return $this->models[$modelName]['table'];
68
        }
69
70
        return $this->getInstance($modelName)->getTable();
71
    }
72
73
    /**
74
     * @param $models
75
     * @return array
76
     */
77
    public function getTables($models)
78
    {
79
        $tables = array();
80
81
        foreach ($models as $model) {
82
            $table = $this->getTable($model['name']);
83
            $this->models[$model['name']]['table'] = $table;
84
            $tables[] = $table;
85
        }
86
87
        return $tables;
88
    }
89
90
    /**
91
     * @param $table
92
     * @return array
93
     */
94
    public function getColumns($table)
95
    {
96
        return Schema::getColumnListing($table);
97
    }
98
99
    /**
100
     * @param $modelName
101
     * @return mixed
102
     */
103
    public function instantiate($modelName)
104
    {
105
        $modelClass = $this->getClass($modelName);
106
107
        if ($this->isFake($modelName)) {
108
            $instance = (new FakeModel())->setup($this->models[$modelName]['fake']);
109
        } else {
110
            $instance = new $modelClass;
111
        }
112
113
        return $this->models[$modelName]['instance'] = $instance;
114
    }
115
116
    public function isFake($modelName)
117
    {
118
        return (isset($this->models[$modelName]['fake']) && $this->models[$modelName]['fake'] !== false);
119
    }
120
121
    /**
122
     * @param $modelName
123
     * @return bool
124
     */
125
    public function hasInstance($modelName)
126
    {
127
        return isset($this->models[$modelName]['instance']);
128
    }
129
130
    /**
131
     * @param null $modelName
132
     * @return mixed
133
     */
134
    public function getInstance($modelName = null)
135
    {
136
        ($modelName) ?: $modelName = Model::getCurrent();
0 ignored issues
show
Are you sure the assignment to $modelName is correct as \Mascame\Artificer\Model\Model::getCurrent() (which targets Mascame\Artificer\Model\Model::getCurrent()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
137
138
        if ($this->hasInstance($modelName)) {
139
            return $this->models[$modelName]['instance'];
140
        }
141
142
        return $this->instantiate($modelName);
143
    }
144
145
    /**
146
     * @param $modelName
147
     * @return string
148
     */
149
    public function getClass($modelName)
150
    {
151
        if (! in_array($modelName, array_keys($this->models))) return null;
152
153
        $model = $this->models[$modelName];
154
155
        return $model['namespace'] . '\\' . $model['name'];
156
    }
157
158
}