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

syndicationModel::getArticles()   F

Complexity

Conditions 12
Paths 320

Size

Total Lines 42
Code Lines 33

Duplication

Lines 6
Ratio 14.29 %

Importance

Changes 0
Metric Value
cc 12
eloc 33
nc 320
nop 6
dl 6
loc 42
rs 3.7956
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * @class  getSyndicationList
6
 * @author NAVER ([email protected])
7
 * @brief syndication model class of the module
8
 **/
9
10
class syndicationModel extends syndication
11
{
12
	private $site_url = null;
13
	private $uri_scheme = 'http://';
14
	private $syndication_password= null;
15
	private $year = null;
16
	private $langs = array();
17
	private $granted_modules = array();
18
	static private $modules = array();
19
20
	function init() {
21
		$oModuleModel = getModel('module');
22
		$config = $oModuleModel->getModuleConfig('syndication');
23
		if(Context::getSslStatus() == 'always') $this->uri_scheme = 'https://';
24
25
		$this->site_url = preg_replace('/\/+$/is', '', $config->site_url);
26
		$this->syndication_password = $config->syndication_password;
27
		$this->year = $config->year;
28
29
		$output = executeQueryArray('syndication.getGrantedModules');
30
		if($output->data) {
31
			foreach($output->data as $key => $val) {
32
				$this->granted_modules[] = $val->module_srl;
33
			}
34
		}
35
36
		$this->gzhandler_enable = FALSE;
37
	}
38
39
	function isExceptedModules($module_srl) {
40
		$args = new stdClass;
41
		$args->module_srl = $module_srl;
42
43
		$output = executeQuery('syndication.getExceptModule', $args);
44
		if($output->data->count) return TRUE;
45
46
		$output = executeQuery('syndication.getGrantedModule', $args);
47
		if($output->data->count) return TRUE;
48
49
		return FALSE;
50
	}
51
52
	function getExceptModuleSrls()
53
	{
54
		$output = executeQueryArray('syndication.getExceptModuleSrls');
55
		$module_srls = array();
56
		if (is_array($output->data))
57
		{
58
			foreach($output->data as $val)
59
			{
60
				$module_srls[] = $val->module_srl;
61
			}
62
		}
63
		return $module_srls;
64
	}
65
66
	function getLang($key, $site_srl)
67
	{
68
		if(!$this->langs[$site_srl])
69
		{
70
			$this->langs[$site_srl] = array();
71
			$args = new stdClass;
72
			$args->site_srl = $site_srl;
73
			$args->lang_code = Context::getLangType();
74
			$output = executeQueryArray("syndication.getLang", $args);
75
			if(!$output->toBool() || !$output->data) return $key;
76
77
			foreach($output->data as $value)
78
			{
79
				$this->langs[$site_srl][$value->name] = $value->value;
80
			}
81
		}
82
		if($this->langs[$site_srl][$key])
83
		{
84
			return $this->langs[$site_srl][$key];
85
		}
86
		else return $key;
87
	}
88
89
	function handleLang($title, $site_srl)
90
	{
91
		$matches = NULL;
92
		if(!preg_match("/\\\$user_lang->(.+)/", $title, $matches))
93
		{
94
			return $title;
95
		}
96
		else
97
		{
98
			return $this->getLang($matches[1], $site_srl);
99
		}
100
	}
101
102
	function getSyndicationList() {
103
		$oModuleModel = getModel('module');
104
		$config = $oModuleModel->getModuleConfig('syndication');
105
		if(!$config->year || !$config->site_url || !$config->syndication_token) 
106
		{
107
			return $this->makeObject(-1,'msg_check_syndication_config');
108
		}
109
110
		$id = Context::get('id');
111
		$type = Context::get('type');
112
113
		$startTime = Context::get('start-time');
114
		$endTime = Context::get('end-time');
115
116
		$page = Context::get('page');
117
		if(!$page)
118
		{
119
			$page = 1;
120
		}
121
		$vars = Context::getRequestVars();
0 ignored issues
show
Unused Code introduced by
$vars 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...
122
		if(!$id || !$type)
123
		{
124
			return $this->makeObject(-1,'msg_invalid_request');
125
		}
126
127
		if(!preg_match('/^tag:([^,]+),([0-9]+):(site|channel|article)(.*)$/i',$id,$matches)) 
128
		{
129
			return $this->makeObject(-1,'msg_invalid_request');
130
		}
131
132
		if($config->syndication_password != Context::get('syndication_password'))
133
		{
134
			return $this->makeObject(-1,'msg_invalid_request');
135
		}
136
137
		$url = $matches[1];
138
		$year = $matches[2];
139
		$target = $matches[3];
140
		$id = $matches[4];
141
		if($id && $id{0}==':')
142
		{
143
			$id = substr($id, 1);
144
		}
145
146
		$module_srl = null;
147
		$document_srl = null;
148
		if($id && strpos($id,'-')!==false) 
149
		{
150
			list($module_srl, $document_srl) = explode('-', $id);
151
		}
152
		elseif($id) 
153
		{
154
			$module_srl = $id;
155
		}
156
157
		if(!$url || !$year || !$target)
158
		{
159
			return $this->makeObject(-1,'msg_invalid_request');
160
		}
161
162
		$time_zone = substr($GLOBALS['_time_zone'], 0, 3).':'.substr($GLOBALS['_time_zone'], 3);
163
		Context::set('time_zone', $time_zone);
164
165
		$site_module_info = Context::get('site_module_info');
166
167
		if($target == 'channel' && !$module_srl)
168
		{
169
			$target = 'site';
170
		}
171
172
		if($module_srl)
173
		{
174
			$args = new stdClass;
175
			$args->module_srls = $module_srl;
176
			$output = executeQuery('syndication.getModules', $args);
177
			$module_info = $output->data;
178
			self::$modules[$module_srl] = $output->data;
179
		}
180
181
		if($target == 'channel' && $module_srl)
182
		{
183
			if($module_info) 
0 ignored issues
show
Bug introduced by
The variable $module_info does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
184
			{
185
				$args->module_srl = $module_srl;
0 ignored issues
show
Bug introduced by
The variable $args does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
186
				$output = executeQuery('syndication.getExceptModules', $args);
187
				if($output->data->count) 
188
				{
189
					$error = 'target is not founded';
190
				}
191
			} 
192
			else 
193
			{
194
				$error = 'target is not founded';
195
			}
196
197
			unset($args);
198
		}
199
200
		if(!$error) 
201
		{
202
			Context::set('target', $target);
203
			Context::set('type', $type);
204
205
			$oMemberModel = getModel('member');
206
			$member_config = $oMemberModel->getMemberConfig();
207
208
			$oModuleModel = getModel('module');
209
			$site_config = $oModuleModel->getModuleConfig('module');
210
211
			switch($target) 
212
			{
213
				case 'site' :
214
						$site_info = new stdClass;
215
						$site_info->id = $this->getID('site');
216
						$site_info->site_url = getFullSiteUrl($this->uri_scheme . $this->site_url, '');
217
						$site_info->site_title = $this->handleLang($site_module_info->browser_title, $site_module_info->site_srl);
218
						$site_info->title = $site_info->site_title;
219
220
						if($module_srl)
221
						{
222
							$args->module_srl = $module_srl;
223
							$site_info->title = $this->handleLang($module_info->browser_title, $module_info->site_srl);
224
							if(!$site_info->title)
225
							{
226
								$site_info->title = $site_info->site_title;
227
							}
228
						}
229
						else
230
						{
231
							$except_module_output = executeQueryArray('syndication.getExceptModuleSrls');
232
							if(is_array($except_module_output->data))
233
							{
234
								$except_module_srls = array();
235
								foreach($except_module_output->data as $val)
236
								{
237
									$except_module_srls[] = $val->module_srl;
238
								}
239
								$args->except_modules = implode(',', $except_module_srls);
240
							}
241
						}
242
243
						$output = executeQuery('syndication.getSiteUpdatedTime', $args);
244
245 View Code Duplication
						if($output->data)
246
						{
247
							$site_info->updated = date("Y-m-d\\TH:i:s", ztime($output->data->last_update)).$time_zone;
248
						}
249
250
						$site_info->self_href = $this->getSelfHref($site_info->id,$type);
251
						Context::set('site_info', $site_info);
252
253
						$this->setTemplateFile('site');
254
						switch($type) {
255
							case 'article' :
256
								// 문서 전체를 신디케이션에 추가
257
								Context::set('articles', $this->getArticles($module_srl, $page, $startTime, $endTime, 'article',$site_info->id));
258
								$next_url = Context::get('articles')->next_url;
259
								
260
								break;
261
							case 'deleted' :
262
								// 문서 전체를 신디케이션에서 삭제
263
								Context::set('deleted', $this->getArticles($module_srl, $page, $startTime, $endTime, 'deleted',$site_info->id));
264
								$next_url = Context::get('deleted')->next_url;
265
								break;
266
							default :
267
								$this->setTemplateFile('site.info');
268
								break;
269
						}
270
271
						// 다음 페이지가 있다면 다시 신디케이션 호출
272
						if($next_url)
0 ignored issues
show
Bug introduced by
The variable $next_url does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
273
						{
274
							$oSyndicationController = getController('syndication');
275
							$oSyndicationController->ping(Context::get('id'), Context::get('type'), ++$page);
276
						}
277
					break;
278
				case 'channel' :
279
						$channel_info = new stdClass;
280
						$channel_info->id = $this->getID('channel', $module_info->module_srl);
281
						$channel_info->site_title = $this->handleLang($site_module_info->browser_title, $site_module_info->site_srl);
282
						$channel_info->title = $this->handleLang($module_info->browser_title, $module_info->site_srl);
283
						$channel_info->updated = date("Y-m-d\\TH:i:s").$time_zone;
284
						$channel_info->self_href = $this->getSelfHref($channel_info->id, $type);
285
						$channel_info->site_url = getFullSiteUrl($this->uri_scheme . $this->site_url, '');
286
						$channel_info->alternative_href = $this->getChannelAlternativeHref($module_info->module_srl);
287
						$channel_info->summary = $module_info->description;
288 View Code Duplication
						if($module_info->module == "textyle")
289
						{
290
							$channel_info->type = "blog";
291
							$channel_info->rss_href = getFullSiteUrl($module_info->domain, '', 'mid', $module_info->mid, 'act', 'rss');
292
						}
293
						else
294
						{
295
							$channel_info->type = "web";
296
						}
297
						$except_module_srls = $this->getExceptModuleSrls();
298
						if($except_module_srls)
0 ignored issues
show
Bug Best Practice introduced by
The expression $except_module_srls 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...
299
						{
300
							$args->except_modules = implode(',',$except_module_srls);
301
						}
302
303
						$output = executeQuery('syndication.getSiteUpdatedTime', $args);
304 View Code Duplication
						if($output->data) $channel_info->updated = date("Y-m-d\\TH:i:s", ztime($output->data->last_update)).$time_zone;
305
						Context::set('channel_info', $channel_info);
306
307
						$this->setTemplateFile('channel');
308
						switch($type) {
309
							case 'article' :
310
									Context::set('articles', $this->getArticles($module_srl, $page, $startTime, $endTime, 'article', $channel_info->id));
311
								break;
312
							case 'deleted' :
313
									Context::set('deleted', $this->getDeleted($module_srl, $page, $startTime, $endTime, 'deleted', $channel_info->id));
314
								break;
315
							default :
316
									$this->setTemplateFile('channel.info');
317
								break;
318
						}
319
					break;
320
321
					case 'article':
322
						$channel_info = new stdClass;
323
						$channel_info->id = $this->getID('channel', $module_info->module_srl);
324
						$channel_info->title = $this->handleLang($module_info->browser_title, $module_info->site_srl);
325
						$channel_info->site_title = $site_config->siteTitle;
326
						if(!$channel_info->site_title) {
327
							$channel_info->site_title = $channel_info->title;
328
						}
329
						$channel_info->updated = date("Y-m-d\\TH:i:s").$time_zone;
330
						$channel_info->self_href = $this->getSelfHref($channel_info->id, $type);
331
						$channel_info->site_url = getFullSiteUrl($this->uri_scheme . $this->site_url, '');
332
						$channel_info->alternative_href = $this->getChannelAlternativeHref($module_info->module_srl);
333
						$channel_info->webmaster_name = $member_config->webmaster_name;
334
						$channel_info->webmaster_email = $member_config->webmaster_email;
335
336
						$except_module_srls = $this->getExceptModuleSrls();
337
						if($except_module_srls)
0 ignored issues
show
Bug Best Practice introduced by
The expression $except_module_srls 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...
338
						{
339
							$args->except_modules = implode(',',$except_module_srls);
340
						}
341
342
						$output = executeQuery('syndication.getSiteUpdatedTime', $args);
343 View Code Duplication
						if($output->data) $channel_info->updated = date("Y-m-d\\TH:i:s", ztime($output->data->last_update)).$time_zone;
344
						Context::set('channel_info', $channel_info);
345
						Context::set('member_config', $member_config);
346
347
						$this->setTemplateFile('channel');
348
						switch($type) {
349
							case "article" :
350
								$articles = new stdClass; 
351
								$articles->list = array($this->getArticle($document_srl));
352
								Context::set('articles', $articles);
353
							break;
354
355
							case "deleted" :
356
								$deleted = new stdClass; 
357
								$deleted->list = $this->getDeletedByDocumentSrl($document_srl);
358
								Context::set('deleted', $deleted);
359
							break;
360
						}
361
					break;
362
			}
363
		} else {
364
			Context::set('message', $error);
0 ignored issues
show
Bug introduced by
The variable $error does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
365
			$this->setTemplateFile('error');
366
		}
367
368
		$this->setTemplatePath($this->module_path.'tpl');
369
		Context::setResponseMethod('XMLRPC');
370
	}
371
372
	// @DEPRECATED
373
	function getChannels() {
374
		if($module_srls) $args->module_srls = $module_srls;
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...
Bug introduced by
The variable $module_srls 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...
375
		if(count($this->granted_modules)) $args->except_module_srls = implode(',',$this->granted_modules);
376
		$output = executeQueryArray('syndication.getModules', $args);
377
378
		$time_zone = substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3);
379
		Context::set('time_zone', $time_zone);
380
381
		if($output->data) {
382
			foreach($output->data as $module_info) {
383
				unset($obj);
384
				$obj = new stdClass;
385
				$obj->id = $this->getID('channel', $module_info->module_srl);
386
				$obj->title = $this->handleLang($module_info->browser_title, $module_info->site_srl);
387
				$obj->updated = date("Y-m-d\\TH:i:s").$time_zone;
388
				$obj->self_href = $this->getSelfHref($obj->id, 'channel');
389
				$obj->alternative_href = $this->getChannelAlternativeHref($module_info);
390
				$obj->summary = $module_info->description;
391 View Code Duplication
				if($module_info->module == "textyle")
392
				{
393
					$obj->type = "blog";
394
					$obj->rss_href = getFullSiteUrl($module_info->domain, '', 'mid', $module_info->mid, 'act', 'rss');
395
				}
396
				else
397
				{
398
					$obj->type = "web";
399
				}
400
401
				$list[] = $obj;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $list = 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...
402
			}
403
		}
404
		return $list;
0 ignored issues
show
Bug introduced by
The variable $list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
405
	}
