Issues (415)

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.

app/Libraries/Metaable/HasMeta.php (5 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 App\Libraries\Metaable;
4
5
use App\Libraries\Metaable\Repository as MetaRepository;
6
7
trait HasMeta
8
{
9
    /**
10
     * @return \Illuminate\Database\Eloquent\Relations\morphMany
11
     */
12
    public function meta()
13
    {
14
        return $this->morphMany(Meta::class, 'metaable');
0 ignored issues
show
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
15
    }
16
17
    /**
18
     * Get meta by key.
19
     *
20
     * @param $key
21
     * @param $group null
22
     * @return mixed
23
     */
24
    public function getMeta($key, $group = null)
25
    {
26
        if (is_null($group))
27
            return $this->meta()->whereKeyUnique($key)->first();
28
29
        return $this->meta()->whereKeyUnique($key)->group($group)->first();
30
    }
31
32
    /**
33
     * Set meta.
34
     *
35
     * @param $key
36
     * @param $value
37
     * @param null $group
38
     * @return mixed
39
     */
40 View Code Duplication
    public function setMeta($meta_data, $group = null)
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...
41
    {
42
        if (!$meta = $this->getMeta($meta_data['key_unique'], $group)) {
43
            return $this->getRepository()->create($this, $meta_data, $group);
44
        } else {
45
            return $this->updateMeta($meta, $meta_data);
46
        }
47
    }
48
49
    /**
50
     * Update Meta.
51
     * 
52
     * @param $meta
53
     * @param $key
54
     * @param $value
55
     * @param null $group
56
     * @return mixed
57
     */
58 View Code Duplication
    public function updateMeta($meta, $meta_data, $group = null)
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...
59
    {
60
        if(is_numeric($meta))
61
            $meta = $this->getRepository()->getModel()->find((int) $meta)->first();
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Libraries\Metaable\Meta>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
62
63
        $meta->key   = $meta_data['key'];
64
        $meta->value = $meta_data['value'];
65
        if(isset($group))
66
            $meta->group = $group;
67
68
        $meta->save();
69
        return $meta;
70
    }
71
72
    /**
73
     * Delete meta.
74
     *
75
     * @param $key
76
     * @param null $group
77
     * @return mixed
78
     */
79
    public function unsetMeta($key, $group = null)
80
    {
81
        return $this->getMeta($key, $group)->delete();
82
    }
83
84
    /**
85
     * Alias for unsetMeta method.
86
     *
87
     * @param $key
88
     * @param null $group
89
     * @return mixed
90
     */
91
    public function removeMeta($meta_data, $group = null)
92
    {
93
        if(isset($group))
94
            return $this->unsetMeta($meta_data['key_unique'], $group);
95
96
        return $this->unsetMeta($meta_data['key_unique']);
97
    }
98
99
    /**
100
     * Remove by id.
101
     * 
102
     * @param $id
103
     */
104
    public function removeMetaById($id)
105
    {
106
        $this->getRepository()->removeById((int) $id);
107
    }
108
    public function removeMetaByKey($key)
109
    {
110
        if ($this->getMeta($key)) {
111
            $this->getRepository()->removeByKey($key);
112
        }
113
    }
114
    public function removeMetaGroupById($group=null, $id=null)
115
    {
116
        if ($id!=null) {
117
            $this->getRepository()->removeGroupById($group,(int)$id);
118
        }
119
    }
120
121
    /**
122
     * Remove group of meta.
123
     *
124
     * @param $groups
125
     * @return $this
126
     */
127 View Code Duplication
    public function removeMetaGroups($groups)
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...
128
    {
129
        if(is_array($groups)) {
130
            array_walk($groups, function ($group) {
131
                $this->getRepository()->removeGroup($group);
132
            });
133
        } else {
134
            $this->getRepository()->removeGroup($groups);
135
        }
136
        
137
        return $this;
138
    }
139
140
    /**
141
     * @param $group
142
     * @return $this
143
     */
144
    public function removeGroup($group)
145
    {
146
        return $this->removeMetaGroups($group);
147
    }
148
149
    /**
150
     * Get other meta.
151
     *
152
     * @return mixed
153
     */
154
    public function getOtherMeta()
155
    {
156
        return $this->getMetaFromGroup('other');
157
    }
158
159
    /**
160
     * Get other meta.
161
     *
162
     * @alias: self::getOtherMeta()
163
     * @return mixed
164
     */
165
    public function getSimpleMeta()
166
    {
167
        return $this->getOtherMeta();
168
    }
169
170
    /**
171
     * Get other meta.
172
     *
173
     * @return mixed
174
     */
175
    public function metaWithoutGroup()
176
    {
177
        return $this->getOtherMeta();
178
    }
179
180
    /**
181
     * Get all meta from specific group.
182
     *
183
     * @param $group
184
     * @return mixed
185
     */
186
    public function getMetaFromGroup($group)
187
    {
188
        return $this->meta()->group($group)->orderBy('id', 'asc')->get();
189
    }
190
191
    /**
192
     * @param $group
193
     * @return mixed
194
     */
195
    public function getMetaGroup($group)
196
    {
197
        return $this->getMetaFromGroup($group);
198
    }
199
200
    /**
201
     * Get meta repository
202
     *
203
     * @return Repository
204
     */
205
    private function getRepository()
206
    {
207
        return new MetaRepository();
208
    }
209
}