Jitamin /
jitamin
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 | |||
| 16 | /** |
||
| 17 | * Metadata. |
||
| 18 | */ |
||
| 19 | abstract class MetadataModel extends Model |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Get the table. |
||
| 23 | * |
||
| 24 | * @abstract |
||
| 25 | * |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | abstract protected function getTable(); |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Define the entity key. |
||
| 32 | * |
||
| 33 | * @abstract |
||
| 34 | * |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | abstract protected function getEntityKey(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Get all metadata for the entity. |
||
| 41 | * |
||
| 42 | * @param int $entity_id |
||
| 43 | * |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | public function getAll($entity_id) |
||
| 47 | { |
||
| 48 | return $this->db |
||
|
0 ignored issues
–
show
|
|||
| 49 | ->hashtable($this->getTable()) |
||
| 50 | ->eq($this->getEntityKey(), $entity_id) |
||
| 51 | ->asc('name') |
||
| 52 | ->getAll('name', 'value'); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Get a metadata for the given entity. |
||
| 57 | * |
||
| 58 | * @param int $entity_id |
||
| 59 | * @param string $name |
||
| 60 | * @param string $default |
||
| 61 | * |
||
| 62 | * @return mixed |
||
| 63 | */ |
||
| 64 | public function get($entity_id, $name, $default = '') |
||
| 65 | { |
||
| 66 | return $this->db |
||
|
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 67 | ->table($this->getTable()) |
||
| 68 | ->eq($this->getEntityKey(), $entity_id) |
||
| 69 | ->eq('name', $name) |
||
| 70 | ->findOneColumn('value') ?: $default; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Return true if a metadata exists. |
||
| 75 | * |
||
| 76 | * @param int $entity_id |
||
| 77 | * @param string $name |
||
| 78 | * |
||
| 79 | * @return bool |
||
| 80 | */ |
||
| 81 | public function exists($entity_id, $name) |
||
| 82 | { |
||
| 83 | return $this->db |
||
|
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 84 | ->table($this->getTable()) |
||
| 85 | ->eq($this->getEntityKey(), $entity_id) |
||
| 86 | ->eq('name', $name) |
||
| 87 | ->exists(); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Update or insert new metadata. |
||
| 92 | * |
||
| 93 | * @param int $entity_id |
||
| 94 | * @param array $values |
||
| 95 | * |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | public function save($entity_id, array $values) |
||
| 99 | { |
||
| 100 | $results = []; |
||
| 101 | $user_id = $this->userSession->getId(); |
||
|
0 ignored issues
–
show
The property
userSession does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 102 | $timestamp = time(); |
||
| 103 | |||
| 104 | $this->db->startTransaction(); |
||
|
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 105 | |||
| 106 | foreach ($values as $key => $value) { |
||
| 107 | if ($this->exists($entity_id, $key)) { |
||
| 108 | $results[] = $this->db->table($this->getTable()) |
||
|
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 109 | ->eq($this->getEntityKey(), $entity_id) |
||
| 110 | ->eq('name', $key) |
||
| 111 | ->update([ |
||
| 112 | 'value' => $value, |
||
| 113 | 'changed_on' => $timestamp, |
||
| 114 | 'changed_by' => $user_id, |
||
| 115 | ]); |
||
| 116 | } else { |
||
| 117 | $results[] = $this->db->table($this->getTable())->insert([ |
||
|
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 118 | 'name' => $key, |
||
| 119 | 'value' => $value, |
||
| 120 | $this->getEntityKey() => $entity_id, |
||
| 121 | 'changed_on' => $timestamp, |
||
| 122 | 'changed_by' => $user_id, |
||
| 123 | ]); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | $this->db->closeTransaction(); |
||
|
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 128 | |||
| 129 | return !in_array(false, $results, true); |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Remove a metadata. |
||
| 134 | * |
||
| 135 | * @param int $entity_id |
||
| 136 | * @param string $name |
||
| 137 | * |
||
| 138 | * @return bool |
||
| 139 | */ |
||
| 140 | public function remove($entity_id, $name) |
||
| 141 | { |
||
| 142 | return $this->db->table($this->getTable()) |
||
|
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\MetadataModel>. 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. Loading history...
|
|||
| 143 | ->eq($this->getEntityKey(), $entity_id) |
||
| 144 | ->eq('name', $name) |
||
| 145 | ->remove(); |
||
| 146 | } |
||
| 147 | } |
||
| 148 |
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@propertyannotation 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.