406
407
	function getArticle($document_srl) {
408
		if($this->site_url==null) $this->init();
409
410
		$oDocumentModel = getModel('document');
411
		$oDocument = $oDocumentModel->getDocument($document_srl,false,false);
412
		if(!$oDocument->isExists()) return;
413
414
		$val = $oDocument->getObjectVars();
415
416
		$time_zone = substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3);
417
		Context::set('time_zone', $time_zone);
418
419
		$mdoule_info = self::$modules[$oDocument->get('module_srl')];
0 ignored issues
show
Unused Code introduced by
$mdoule_info 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...
420
421
		$article = new stdClass();
422
		$article->id = $this->getID('article', $oDocument->get('module_srl').'-'.$oDocument->get('document_srl'));
423
		$article->updated = date("Y-m-d\\TH:i:s", ztime($oDocument->get('last_update'))).$time_zone;
424
		$article->published = date("Y-m-d\\TH:i:s", ztime($oDocument->get('regdate'))).$time_zone;
425
		$article->alternative_href = $this->getAlternativeHref($oDocument->get('document_srl'), $oDocument->get('module_srl'));
426
		$article->channel_alternative_href = $this->getChannelAlternativeHref($oDocument->get('module_srl'));
427
		$article->nick_name = (!$oDocument->get('nick_name')) ? $oDocument->get('user_name') : $oDocument->get('nick_name');
