GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#1814)
by
unknown
13:24 queued 02:11
created

XEObject::getMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * Every modules inherits from XEObject class. It includes error, message, and other variables for communicatin purpose.
6
 *
7
 * The name has been changed from Object to ensure compatibility with future versions of PHP.
8
 * See http://www.php.net/manual/en/reserved.other-reserved-words.php
9
 * However, we keep an alias to the old name, for compatibility with existing codebase.
10
 * The alias can be removed in the future if using the name 'Object' actually begins to cause errors.
11
 *
12
 * @author NAVER ([email protected])
13
 */
14
class XEObject
15
{
16
17
	/**
18
	 * Error code. If `0`, it is not an error.
19
	 * @var int
20
	 */
21
	var $error = 0;
22
23
	/**
24
	 * Error message. If `success`, it is not an error.
25
	 * @var string
26
	 */
27
	var $message = 'success';
28
29
	/**
30
	 * An additional variable
31
	 * @var array
32
	 */
33
	var $variables = array();
34
35
	/**
36
	 * http status code.
37
	 * @var int
38
	 */
39
	var $httpStatusCode = NULL;
40
41
	/**
42
	 * Constructor
43
	 *
44
	 * @param int $error Error code
45
	 * @param string $message Error message
46
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
47
	 */
48
	function __construct($error = 0, $message = 'success')
49
	{
50
		$this->setError($error);
51
		$this->setMessage($message);
52
	}
53
54
	/**
55
	 * Setter to set error code
56
	 *
57
	 * @param int $error error code
58
	 * @return void
59
	 */
60
	function setError($error = 0)
61
	{
62
		$this->error = $error;
63
	}
64
65
	/**
66
	 * Getter to retrieve error code
67
	 *
68
	 * @return int Returns an error code
69
	 */
70
	function getError()
71
	{
72
		return $this->error;
73
	}
74
75
	/**
76
	 * Setter to set HTTP status code
77
	 *
78
	 * @param int $code HTTP status code. Default value is `200` that means successful
79
	 * @return void
80
	 */
81
	function setHttpStatusCode($code = '200')
82
	{
83
		$this->httpStatusCode = $code;
0 ignored issues
show
Documentation Bug introduced by
It seems like $code can also be of type string. However, the property $httpStatusCode is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
84
	}
85
86
	/**
87
	 * Getter to retrieve HTTP status code
88
	 *
89
	 * @return int Returns HTTP status code
90
	 */
91
	function getHttpStatusCode()
92
	{
93
		return $this->httpStatusCode;
94
	}
95
96
	/**
97
	 * Setter to set set the error message
98
	 *
99
	 * @param string $message Error message
100
	 * @return bool Alaways returns true.
101
	 */
102
	function setMessage($message = 'success', $type = NULL)
103
	{
104
		if($str = Context::getLang($message))
105
		{
106
			$this->message = $str;
107
		}
108
		else
109
		{
110
			$this->message = $message;
111
		}
112
113
		// TODO This method always returns True. We'd better remove it
114
		return TRUE;
115
	}
116
117
	/**
118
	 * Getter to retrieve an error message
119
	 *
120
	 * @return string Returns message
121
	 */
122
	function getMessage()
123
	{
124
		return $this->message;
125
	}
126
127
	/**
128
	 * Setter to set a key/value pair as an additional variable
129
	 *
130
	 * @param string $key A variable name
131
	 * @param mixed $val A value for the variable
132
	 * @return void
133
	 */
134
	function add($key, $val)
135
	{
136
		$this->variables[$key] = $val;
137
	}
138
139
	/**
140
	 * Method to set multiple key/value pairs as an additional variables
141
	 *
142
	 * @param Object|array $object Either object or array containg key/value pairs to be added
143
	 * @return void
144
	 */
145
	function adds($object)
146
	{
147
		if(is_object($object))
148
		{
149
			$object = get_object_vars($object);
150
		}
151
152
		if(is_array($object))
153
		{
154
			foreach($object as $key => $val)
155
			{
156
				$this->variables[$key] = $val;
157
			}
158
		}
159
	}
160
161
	/**
162
	 * Method to retrieve a corresponding value to a given key
163
	 *
164
	 * @param string $key
165
	 * @return string Returns value to a given key
166
	 */
167
	function get($key)
168
	{
169
		return $this->variables[$key];
170
	}
171
172
	/**
173
	 * Method to retrieve an object containing a key/value pairs
174
	 *
175
	 * @return Object Returns an object containing key/value pairs
176
	 */
177
	function gets()
178
	{
179
		$args = func_get_args();
180
		$output = new stdClass();
181
		foreach($args as $arg)
182
		{
183
			$output->{$arg} = $this->get($arg);
184
		}
185
		return $output;
186
	}
187
188
	/**
189
	 * Method to retrieve an array of key/value pairs
190
	 *
191
	 * @return array
192
	 */
193
	function getVariables()
194
	{
195
		return $this->variables;
196
	}
197
198
	/**
199
	 * Method to retrieve an object of key/value pairs
200
	 *
201
	 * @return Object
202
	 */
203
	function getObjectVars()
204
	{
205
		$output = new stdClass();
206
		foreach($this->variables as $key => $val)
207
		{
208
			$output->{$key} = $val;
209
		}
210
		return $output;
211
	}
212
213
	/**
214
	 * Method to return either true or false depnding on the value in a 'error' variable
215
	 *
216
	 * @return bool Retruns true : error isn't 0 or false : otherwise.
217
	 */
218
	function toBool()
219
	{
220
		// TODO This method is misleading in that it returns true if error is 0, which should be true in boolean representation.
221
		return ($this->error == 0);
222
	}
223
224
	/**
225
	 * Method to return either true or false depnding on the value in a 'error' variable
226
	 *
227
	 * @return bool
228
	 */
229
	function toBoolean()
230
	{
231
		return $this->toBool();
232
	}
233
234
}
235
236
/**
237
 * Define an alias for the XEObject class.
238
 */
239
class_alias('XEObject', 'Object');
240
241
/* End of file Object.class.php */
242
/* Location: ./classes/object/Object.class.php */
243