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 ( 278e53...818459 )
by gyeong-won
39:17 queued 30:14
created

syndicationController   B

Complexity

Total Complexity 36

Size/Duplication

Total Lines 229
Duplicated Lines 40.17 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 92
loc 229
rs 8.8
c 0
b 0
f 0
wmc 36
lcom 1
cbo 4

10 Methods

Rating   Name   Duplication   Size   Complexity  
A triggerInsertDocument() 18 18 4
A triggerUpdateDocument() 18 18 4
A triggerDeleteDocument() 0 20 4
A triggerDeleteModule() 19 19 4
B triggerMoveDocumentModule() 0 25 6
A triggerMoveDocumentToTrash() 18 18 3
A triggerRestoreTrash() 19 19 3
A insertLog() 0 9 1
A deleteLog() 0 7 1
B ping() 0 61 6

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
/**
5
 * @class  syndicationController
6
 * @author NAVER ([email protected])
7
 * @brief syndication module's Controller class
8
 **/
9
10
class syndicationController extends syndication
11
{
12
	var $ping_message = '';
13
14 View Code Duplication
	function triggerInsertDocument(&$obj) {
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...
15
		if($obj->module_srl < 1) return $this->makeObject();
16
17
		$oSyndicationModel = getModel('syndication');
18
		$oModuleModel = getModel('module');
19
20
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
21
22
		$config = $oModuleModel->getModuleConfig('syndication');
23
24
		if($config->syndication_use!='Y') return $this->makeObject();
25
26
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
27
		$id = $oSyndicationModel->getID('article', $target_id);
28
		$this->ping($id, 'article');
29
30
		return $this->makeObject();
31
	}
32
33 View Code Duplication
	function triggerUpdateDocument(&$obj) {
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...
34
		if($obj->module_srl < 1) return $this->makeObject();
35
36
		$oSyndicationModel = getModel('syndication');
37
		$oModuleModel = getModel('module');
38
39
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
40
41
		$config = $oModuleModel->getModuleConfig('syndication');
42
43
		if($config->syndication_use!='Y') return $this->makeObject();
44
45
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
46
		$id = $oSyndicationModel->getID('article', $target_id);
47
		$this->ping($id, 'article');
48
49
		return $this->makeObject();
50
	}
51
52
	function triggerDeleteDocument(&$obj) {
53
		if($obj->module_srl < 1) return $this->makeObject();
54
55
		$oSyndicationModel = getModel('syndication');
56
		$oModuleModel = getModel('module');
57
58
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
59
60
		$config = $oModuleModel->getModuleConfig('syndication');
61
62
		if($config->syndication_use!='Y') return $this->makeObject();
63
64
		$this->insertLog($obj->module_srl, $obj->document_srl, $obj->title, $obj->content);
65
66
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
67
		$id = $oSyndicationModel->getID('article', $target_id);
68
		$this->ping($id, 'deleted');
69
70
		return $this->makeObject();
71
	}
72
73
	// @deplicate
74 View Code Duplication
	function triggerDeleteModule(&$obj) {
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...
75
		$oSyndicationModel = getModel('syndication');
76
		$oModuleModel = getModel('module');
77
78
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
79
80
		$config = $oModuleModel->getModuleConfig('syndication');
81
82
		if($config->syndication_use!='Y') return $this->makeObject();
83
84
		$output = executeQuery('syndication.getExceptModule', $obj);
85
		if($output->data->count) return $this->makeObject();
86
		
87
88
		$id = $oSyndicationModel->getID('site', $obj->module_srl);
89
		$this->ping($id, 'deleted');
90
91
		return $this->makeObject();
92
	}
93
94
	function triggerMoveDocumentModule(&$obj)
95
	{
96
		if($obj->module_srl < 1) return $this->makeObject();
97
98
		$oSyndicationModel = getModel('syndication');
99
		$oModuleModel = getModel('module');
100
101
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
102
103
		$config = $oModuleModel->getModuleConfig('syndication');
104
105
		if($config->syndication_use!='Y') return $this->makeObject();
106
107
		$arr_document_srl = explode(',', $obj->document_srls);
108
		if(!$arr_document_srl) return $this->makeObject();
0 ignored issues
show
Bug Best Practice introduced by
The expression $arr_document_srl of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
109
110
		foreach($arr_document_srl as $document_srl)
111
		{
112
			$target_id = sprintf('%s-%s', $obj->module_srl, $document_srl);
113
			$id = $oSyndicationModel->getID('article', $target_id);
114
			$this->ping($id, 'article');
115
		}
116
117
		return $this->makeObject();
118
	}
119
120 View Code Duplication
	function triggerMoveDocumentToTrash(&$obj) {
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...
121
		$oSyndicationModel = getModel('syndication');
122
		$oModuleModel = getModel('module');
123
124
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
125
126
		$config = $oModuleModel->getModuleConfig('syndication');
127
128
		if($config->syndication_use!='Y') return $this->makeObject();
129
130
		$this->insertLog($obj->module_srl, $obj->document_srl, '', '');
131
132
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
133
		$id = $oSyndicationModel->getID('article', $target_id);
134
		$this->ping($id, 'deleted');
135
136
		return $this->makeObject();
137
	}
138
139 View Code Duplication
	function triggerRestoreTrash(&$obj) {
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...
140
		$oSyndicationModel = getModel('syndication');
141
		$oModuleModel = getModel('module');
142
143
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
144
145
		$config = $oModuleModel->getModuleConfig('syndication');
146
147
		if($config->syndication_use!='Y') return $this->makeObject();
148
149
		// 신디케이션 삭제 로그 제거
150
		$this->deleteLog($obj->module_srl, $obj->document_srl);
151
152
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
153
		$id = $oSyndicationModel->getID('article', $target_id);
154
		$this->ping($id, 'article');
155
156
		return $this->makeObject();
157
	}
158
159
	function insertLog($module_srl, $document_srl, $title = null, $summary = null)
160
	{
161
		$args = new stdClass;
162
		$args->module_srl = $module_srl;
163
		$args->document_srl = $document_srl;
164
		$args->title = $title;
165
		$args->summary = $summary;
166
		$output = executeQuery('syndication.insertLog', $args);
0 ignored issues
show
Unused Code introduced by
$output 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...
167
	}
168
169
	function deleteLog($module_srl, $document_srl)
170
	{
171
		$args = new stdClass;
172
		$args->module_srl = $module_srl;
173
		$args->document_srl = $document_srl;
174
		$output = executeQuery('syndication.deleteLog', $args);
0 ignored issues
show
Unused Code introduced by
$output 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...
175
	}
176
177
	function ping($id, $type, $page=1) {
178
		$this->ping_message = '';
179
debugPrint($id);
180
		$oSyndicationModel = getModel('syndication');
181
182
		$oModuleModel = getModel('module');
183
		$config = $oModuleModel->getModuleConfig('syndication');
184
185
		if(!$config->syndication_token)
186
		{
187
			$this->ping_message = 'Syndication Token empty';
188
			$oSyndicationModel->setResentPingLog($this->ping_message);
189
			return false;
190
		}
191
192
		if(!$this->checkOpenSSLSupport())
193
		{
194
			$lang = Context::get('lang');
195
			$this->ping_message = $lang->msg_need_openssl_support;
196
			$oSyndicationModel->setResentPingLog($this->ping_message);
197
			return false;
198
		}
199
200
		if(substr($config->site_url,-1)!='/')
201
		{
202
			$config->site_url .= '/';
203
		}
204
205
		$ping_url = 'https://apis.naver.com/crawl/nsyndi/v2';
206
		$ping_header = array();
207
		$ping_header['Host'] = 'apis.naver.com';
208
		$ping_header['Pragma'] = 'no-cache';
209
		$ping_header['Accept'] = '*/*';
210
		$ping_header['Authorization'] = sprintf("Bearer %s", $config->syndication_token);
211
212
		$request_config = array();
213
		$request_config['ssl_verify_peer'] = false;
214
215
		$ping_body = getNotEncodedFullUrl('', 'module', 'syndication', 'act', 'getSyndicationList', 'id', $id, 'type', $type, 'page', $page, 'syndication_password', $config->syndication_password);
216
217
		$buff = FileHandler::getRemoteResource($ping_url, null, 10, 'POST', 'application/x-www-form-urlencoded', $ping_header, array(), array('ping_url'=>$ping_body), $request_config);
218
219
		$xml = new XmlParser();
220
		$xmlDoc= $xml->parse($buff);
221
222
		if($xmlDoc->result->error_code->body != '000')
223
		{
224
			if(!$buff)
225
			{
226
				$this->ping_message = 'Socket connection error. Check your Server Environment.';
227
			}
228
			else
229
			{
230
				$this->ping_message = $xmlDoc->result->message->body;
231
			}
232
233
			$oSyndicationModel->setResentPingLog($this->ping_message);
234
			return false;
235
		}
236
		return true;
237
	}
238
}
239