428
		$article->title = $oDocument->getTitle();
429
		$article->content = $oDocument->get('content');
430
		if($val->category_srl) {
431
			$category = $oDocumentModel->getCategory($val->category_srl);
432
			$category_title = $category->title;
433
			$article->category = new stdClass();
434
			$article->category->term = $val->category_srl;
435
			$article->category->label = $category_title;
436
		}
437
438
		return $article;
439
	}
440
441
	function getArticles($module_srl = null, $page=1, $startTime = null, $endTime = null, $type = null, $id = null) {
442
		if($this->site_url==null) $this->init();
443
444
		$args = new stdClass;
445
		if($module_srl) $args->module_srl = $module_srl;
446
		if($startTime) $args->start_date = $this->getDate($startTime);
447
		if($endTime) $args->end_date = $this->getDate($endTime);
448
		if(count($this->granted_modules)) $args->except_module_srls = implode(',',$this->granted_modules);
449
		$args->page = $page;
450
		$output = executeQueryArray('syndication.getDocumentList', $args);
451
		$cur_page = $output->page_navigation->cur_page;
452
		$total_page = $output->page_navigation->last_page;
453
454
		$result = new stdClass;
455
		$result->next_url = null;
456
		$result->list = array();
457
458
		$time_zone = substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3);
