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
Push — master ( b130b6...8a2f54 )
by gyeong-won
07:36
created

BaseObject::getVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * Every modules inherits from BaseObject class. It includes error, message, and other variables for communicatin purpose.
6
 *
7
 * @author NAVER ([email protected])
8
 */
9
class BaseObject
10
{
11
	/**
12
	 * Error code. If `0`, it is not an error.
13
	 * @var int
14
	 */
15
	var $error = 0;
16
17
	/**
18
	 * Error message. If `success`, it is not an error.
19
	 * @var string
20
	 */
21
	var $message = 'success';
22
23
	/**
24
	 * An additional variable
25
	 * @var array
26
	 */
27
	var $variables = array();
28
29
	/**
30
	 * http status code.
31
	 * @var int
32
	 */
33
	var $httpStatusCode = NULL;
34
35
	/**
36
	 * Constructor
37
	 *
38
	 * @param int $error Error code
39
	 * @param string $message Error message
40
	 * @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...
41
	 */
42
	function __construct($error = 0, $message = 'success')
43
	{
44
		$this->setError($error);
45
		$this->setMessage($message);
46
	}
47
48
	/**
49
	 * Setter to set error code
50
	 *
51
	 * @param int $error error code
52
	 * @return void
53
	 */
54
	function setError($error = 0)
55
	{
56
		$this->error = $error;
57
	}
58
59
	/**
60
	 * Getter to retrieve error code
61
	 *
62
	 * @return int Returns an error code
63
	 */
64
	function getError()
65
	{
66
		return $this->error;
67
	}
68
69
	/**
70
	 * Setter to set HTTP status code
71
	 *
72
	 * @param int $code HTTP status code. Default value is `200` that means successful
73
	 * @return void
74
	 */
75
	function setHttpStatusCode($code = '200')
76
	{
77
		$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...
78
	}
79
80
	/**
81
	 * Getter to retrieve HTTP status code
82
	 *
83
	 * @return int Returns HTTP status code
84
	 */
85
	function getHttpStatusCode()
86
	{
87
		return $this->httpStatusCode;
88
	}
89
90
	/**
91
	 * Setter to set set the error message
92
	 *
93
	 * @param string $message Error message
94
	 * @return bool Alaways returns true.
95
	 */
96
	function setMessage($message = 'success', $type = NULL)
97
	{
98
		if($str = Context::getLang($message))
99
		{
100
			$this->message = $str;
101
		}
102
		else
103
		{
104
			$this->message = $message;
105
		}
106
107
		// TODO This method always returns True. We'd better remove it
108
		return TRUE;
109
	}
110
111
	/**
112
	 * Getter to retrieve an error message
113
	 *
114
	 * @return string Returns message
115
	 */
116
	function getMessage()
117
	{
118
		return $this->message;
119
	}
120
121
	/**
122
	 * Setter to set a key/value pair as an additional variable
123
	 *
124
	 * @param string $key A variable name
125
	 * @param mixed $val A value for the variable
126
	 * @return void
127
	 */
128
	function add($key, $val)
129
	{
130
		$this->variables[$key] = $val;
131
	}
132
133
	/**
134
	 * Method to set multiple key/value pairs as an additional variables
135
	 *
136
	 * @param BaseObject|array $object Either object or array containg key/value pairs to be added
137
	 * @return void
138
	 */
139
	function adds($object)
140
	{
141
		if(is_object($object))
142
		{
143
			$object = get_object_vars($object);
144
		}
145
146
		if(is_array($object))
147
		{
148
			foreach($object as $key => $val)
149
			{
150
				$this->variables[$key] = $val;
151
			}
152
		}
153
	}
154
155
	/**
156
	 * Method to retrieve a corresponding value to a given key
157
	 *
158
	 * @param string $key
159
	 * @return string Returns value to a given key
160
	 */
161
	function get($key)
162
	{
163
		return $this->variables[$key];
164
	}
165
166
	/**
167
	 * Method to retrieve an object containing a key/value pairs
168
	 *
169
	 * @return BaseObject Returns an object containing key/value pairs
170
	 */
171
	function gets()
172
	{
173
		$args = func_get_args();
174
		$output = new stdClass();
175
		foreach($args as $arg)
176
		{
177
			$output->{$arg} = $this->get($arg);
178
		}
179
		return $output;
180
	}
181
182
	/**
183
	 * Method to retrieve an array of key/value pairs
184
	 *
185
	 * @return array
186
	 */
187
	function getVariables()
188
	{
189
		return $this->variables;
190
	}
191
192
	/**
193
	 * Method to retrieve an object of key/value pairs
194
	 *
195
	 * @return BaseObject
196
	 */
197
	function getObjectVars()
198
	{
199
		$output = new stdClass();
200
		foreach($this->variables as $key => $val)
201
		{
202
			$output->{$key} = $val;
203
		}
204
		return $output;
205
	}
206
207
	/**
208
	 * Method to return either true or false depnding on the value in a 'error' variable
209
	 *
210
	 * @return bool Retruns true : error isn't 0 or false : otherwise.
211
	 */
212
	function toBool()
213
	{
214
		// TODO This method is misleading in that it returns true if error is 0, which should be true in boolean representation.
215
		return ($this->error == 0);
216
	}
217
218
	/**
219
	 * Method to return either true or false depnding on the value in a 'error' variable
220
	 *
221
	 * @return bool
222
	 */
223
	function toBoolean()
224
	{
225
		return $this->toBool();
226
	}
227
228
}
229
/* End of file BaseObject.class.php */
230
/* Location: ./classes/object/BaseObject.class.php */
231