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 ( 423fe8...f48289 )
by gyeong-won
15:56 queued 08:14
created

layout   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 129
Duplicated Lines 17.83 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 23
loc 129
rs 10
c 0
b 0
f 0
wmc 26
lcom 0
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A moduleInstall() 0 7 1
C checkUpdate() 9 38 11
C moduleUpdate() 14 53 12
A recompileCache() 0 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  layout
5
 * @author NAVER ([email protected])
6
 * high class of the layout module
7
 */
8
class layout extends ModuleObject
9
{
10
	/**
11
	 * Implement if additional tasks are necessary when installing
12
	 * @return Object
13
	 */
14
	function moduleInstall()
15
	{
16
		// Create a directory to be used in the layout
17
		FileHandler::makeDir('./files/cache/layout');
18
19
		return new Object();
20
	}
21
22
	/**
23
	 * a method to check if successfully installed
24
	 * @return boolean
25
	 */
26
	function checkUpdate()
27
	{
28
		$oDB = &DB::getInstance();
29
		$oModuleModel = getModel('module');
30
		$oModuleController = getController('module');
31
		$version_update_id = implode('.', array(__CLASS__, __XE_VERSION__, 'updated'));
32
		if($oModuleModel->needUpdate($version_update_id))
33
		{
34
			// 2009. 02. 11 Add site_srl to layout table
35
			if(!$oDB->isColumnExists('layouts', 'site_srl')) return true;
36
			// 2009. 02. 26 Move the previous layout for faceoff
37
			$files = FileHandler::readDir('./files/cache/layout');
38
			for($i=0,$c=count($files);$i<$c;$i++)
39
			{
40
				$filename = $files[$i];
41
				if(preg_match('/([0-9]+)\.html/i',$filename)) return true;
42
			}
43
44
			if(!$oDB->isColumnExists('layouts', 'layout_type')) return true;
45
46
			$args = new stdClass();
47
			$args->layout = '.';
48
			$output = executeQueryArray('layout.getLayoutDotList', $args);
49 View Code Duplication
			if($output->data && count($output->data) > 0)
50
			{
51
				foreach($output->data as $layout)
52
				{
53
					$layout_path = explode('.', $layout->layout);
54
					if(count($layout_path) != 2) continue;
55
					if(is_dir(sprintf(_XE_PATH_ . 'themes/%s/layouts/%s', $layout_path[0], $layout_path[1]))) return true;
56
				}
57
			}
58
59
			$oModuleController->insertUpdatedLog($version_update_id);
60
		}
61
62
		return false;
63
	}
64
65
	/**
66
	 * Execute update
67
	 * @return Object
68
	 */
69
	function moduleUpdate()
70
	{
71
		$oDB = &DB::getInstance();
72
		$oModuleModel = getModel('module');
0 ignored issues
show
Unused Code introduced by
$oModuleModel 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...
73
		$oModuleController = getController('module');
74
		$version_update_id = implode('.', array(__CLASS__, __XE_VERSION__, 'updated'));
75
		{
76
			// 2009. 02. 11 Add site_srl to menu table
77
			if(!$oDB->isColumnExists('layouts', 'site_srl'))
78
			{
79
				$oDB->addColumn('layouts','site_srl','number',11,0,true);
80
			}
81
			// 2009. 02. 26 Move the previous layout for faceoff
82
			$oLayoutModel = getModel('layout');
83
			$files = FileHandler::readDir('./files/cache/layout');
84
			for($i=0,$c=count($files);$i<$c;$i++)
85
			{
86
				$filename = $files[$i];
87
				if(!preg_match('/([0-9]+)\.html/i',$filename,$match)) continue;
88
				$layout_srl = $match[1];
89
				if(!$layout_srl) continue;
90
				$path = $oLayoutModel->getUserLayoutPath($layout_srl);
91
				if(!is_dir($path)) FileHandler::makeDir($path);
92
				FileHandler::copyFile('./files/cache/layout/'.$filename, $path.'layout.html');
93
				@unlink('./files/cache/layout/'.$filename);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
94
			}
95
96
			if(!$oDB->isColumnExists('layouts', 'layout_type'))
97
			{
98
				$oDB->addColumn('layouts','layout_type','char',1,'P',true);
99
			}
100
101
			$args->layout = '.';
0 ignored issues
show
Bug introduced by
The variable $args 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...
102
			$output = executeQueryArray('layout.getLayoutDotList', $args);
103 View Code Duplication
			if($output->data && count($output->data) > 0)
104
			{
105
				foreach($output->data as $layout)
106
				{
107
					$layout_path = explode('.', $layout->layout);
108
					if(count($layout_path) != 2) continue;
109
					if(is_dir(sprintf(_XE_PATH_ . 'themes/%s/layouts/%s', $layout_path[0], $layout_path[1])))
110
					{
111
						$args->layout = implode('|@|', $layout_path);
112
						$args->layout_srl = $layout->layout_srl;
113
						$output = executeQuery('layout.updateLayout', $args);
114
					}
115
				}
116
			}
117
118
			$oModuleController->insertUpdatedLog($version_update_id);
119
		}
120
		return new Object(0, 'success_updated');
121
	}
122
123
	/**
124
	 * Re-generate the cache file
125
	 * @return void
126
	 */
127
	function recompileCache()
128
	{
129
		$path = './files/cache/layout';
130
		if(!is_dir($path))
131
		{
132
			FileHandler::makeDir($path);
133
			return;
134
		}
135
	}
136
}
137
/* End of file layout.class.php */
138
/* Location: ./modules/layout/layout.class.php */
139