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 (#1930)
by
unknown
13:51
created

autoinstallModel::setDepth()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 4
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * Model class of the autoinstall module
6
 * @author NAVER ([email protected])
7
 */
8
class autoinstallModel extends autoinstall
9
{
10
11
	/**
12
	 * Get category information
13
	 *
14
	 * @param int $category_srl The sequence of category to get information
15
	 * @return object
16
	 */
17 View Code Duplication
	function getCategory($category_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
	{
19
		$args = new stdClass();
20
		$args->category_srl = $category_srl;
21
		$output = executeQueryArray("autoinstall.getCategory", $args);
22
		if(!$output->data)
23
		{
24
			return null;
25
		}
26
		return array_shift($output->data);
27
	}
28
29
	/**
30
	 * Get packages information
31
	 *
32
	 * @return array
33
	 */
34
	function getPackages()
35
	{
36
		$output = executeQueryArray("autoinstall.getPackages");
37
		if(!$output->data)
38
		{
39
			return array();
40
		}
41
		return $output->data;
42
	}
43
44
	/**
45
	 * Get installed packages information
46
	 *
47
	 * @param int $package_srl The sequence of package to get information
48
	 * @return object
49
	 */
50 View Code Duplication
	function getInstalledPackage($package_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
	{
52
		$args = new stdClass();
53
		$args->package_srl = $package_srl;
54
		$output = executeQueryArray("autoinstall.getInstalledPackage", $args);
55
		if(!$output->data)
56
		{
57
			return null;
58
		}
59
		return array_shift($output->data);
60
	}
61
62
	/**
63
	 * Get one package information
64
	 *
65
	 * @param int $package_srl The sequence of package to get information
66
	 * @return object
67
	 */
68 View Code Duplication
	function getPackage($package_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
	{
70
		$args = new stdClass();
71
		$args->package_srl = $package_srl;
72
		$output = executeQueryArray("autoinstall.getPackage", $args);
73
		if(!$output->data)
74
		{
75
			return null;
76
		}
77
		return array_shift($output->data);
78
	}
79
80
	/**
81
	 * Get category list
82
	 *
83
	 * @return array
84
	 */
85
	function getCategoryList()
86
	{
87
		$output = executeQueryArray("autoinstall.getCategories");
88
		if(!$output->toBool() || !$output->data)
89
		{
90
			return array();
91
		}
92
93
		$categoryList = array();
94
		foreach($output->data as $category)
95
		{
96
			$category->children = array();
97
			$categoryList[$category->category_srl] = $category;
98
		}
99
100
		$depth0 = array();
101
		foreach($categoryList as $key => $category)
102
		{
103
			if($category->parent_srl)
104
			{
105
				$categoryList[$category->parent_srl]->children[] = & $categoryList[$key];
106
			}
107
			else
108
			{
109
				$depth0[] = $key;
110
			}
111
		}
112
		$resultList = array();
113
		foreach($depth0 as $category_srl)
114
		{
115
			$this->setDepth($categoryList[$category_srl], 0, $categoryList, $resultList);
116
		}
117
		return $resultList;
118
	}
119
120
	/**
121
	 * Get pcakge count in category
122
	 *
123
	 * @param int $category_srl The sequence of category to get count
124
	 * @return int
125
	 */
126
	function getPackageCount($category_srl)
127
	{
128
		$args = new stdClass();
129
		$args->category_srl = $category_srl;
130
		$output = executeQuery("autoinstall.getPackageCount", $args);
131
		if(!$output->data)
132
		{
133
			return 0;
134
		}
135
		return $output->data->count;
136
	}
137
138
	/**
139
	 * Get installed package count
140
	 *
141
	 * @return int
142
	 */
143
	function getInstalledPackageCount()
144
	{
145
		$output = executeQuery("autoinstall.getInstalledPackageCount");
146
		if(!$output->data)
147
		{
148
			return 0;
149
		}
150
		return $output->data->count;
151
	}
152
153
	/**
154
	 * Set depth, children list and package count of category
155
	 *
156
	 * @param object $item Category information
157
	 * @param int $depth Depth of category
158
	 * @param array $list Category list
159
	 * @param array $resultList Final result list
160
	 * @return string $siblingList Comma seperated list
161
	 */
162
	function setDepth(&$item, $depth, &$list, &$resultList)
163
	{
164
		$resultList[$item->category_srl] = &$item;
165
		$item->depth = $depth;
166
		$siblingList = $item->category_srl;
167
		foreach($item->children as $child)
168
		{
169
			$siblingList .= "," . $this->setDepth($list[$child->category_srl], $depth + 1, $list, $resultList);
170
		}
171
		if(count($item->children) < 1)
172
		{
173
			$item->nPackages = $this->getPackageCount($item->category_srl);
174
		}
175
		$item->childrenList = $siblingList;
176
		return $siblingList;
177
	}
178
179
	/**
180
	 * Get lastest package information
181
	 *
182
	 * @return object Returns lastest package information. If no result returns null.
183
	 */
184
	function getLatestPackage()
185
	{
186
		$output = executeQueryArray("autoinstall.getLatestPackage");
187
		if(!$output->data)
188
		{
189
			return null;
190
		}
191
		return array_shift($output->data);
192
	}
193
194
	/**
195
	 * Get installed package informations
196
	 *
197
	 * @param array $package_list Package sequence list to get information
198
	 * @return array Returns array contains pacakge information. If no result returns empty array.
199
	 */
200
	function getInstalledPackages($package_list)
201
	{
202
		$args = new stdClass();
203
		$args->package_list = $package_list;
204
		$output = executeQueryArray("autoinstall.getInstalledPackages", $args);
205
		$result = array();
206
		if(!$output->data)
207
		{
208
			return $result;
209
		}
210
		foreach($output->data as $value)
211
		{
212
			$result[$value->package_srl] = $value;
213
		}
214
		return $result;
215
	}
216
217
	/**
218
	 * Get installed package list
219
	 *
220
	 * @param int $page
221
	 * @return Object
222
	 */
223
	function getInstalledPackageList($page)
224
	{
225
		$args = new stdClass();
226
		$args->page = $page;
227
		$args->list_count = 10;
228
		$args->page_count = 5;
229
		if(Context::getDBType() == 'mssql')
230
		{
231
			$args->sort_index = 'package_srl';
232
		}
233
		$output = executeQueryArray("autoinstall.getInstalledPackageList", $args);
234
		$res = array();
235
		if($output->data)
236
		{
237
			foreach($output->data as $val)
238
			{
239
				$res[$val->package_srl] = $val;
240
			}
241
		}
242
		$output->data = $res;
243
		return $output;
244
	}
245
246
	/**
247
	 * Get type using path
248
	 *
249
	 * @param string $path Path to get type
250
	 * @return string
251
	 */
252
	function getTypeFromPath($path)
253
	{
254
		if(!$path)
255
		{
256
			return NULL;
257
		}
258
259
		if($path == ".")
260
		{
261
			return "core";
262
		}
263
264
		$path_array = explode("/", $path);
265
		$target_name = array_pop($path_array);
266
		if(!$target_name)
267
		{
268
			$target_name = array_pop($path_array);
0 ignored issues
show
Unused Code introduced by
$target_name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
269
		}
270
		$type = substr(array_pop($path_array), 0, -1);
271
		return $type;
272
	}
273
274
	/**
275
	 * Get config file path by type
276
	 *
277
	 * @param string $type Type to get config file path
278
	 * @return string
279
	 */
280
	function getConfigFilePath($type)
281
	{
282
		$config_file = NULL;
283
		switch($type)
284
		{
285
			case "m.layout":
286
			case "module":
287
			case "addon":
288
			case "layout":
289
			case "widget":
290
			case 'theme': // for backward compatibility
291
				$config_file = "/conf/info.xml";
292
				break;
293
			case "component":
294
				$config_file = "/info.xml";
295
				break;
296
			case "m.skin":
297
			case "skin":
298
			case "widgetstyle":
299
			case "style":
300
				$config_file = "/skin.xml";
301
				break;
302
			case "drcomponent":
303
				$config_file = "/info.xml";
304
				break;
305
		}
306
		return $config_file;
307
	}
308
309
	/**
310
	 * Returns target is removable
311
	 *
312
	 * @param string $path Path
313
	 * @return bool
314
	 */
315
	function checkRemovable($path)
316
	{
317
		$path_array = explode("/", $path);
318
		$target_name = array_pop($path_array);
319
		$oModule = getModule($target_name, "class");
320
		if(!$oModule)
321
		{
322
			return FALSE;
323
		}
324
		if(method_exists($oModule, "moduleUninstall"))
325
		{
326
			return TRUE;
327
		}
328
		else
329
		{
330
			return FALSE;
331
		}
332
	}
333
334
	/**
335
	 * Get sequence of package by path
336
	 *
337
	 * @param string $path Path to get sequence
338
	 * @return int
339
	 */
340
	function getPackageSrlByPath($path)
341
	{
342
		if(!$path)
343
		{
344
			return;
345
		}
346
347 View Code Duplication
		if(substr($path, -1) == '/')
348
		{
349
			$path = substr($path, 0, strlen($path) - 1);
350
		}
351
352
		if(!$GLOBLAS['XE_AUTOINSTALL_PACKAGE_SRL_BY_PATH'][$path])
0 ignored issues
show
Bug introduced by
The variable $GLOBLAS does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
353
		{
354
			$args = new stdClass();
355
			$args->path = $path;
356
			$output = executeQuery('autoinstall.getPackageSrlByPath', $args);
357
358
			$GLOBLAS['XE_AUTOINSTALL_PACKAGE_SRL_BY_PATH'][$path] = $output->data->package_srl;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$GLOBLAS was never initialized. Although not strictly required by PHP, it is generally a good practice to add $GLOBLAS = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
359
		}
360
361
		return $GLOBLAS['XE_AUTOINSTALL_PACKAGE_SRL_BY_PATH'][$path];
362
	}
363
364
	/**
365
	 * Get remove url by package srl
366
	 *
367
	 * @param int $packageSrl Sequence of pakcage to get url
368
	 * @return string
369
	 */
370
	function getRemoveUrlByPackageSrl($packageSrl)
371
	{
372
		$ftp_info = Context::getFTPInfo();
373
		if(!$ftp_info->ftp_root_path)
374
		{
375
			return;
376
		}
377
378
		if(!$packageSrl)
379
		{
380
			return;
381
		}
382
383
		return getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAutoinstallAdminUninstall', 'package_srl', $packageSrl);
384
	}
385
386
	/**
387
	 * Get remove url by path
388
	 *
389
	 * @param string $path Path to get url
390
	 * @return string
391
	 */
392
	function getRemoveUrlByPath($path)
393
	{
394
		if(!$path)
395
		{
396
			return;
397
		}
398
399
		$ftp_info = Context::getFTPInfo();
400
		if(!$ftp_info->ftp_root_path)
401
		{
402
			return;
403
		}
404
405
		$packageSrl = $this->getPackageSrlByPath($path);
406
		if(!$packageSrl)
407
		{
408
			return;
409
		}
410
411
		return getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAutoinstallAdminUninstall', 'package_srl', $packageSrl);
412
	}
413
414
	/**
415
	 * Get update url by package srl
416
	 *
417
	 * @param int $packageSrl Sequence to get url
418
	 * @return string
419
	 */
420
	function getUpdateUrlByPackageSrl($packageSrl)
421
	{
422
		if(!$packageSrl)
423
		{
424
			return;
425
		}
426
427
		return getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAutoinstallAdminInstall', 'package_srl', $packageSrl);
428
	}
429
430
	/**
431
	 * Get update url by path
432
	 *
433
	 * @param string $path Path to get url
434
	 * @return string
435
	 */
436
	function getUpdateUrlByPath($path)
437
	{
438
		if(!$path)
439
		{
440
			return;
441
		}
442
443
		$packageSrl = $this->getPackageSrlByPath($path);
444
		if(!$packageSrl)
445
		{
446
			return;
447
		}
448
449
		return getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAutoinstallAdminInstall', 'package_srl', $packageSrl);
450
	}
451
452
	function getHaveInstance($columnList = array())
453
	{
454
		$output = executeQueryArray('autoinstall.getHaveInstance', NULL, $columnList);
455
		if(!$output->data)
456
		{
457
			return array();
458
		}
459
460
		return $output->data;
461
	}
462
463
}
464
/* End of file autoinstall.model.php */
465
/* Location: ./modules/autoinstall/autoinstall.model.php */
466