459
		Context::set('time_zone', $time_zone);
460
461 View Code Duplication
		if($cur_page<$total_page) {
462
			$next_url = $this->getSelfHref($id, $type);
463
			if($startTime) $next_url .= '&startTime='.$startTime;
464
			if($endTime) $next_url .= '&endTime='.$endTime;
465
			$result->next_url = $next_url.'&page='.($cur_page+1);
466
		}
467
468
		if($output->data) {
469
			foreach($output->data as $key => $val) {
470
				$article = new stdClass();
471
				$article->id = $this->getID('article', $val->module_srl.'-'.$val->document_srl);
472
				$article->updated = date("Y-m-d\\TH:i:s", ztime($val->last_update)).$time_zone;
473
				$article->published = date("Y-m-d\\TH:i:s", ztime($val->regdate)).$time_zone;
474
				$article->alternative_href = getFullSiteUrl($this->uri_scheme . $this->site_url, '', 'document_srl', $val->document_srl);
475
				$article->channel_alternative_href = $this->getChannelAlternativeHref($val->module_srl);
476
				$article->nick_name = (!$val->nick_name) ? $val->user_name : $val->nick_name;
477
				$article->content = $val->content;
478
				$result->list[] = $article;
479
			}
480
		}
481
		return $result;
482
	}
