This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; |
||
3 | |||
4 | /** |
||
5 | * A wrapper class used to store values transparently in memcache |
||
6 | * Can be enabled or disabled through site configuration |
||
7 | * Also sets a default time if no time is passed to it to enforce caching |
||
8 | **/ |
||
9 | class StatsCache { |
||
10 | private $cache, $round; |
||
11 | |||
12 | public function __construct($config, $debug) { |
||
13 | $this->config = $config; |
||
0 ignored issues
–
show
|
|||
14 | $this->debug = $debug; |
||
0 ignored issues
–
show
The property
debug does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
15 | if (! $config['memcache']['enabled'] ) { |
||
16 | $this->debug->append("Not storing any values in memcache"); |
||
17 | } else { |
||
18 | if (PHP_OS == 'WINNT') { |
||
19 | require_once(CLASS_DIR . '/memcached.class.php'); |
||
20 | } |
||
21 | $this->cache = new Memcached(); |
||
22 | if ($config['memcache']['sasl'] === true) { |
||
23 | $this->cache->setOption(Memcached::OPT_BINARY_PROTOCOL, true); |
||
0 ignored issues
–
show
The method
setOption() does not seem to exist on object<Memcached> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
24 | $this->cache->setSaslAuthData($config['memcache']['sasl']['username'], $config['memcache']['sasl']['password']); |
||
0 ignored issues
–
show
The method
setSaslAuthData() does not seem to exist on object<Memcached> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
25 | } |
||
26 | } |
||
27 | } |
||
28 | |||
29 | public function setRound($round_id) { |
||
30 | $this->round = $round_id; |
||
31 | } |
||
32 | public function getRound() { |
||
33 | return $this->round; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Wrapper around memcache->set |
||
38 | * Do not store values if memcache is disabled |
||
39 | **/ |
||
40 | public function set($key, $value, $expiration=NULL) { |
||
41 | if (! $this->config['memcache']['enabled']) return $value; |
||
42 | View Code Duplication | if (empty($expiration)) |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
43 | $expiration = $this->config['memcache']['expiration'] + rand( -$this->config['memcache']['splay'], $this->config['memcache']['splay']); |
||
44 | $this->debug->append("Storing " . $this->getRound() . '_' . $this->config['memcache']['keyprefix'] . "$key with expiration $expiration", 3); |
||
45 | return $this->cache->set($this->getRound() . '_' . $this->config['memcache']['keyprefix'] . $key, $value, $expiration); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Special memcache->set call bypassing any auto-expiration systems |
||
50 | * Can be used as a static, auto-updated cache via crons |
||
51 | **/ |
||
52 | public function setStaticCache($key, $value, $expiration=NULL) { |
||
53 | if (! $this->config['memcache']['enabled']) return $value; |
||
54 | View Code Duplication | if (empty($expiration)) |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
55 | $expiration = $this->config['memcache']['expiration'] + rand( -$this->config['memcache']['splay'], $this->config['memcache']['splay']); |
||
56 | $this->debug->append("Storing " . $this->config['memcache']['keyprefix'] . "$key with expiration $expiration", 3); |
||
57 | if ($this->cache->set($this->config['memcache']['keyprefix'] . $key, $value, $expiration)) |
||
58 | return $value; |
||
59 | return false; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Wrapper around memcache->get |
||
64 | * Always return false if memcache is disabled |
||
65 | **/ |
||
66 | public function get($key, $cache_cb = NULL, &$cas_token = NULL) { |
||
0 ignored issues
–
show
|
|||
67 | if (! $this->config['memcache']['enabled']) return false; |
||
68 | $this->debug->append("Trying to fetch key " . $this->getRound() . '_' . $this->config['memcache']['keyprefix'] . "$key from cache", 3); |
||
69 | View Code Duplication | if ($data = $this->cache->get($this->getRound() . '_' . $this->config['memcache']['keyprefix'].$key)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
70 | $this->debug->append("Found key in cache", 3); |
||
71 | return $data; |
||
72 | } else { |
||
73 | $this->debug->append("Key not found", 3); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * As the static set call, we try to fetch static data here |
||
79 | **/ |
||
80 | public function getStatic($key, $cache_cb = NULL, &$cas_token = NULL) { |
||
0 ignored issues
–
show
|
|||
81 | if (! $this->config['memcache']['enabled']) return false; |
||
82 | $this->debug->append("Trying to fetch key " . $this->config['memcache']['keyprefix'] . "$key from cache", 3); |
||
83 | View Code Duplication | if ($data = $this->cache->get($this->config['memcache']['keyprefix'].$key)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
84 | $this->debug->append("Found key in cache", 3); |
||
85 | return $data; |
||
86 | } else { |
||
87 | $this->debug->append("Key not found", 3); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Another wrapper, we want to store data in memcache and return the actual data |
||
93 | * for further processing |
||
94 | * @param key string Our memcache key |
||
95 | * @param data mixed Our data to store in Memcache |
||
96 | * @param expiration time Our expiration time, see Memcached documentation |
||
97 | * @return data mixed Return our stored data unchanged |
||
98 | **/ |
||
99 | public function setCache($key, $data, $expiration=NULL) { |
||
100 | if ($this->config['memcache']['enabled']) $this->set($key, $data, $expiration); |
||
101 | return $data; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * This method is invoked if the called method was not realised in this class |
||
106 | **/ |
||
107 | public function __call($name, $arguments) { |
||
108 | if (! $this->config['memcache']['enabled']) return false; |
||
109 | //Invoke method $name of $this->cache class with array of $arguments |
||
110 | return call_user_func_array(array($this->cache, $name), $arguments); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | $memcache = new StatsCache($config, $debug); |
||
115 | $memcache->addServer($config['memcache']['host'], $config['memcache']['port']); |
||
0 ignored issues
–
show
The method
addServer does not exist on object<StatsCache> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when 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 { }
![]() |
|||
116 | // Now we can set our additional key prefix |
||
117 | if ($aTmpBlock = $block->getLast()) { |
||
118 | $iRoundId = $aTmpBlock['id']; |
||
119 | } else { |
||
120 | $iRoundId = 0; |
||
121 | } |
||
122 | $memcache->setRound($iRoundId); |
||
123 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: