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 | * Upgrade object for upgrades that need to be tracked |
||
5 | * and listed in the admin area. |
||
6 | * |
||
7 | * @todo Expand for all upgrades to be \ElggUpgrade subclasses. |
||
8 | */ |
||
9 | |||
10 | use Elgg\TimeUsing; |
||
11 | use Elgg\Upgrade\Batch; |
||
12 | |||
13 | /** |
||
14 | * Represents an upgrade that runs outside of the upgrade.php script. |
||
15 | * |
||
16 | * @package Elgg.Admin |
||
17 | * @access private |
||
18 | */ |
||
19 | class ElggUpgrade extends ElggObject { |
||
20 | |||
21 | use TimeUsing; |
||
22 | |||
23 | private $requiredProperties = [ |
||
24 | 'id', |
||
25 | 'title', |
||
26 | 'description', |
||
27 | 'class', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Do not use. |
||
32 | * |
||
33 | * @access private |
||
34 | * @var callable |
||
35 | */ |
||
36 | public $_callable_egefps = 'elgg_get_entities_from_private_settings'; |
||
37 | |||
38 | /** |
||
39 | * Set subtype to upgrade |
||
40 | * |
||
41 | * @return null |
||
42 | */ |
||
43 | 11 | public function initializeAttributes() { |
|
44 | 11 | parent::initializeAttributes(); |
|
45 | |||
46 | 11 | $this->attributes['subtype'] = 'elgg_upgrade'; |
|
47 | |||
48 | // unowned |
||
49 | 11 | $this->attributes['container_guid'] = 0; |
|
50 | 11 | $this->attributes['owner_guid'] = 0; |
|
51 | |||
52 | 11 | $this->is_completed = 0; |
|
1 ignored issue
–
show
|
|||
53 | 11 | } |
|
54 | |||
55 | /** |
||
56 | * Mark this upgrade as completed |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | 1 | public function setCompleted() { |
|
61 | 1 | $this->setCompletedTime(); |
|
62 | 1 | return $this->is_completed = true; |
|
1 ignored issue
–
show
The property
is_completed does not exist on object<ElggUpgrade> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?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.");
}
}
}
Since the property has write access only, you can use the @property-write 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...
|
|||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Has this upgrade completed? |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function isCompleted() { |
||
71 | return (bool) $this->is_completed; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Sets an unique id for the upgrade |
||
76 | * |
||
77 | * @param string $id Upgrade id in format <plugin_name>:<yyymmddhh> |
||
78 | * @return void |
||
79 | */ |
||
80 | 5 | public function setID($id) { |
|
81 | 5 | $this->id = $id; |
|
1 ignored issue
–
show
The property
id does not exist on object<ElggUpgrade> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?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.");
}
}
}
Since the property has write access only, you can use the @property-write 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...
|
|||
82 | 5 | } |
|
83 | |||
84 | /** |
||
85 | * Sets a class for the upgrade |
||
86 | * |
||
87 | * @param string $class Fully qualified class name |
||
88 | * @return void |
||
89 | */ |
||
90 | 9 | public function setClass($class) { |
|
91 | 9 | $this->class = $class; |
|
1 ignored issue
–
show
The property
class does not exist on object<ElggUpgrade> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?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.");
}
}
}
Since the property has write access only, you can use the @property-write 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...
|
|||
92 | 9 | } |
|
93 | |||
94 | /** |
||
95 | * Return instance of the class that processes the data |
||
96 | * |
||
97 | * @return Batch|false |
||
98 | */ |
||
99 | 5 | public function getBatch() { |
|
100 | 5 | return _elgg_services()->upgradeLocator->getBatch($this->class); |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Sets the timestamp for when the upgrade completed. |
||
105 | * |
||
106 | * @param int $time Timestamp when upgrade finished. Defaults to now. |
||
107 | * @return bool |
||
108 | */ |
||
109 | 1 | public function setCompletedTime($time = null) { |
|
110 | 1 | if (!$time) { |
|
111 | 1 | $time = $this->getCurrentTime()->getTimestamp(); |
|
112 | } |
||
113 | |||
114 | 1 | return $this->completed_time = $time; |
|
1 ignored issue
–
show
The property
completed_time does not exist on object<ElggUpgrade> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?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.");
}
}
}
Since the property has write access only, you can use the @property-write 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...
|
|||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Gets the time when the upgrade completed. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public function getCompletedTime() { |
||
123 | return $this->completed_time; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Require an upgrade page. |
||
128 | * |
||
129 | * @return mixed |
||
130 | * @throws UnexpectedValueException |
||
131 | */ |
||
132 | 9 | public function save() { |
|
133 | 9 | foreach ($this->requiredProperties as $prop) { |
|
134 | 9 | if (!$this->$prop) { |
|
135 | 9 | throw new UnexpectedValueException("ElggUpgrade objects must have a value for the $prop property."); |
|
136 | } |
||
137 | } |
||
138 | |||
139 | 5 | return parent::save(); |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * Set a value as private setting or attribute. |
||
144 | * |
||
145 | * Attributes include title and description. |
||
146 | * |
||
147 | * @param string $name Name of the attribute or private_setting |
||
148 | * @param mixed $value Value to be set |
||
149 | * @return void |
||
150 | */ |
||
151 | 11 | public function __set($name, $value) { |
|
152 | 11 | if (array_key_exists($name, $this->attributes)) { |
|
153 | 9 | parent::__set($name, $value); |
|
154 | } else { |
||
155 | 11 | $this->setPrivateSetting($name, $value); |
|
156 | } |
||
157 | 11 | } |
|
158 | |||
159 | /** |
||
160 | * Get an attribute or private setting value |
||
161 | * |
||
162 | * @param string $name Name of the attribute or private setting |
||
163 | * @return mixed |
||
164 | */ |
||
165 | 11 | public function __get($name) { |
|
166 | // See if its in our base attribute |
||
167 | 11 | if (array_key_exists($name, $this->attributes)) { |
|
168 | 11 | return parent::__get($name); |
|
169 | } |
||
170 | |||
171 | 11 | return $this->getPrivateSetting($name); |
|
172 | } |
||
173 | |||
174 | } |
||
175 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write 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.