483
484
	function getDeleted($module_srl = null, $page = 1, $startTime = null, $endTime = null, $type = null, $id = null) {
485
		if($this->site_url==null) $this->init();
486
487
		$args = new stdClass;
488
		if($module_srl) $args->module_srl= $module_srl;
489
		if($startTime) $args->start_date = $this->getDate($startTime);
490
		if($endTime) $args->end_date = $this->getDate($endTime);
491
		$args->page = $page;
492
493
		$output = executeQueryArray('syndication.getDeletedList', $args);
494
495
		$cur_page = $output->page_navigation->cur_page;
496
		$total_page = $output->page_navigation->last_page;
497
498
		$result = new stdClass;
499
		$result->next_url = null;
500
		$result->list = array();
501
502
		$time_zone = substr($GLOBALS['_time_zone'],0,3).':'.substr($GLOBALS['_time_zone'],3);
503
		Context::set('time_zone', $time_zone);
504
505 View Code Duplication
		if($cur_page<$total_page) {
506
			$next_url = $this->getSelfHref($id, $type);
507
			if($startTime) $next_url .= '&startTime='.$startTime;
508
			if($endTime) $next_url .= '&endTime='.$endTime;
509
			$result->next_url = $next_url . '&page='.($cur_page+1);
510
		}
511
512
		if($output->data) {
513 View Code Duplication
			foreach($output->data as $key => $val) {
514
				$val->id = $this->getID('article', $val->module_srl.'-'.$val->document_srl);
515
				$val->deleted = date("Y-m-d\\TH:i:s", ztime($val->regdate)).$time_zone;
516
				$val->alternative_href = getFullSiteUrl($this->uri_scheme . $this->site_url, '', 'document_srl', $val->document_srl);
517
				$val->channel_id = $this->getID('channel', $val->module_srl.'-'.$val->document_srl);
518
				$output->data[$key] = $val;
519
			}
520
			$result->list = $output->data;
521
		}
522
		return $result;
523
	}
524
525
	function getDeletedByDocumentSrl($document_srl)
