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 | |||
3 | /* |
||
4 | * This file is part of Jitamin. |
||
5 | * |
||
6 | * Copyright (C) Jitamin Team |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Jitamin\Model; |
||
13 | |||
14 | use Jitamin\Foundation\Database\Model; |
||
15 | use Jitamin\Foundation\Security\Token; |
||
16 | |||
17 | /** |
||
18 | * Setting model. |
||
19 | */ |
||
20 | class SettingModel extends Model |
||
21 | { |
||
22 | /** |
||
23 | * SQL table name. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | const TABLE = 'settings'; |
||
28 | |||
29 | /** |
||
30 | * Get a config variable with in-memory caching. |
||
31 | * |
||
32 | * @param string $name Parameter name |
||
33 | * @param string $default_value Default value of the parameter |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function get($name, $default_value = '') |
||
38 | { |
||
39 | $options = $this->memoryCache->proxy($this, 'getAll'); |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | return isset($options[$name]) && $options[$name] !== '' ? $options[$name] : $default_value; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Get all settings. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function getAll() |
||
50 | { |
||
51 | return $this->db->hashtable(self::TABLE)->getAll('option', 'value'); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get a setting value. |
||
56 | * |
||
57 | * @param string $name |
||
58 | * @param string $default |
||
59 | * |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function getOption($name, $default = '') |
||
63 | { |
||
64 | $value = $this->db |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
65 | ->table(self::TABLE) |
||
66 | ->eq('option', $name) |
||
67 | ->findOneColumn('value'); |
||
68 | |||
69 | return $value === null || $value === false || $value === '' ? $default : $value; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Return true if a setting exists. |
||
74 | * |
||
75 | * @param string $name |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function exists($name) |
||
80 | { |
||
81 | return $this->db |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
82 | ->table(self::TABLE) |
||
83 | ->eq('option', $name) |
||
84 | ->exists(); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Update or insert new settings. |
||
89 | * |
||
90 | * @param array $values |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function save(array $values) |
||
95 | { |
||
96 | $results = []; |
||
97 | $values = $this->prepare($values); |
||
98 | $user_id = $this->userSession->getId(); |
||
0 ignored issues
–
show
The property
userSession does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
99 | $timestamp = time(); |
||
100 | |||
101 | $this->db->startTransaction(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
102 | |||
103 | foreach ($values as $option => $value) { |
||
104 | if ($this->exists($option)) { |
||
105 | $results[] = $this->db->table(self::TABLE)->eq('option', $option)->update([ |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
106 | 'value' => $value, |
||
107 | 'changed_on' => $timestamp, |
||
108 | 'changed_by' => $user_id, |
||
109 | ]); |
||
110 | } else { |
||
111 | $results[] = $this->db->table(self::TABLE)->insert([ |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
112 | 'option' => $option, |
||
113 | 'value' => $value, |
||
114 | 'changed_on' => $timestamp, |
||
115 | 'changed_by' => $user_id, |
||
116 | ]); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | $this->db->closeTransaction(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
121 | |||
122 | return !in_array(false, $results, true); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Optimize the Sqlite database. |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function optimizeDatabase() |
||
131 | { |
||
132 | return $this->db->getConnection()->exec('VACUUM'); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\SettingModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Compress the Sqlite database. |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | public function downloadDatabase() |
||
141 | { |
||
142 | return gzencode(file_get_contents(DB_FILENAME)); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Get the Sqlite database size in bytes. |
||
147 | * |
||
148 | * @return int |
||
149 | */ |
||
150 | public function getDatabaseSize() |
||
151 | { |
||
152 | return DB_DRIVER === 'sqlite' ? filesize(DB_FILENAME) : 0; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Regenerate a token. |
||
157 | * |
||
158 | * @param string $option Parameter name |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function regenerateToken($option) |
||
163 | { |
||
164 | return $this->save([$option => Token::getToken()]); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Prepare data before save. |
||
169 | * |
||
170 | * @param array $values |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | public function prepare(array $values) |
||
175 | { |
||
176 | if (!empty($values['application_url']) && substr($values['application_url'], -1) !== '/') { |
||
177 | $values['application_url'] = $values['application_url'].'/'; |
||
178 | } |
||
179 | |||
180 | return $values; |
||
181 | } |
||
182 | } |
||
183 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.