Issues (8)

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/SmartMeta.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
 * Created by PhpStorm.
4
 * User: alive
5
 * Date: 5/7/18
6
 * Time: 8:10 AM
7
 */
8
9
namespace Alive2212\LaravelSmartMeta;
10
11
use Illuminate\Support\Facades\Cache;
12
13
trait SmartMeta
14
{
15
    protected $id;
16
17
    protected $cacheMetas;
18
19
    protected $globalKey;
20
21
    protected $expireTime = 5; // 5 minutes
22
23
    /**
24
     *
25
     *
26
     * @return $this
27
     */
28
    public function initCache()
29
    {
30
        if(!($this->id>0)){
31
            $this->id = $this->toArray()['id'];
0 ignored issues
show
It seems like toArray() 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...
32
        }
33
        if (is_null($this->globalKey)){
34
            $this->globalKey = get_class($this) . '_' . $this->id;
35
        }
36
        $this->getAllCacheMeta();
37
        return $this;
38
    }
39
40
    /**
41
     *
42
     *
43
     * @param $key
44
     * @param $value
45
     * @return $this
46
     */
47
    public function putCacheMeta($key, $value)
48
    {
49
        $this->initCache();
50
        $value = [$key => $value];
51
        Cache::put($this->globalKey, $value, $this->expireTime);
52
        return $this;
53
    }
54
55
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
//     * @return array
57
//     */
58
//    public function getAllCacheMeta(): array
59
//    {
60
//        return (Cache::get($this->globalKey));
61
//    }
62
63
64
    /**
65
     * @param $key
66
     * @param null $default
67
     * @param bool $getObj
68
     * @return null
69
     */
70
    public function getCacheMeta($key, $default = null, $getObj = false)
0 ignored issues
show
The parameter $getObj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        $this->initCache();
73
        if (isset($this->cacheMetas[$key])) {
74
            return $this->cacheMetas[$key];
75
        }
76
        return $default;
77
    }
78
79
    /**
80
     * @param $key
81
     * @return $this
82
     */
83
    public function deleteCacheMeta($key)
84
    {
85
        $this->initCache();
86
        unset($this->cacheMetas[$key]);
87
        $this->setAllCacheMeta();
88
        return $this;
89
    }
90
91
    /**
92
     *
93
     */
94
    public function deleteCacheMetas()
95
    {
96
        $this->initCache();
97
        $this->cacheMetas = null;
98
        $this->setAllCacheMeta();
99
        return $this;
100
    }
101
102
    /**
103
     * @param $key
104
     * @param $value
105
     */
106
    public function addCacheMeta($key, $value)
107
    {
108
        $this->initCache();
109
        $this->cacheMetas = array_add($this->cacheMetas, $key, $value);
110
        $this->setAllCacheMeta();
111
    }
112
113
    /**
114
     * @param $value
115
     * @return $this
116
     */
117
    public function pushCacheMeta($value)
118
    {
119
        $this->initCache();
120
        array_push($this->cacheMetas, $value);
121
        $this->setAllCacheMeta();
122
        return $this;
123
    }
124
125
    /**
126
     * @param $key
127
     * @param $default
128
     * @return $this
129
     */
130
    public function pullCacheMeta($key, $default = null)
131
    {
132
        $this->initCache();
133
        array_pull($this->cacheMetas, $key, $default);
134
        $this->setAllCacheMeta();
135
        return $this;
136
    }
137
138
    /**
139
     * @return $this
140
     */
141
    public function setAllCacheMeta()
142
    {
143
        Cache::put($this->globalKey, $this->cacheMetas, $this->expireTime);
144
        return $this;
145
    }
146
147
    /**
148
     * @return $this
149
     */
150
    public function getAllCacheMeta()
151
    {
152
        $this->cacheMetas = Cache::get($this->globalKey);
153
        return $this;
154
    }
155
156
    /**
157
     * @return mixed
158
     */
159 1
    public function getId()
160
    {
161 1
        return $this->id;
162
    }
163
164
    /**
165
     * @param mixed $id
166
     */
167 1
    public function setId($id)
168
    {
169 1
        $this->id = $id;
170 1
    }
171
172
    /**
173
     * @return mixed
174
     */
175
    public function getGlobalKey()
176
    {
177
        return $this->globalKey;
178
    }
179
180
    /**
181
     * @param mixed $globalKey
182
     */
183 1
    public function setGlobalKey($globalKey)
184
    {
185 1
        $this->globalKey = $globalKey;
186 1
    }
187
188
    /**
189
     * @return int
190
     */
191
    public function getExpireTime(): int
192
    {
193
        return $this->expireTime;
194
    }
195
196
    /**
197
     * @param int $expireTime
198
     */
199
    public function setExpireTime(int $expireTime)
200
    {
201
        $this->expireTime = $expireTime;
202
    }
203
204
    /**
205
     * @return mixed
206
     */
207
    public function getCacheMetas()
208
    {
209
        return $this->cacheMetas;
210
    }
211
212
    /**
213
     * @param mixed $cacheMetas
214
     */
215
    public function setCacheMetas($cacheMetas)
216
    {
217
        $this->cacheMetas = $cacheMetas;
218
    }
219
}