526
	{
527
		$args = new stdClass;
528
		$args->document_srl = $document_srl;
529
		$output = executeQueryArray('syndication.getDeletedList', $args);
530 View Code Duplication
		foreach($output->data as $key => $val) {
531
			$val->id = $this->getID('article', $val->module_srl.'-'.$val->document_srl);
532
			$val->deleted = date("Y-m-d\\TH:i:s", ztime($val->regdate)).$time_zone;
0 ignored issues
show
Bug introduced by
The variable $time_zone 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...
533
			$val->alternative_href = getFullSiteUrl($this->uri_scheme . $this->site_url, '', 'document_srl', $val->document_srl);
534
			$val->channel_id = $this->getID('channel', $val->module_srl.'-'.$val->document_srl);
535
			$output->data[$key] = $val;
536
		}
537
538
		return $output->data;
539
	}
540
541
	function getID($type, $target_id = null) {
542
		if($this->site_url==null) $this->init();
543
544
		return sprintf('tag:%s,%d:%s', $this->site_url, $this->year, $type) . ($target_id?':'.$target_id:'');
545
	}
546
547
	function getChannelAlternativeHref($module_srl) {
548
		static $module_info = array();
549
		if(!isset($module_info[$module_srl])) {
550
			$args = new stdClass;
551
			$args->module_srl = $module_srl;
552
			$output = executeQuery('syndication.getModuleSiteInfo', $args);
553
			if($output->data) $module_info[$module_srl] = $output->data;
554
			else $module_info[$module_srl] = null;
555
		}
556
557
		if(is_null($module_info[$module_srl])) return $this->site_url;
558
559
		$domain = $module_info[$module_srl]->domain;
560
		$url = getFullSiteUrl($domain, '', 'mid', $module_info[$module_srl]->mid);
561 View Code Duplication
		if(substr($url,0,1)=='/') $domain = $this->uri_scheme . $this->site_url . $url;
0 ignored issues
show
Unused Code introduced by
$domain 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...
562
		return $url;
563
	}
564
565
	function getSelfHref($id, $type = null) {
566
		if($this->site_url==null) $this->init();
567
568
		return  sprintf('%s/?module=syndication&act=getSyndicationList&id=%s&type=%s&syndication_password=%s', $this->uri_scheme . $this->site_url, $id, $type, $this->syndication_password);
569
	}
570
571
	/**
572
	 * 문서의 고유 URL 반환
573
	 */
574
	function getAlternativeHref($document_srl, $module_srl) {
575
		if($this->site_url==null) $this->init();
576
577
		if(!self::$modules[$module_srl]) {
578
			$args = new stdClass;
579
			$args->module_srls = $module_srl;
580
			$output = executeQuery('syndication.getModules', $args);
581
			$module_info = $output->data;
582
			self::$modules[$module_srl] = $module_info;
583
		} else {
584
			$module_info = self::$modules[$module_srl];
585
		}
586
587
		$domain = $module_info->domain;
588
		$url = getFullSiteUrl($domain, '', 'mid', $module_info->mid, 'document_srl', $document_srl);
589 View Code Duplication
		if(substr($url,0,1)=='/') $domain = $this->uri_scheme . $this->site_url.$url;
0 ignored issues
show
Unused Code introduced by
$domain 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...
590
		return $url;
591
	}
592
593
	function getDate($date) {
594
		$time = strtotime($date);
595
		if($time == -1) $time = ztime(str_replace(array('-','T',':'),'',$date));
596
		return date('YmdHis', $time);
597
	}
598
599
	function getResentPingLogPath()
600
	{
601
		$target_filename = _XE_PATH_.'files/cache/tmp/syndication_ping_log';
602
		if(!file_exists($target_filename))
603
		{
604
			FileHandler::writeFile($target_filename, '');
605
		}
606
		return $target_filename;
607
	}
608
609
	function setResentPingLog($msg)
610
	{
611
		$file_path = $this->getResentPingLogPath();
612
613
		$args = new stdClass;
614
		$args->regdate = date('YmdHis');
615
		$args->message = urlencode($msg);
616
617
		$list = $this->getResentPingLog();
618
		if(count($list)>=10)
619
		{
620
			array_pop($list);
621
		}
622
		array_unshift($list, $args);
623
		FileHandler::writeFile($file_path, serialize($list));
624
625
		return true;
626
	}
627
628
	function getResentPingLog()
629
	{
630
		$file_path = $this->getResentPingLogPath();
631
		$str = FileHandler::readFile($file_path);
632
		$list = array();
633
		if($str)
634
		{
635
			$list = unserialize($str);
636
		}
637
638
		return $list;
639
	}
640
}
641