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 — develop ( baac3d...439f66 )
by gyeong-won
17:54
created

editorAdminView::dispEditorAdminIndex()   F

Complexity

Conditions 14
Paths 4608

Size

Total Lines 113
Code Lines 81

Duplication

Lines 7
Ratio 6.19 %

Importance

Changes 0
Metric Value
cc 14
eloc 81
nc 4608
nop 0
dl 7
loc 113
rs 2
c 0
b 0
f 0

How to fix   Long Method    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
 * @class  editorAdminView
5
 * @author NAVER ([email protected])
6
 * @brief editor admin view of the module class
7
 */
8
class editorAdminView extends editor
9
{
10
	/**
11
	 * @brief Initialization
12
	 */
13
	function init()
14
	{
15
	}
16
17
	/**
18
	 * @brief Administrator Setting page
19
	 * Settings to enable/disable editor component and other features
20
	 */
21
	function dispEditorAdminIndex()
22
	{
23
		$component_count = 0;
24
		$site_module_info = Context::get('site_module_info');
25
		$site_srl = (int)$site_module_info->site_srl;
26
27
		// Get a type of component
28
		$oEditorModel = getModel('editor');
29
		$oModuleModel = getModel('module');
30
		$editor_config = $oModuleModel->getModuleConfig('editor');
31
32
		if(!$editor_config)
33
		{
34
			$editor_config = new stdClass();
35
		}
36
37
		//editor_config init
38
		if(!$editor_config->editor_height) $editor_config->editor_height = 300;
39
		if(!$editor_config->comment_editor_height) $editor_config->comment_editor_height = 100;
40
		if(!$editor_config->editor_skin) $editor_config->editor_skin = 'ckeditor';
41
		if(!$editor_config->comment_editor_skin) $editor_config->comment_editor_skin = 'ckeditor';
42
		if(!$editor_config->sel_editor_colorset) $editor_config->sel_editor_colorset= 'moono';
43
		if(!$editor_config->sel_comment_editor_colorset) $editor_config->sel_comment_editor_colorset= 'moono';
44
45
		$component_list = $oEditorModel->getComponentList(false, $site_srl, true);
46
		$editor_skin_list = FileHandler::readDir(_XE_PATH_.'modules/editor/skins');
47
48
		$skin_info = $oModuleModel->loadSkinInfo($this->module_path,$editor_config->editor_skin);
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
49
50
		$contents = FileHandler::readDir(_XE_PATH_.'modules/editor/styles');
51
		$content_style_list = array();
52 View Code Duplication
		for($i=0,$c=count($contents);$i<$c;$i++)
53
		{
54
			$style = $contents[$i];
55
			$info = $oModuleModel->loadSkinInfo($this->module_path,$style,'styles');
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
56
			$content_style_list[$style] = new stdClass();
57
			$content_style_list[$style]->title = $info->title;
58
		}
59
60
		// Get install info, update info, count
61
		$oAutoinstallModel = getModel('autoinstall');
62
		foreach($component_list as $component_name => $xml_info)
63
		{
64
			$component_count++;
65
			$xml_info->path = './modules/editor/components/'.$xml_info->component_name;
66
			$xml_info->delete_url = $oAutoinstallModel->getRemoveUrlByPath($xml_info->path);
67
			$xml_info->package_srl = $oAutoinstallModel->getPackageSrlByPath($xml_info->path);
68
			if($xml_info->package_srl) $targetpackages[$xml_info->package_srl] = 0;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$targetpackages was never initialized. Although not strictly required by PHP, it is generally a good practice to add $targetpackages = 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...
69
		}
70
71
		if(is_array($targetpackages))	$packages = $oAutoinstallModel->getInstalledPackages(array_keys($targetpackages));
0 ignored issues
show
Bug introduced by
The variable $targetpackages 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...
72
73
		foreach($component_list as $component_name => $xml_info)
74
		{
75
			if($packages[$xml_info->package_srl])	$xml_info->need_update = $packages[$xml_info->package_srl]->need_update;
0 ignored issues
show
Bug introduced by
The variable $packages 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...
76
		}
77
		$editor_config_default = array( "editor_height" => "300", "comment_editor_height" => "100","content_font_size"=>"13");
78
79
		//editor preview
80
		$config = $oEditorModel->getEditorConfig();
81
82
		$option = new stdClass();
83
		$option->allow_fileupload = false;
84
		$option->content_style = $config->content_style;
85
		$option->content_font = $config->content_font;
86
		$option->content_font_size = $config->content_font_size;
87
		$option->enable_autosave = false;
88
		$option->enable_default_component = true;
89
		$option->enable_component = true;
90
		$option->disable_html = false;
91
		$option->height = $config->editor_height;
92
		$option->skin = $config->editor_skin;
93
		$option->content_key_name = 'dummy_content';
94
		$option->primary_key_name = 'dummy_key';
95
		$option->colorset = $config->sel_editor_colorset;
96
		$editor = $oEditorModel->getEditor(0, $option);
97
98
		Context::set('preview_editor', $editor);
99
100
		$option_com = new stdClass();
101
		$option_com->allow_fileupload = false;
102
		$option_com->content_style = $config->content_style;
103
		$option_com->content_font = $config->content_font;
104
		$option_com->content_font_size = $config->content_font_size;
105
		$option_com->enable_autosave = false;
106
		$option_com->enable_default_component = true;
107
		$option_com->enable_component = true;
108
		$option_com->disable_html = false;
109
		$option_com->height = $config->comment_editor_height;
110
		$option_com->skin = $config->comment_editor_skin;
111
		$option_com->content_key_name = 'dummy_content2';
112
		$option_com->primary_key_name = 'dummy_key2';
113
		$option_com->content_style = $config->comment_content_style;
114
		$option_com->colorset = $config->sel_comment_editor_colorset;
115
116
		$editor_comment = $oEditorModel->getEditor(0, $option_com);
117
118
		Context::set('preview_editor_comment', $editor_comment);
119
120
		Context::set('editor_config', $editor_config);
121
		Context::set('editor_skin_list', $editor_skin_list);
0 ignored issues
show
Documentation introduced by
$editor_skin_list is of type array<integer,string>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
122
		Context::set('editor_colorset_list', $skin_info->colorset);
123
		Context::set('content_style_list', $content_style_list);
0 ignored issues
show
Documentation introduced by
$content_style_list is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
		Context::set('component_list', $component_list);
125
		Context::set('component_count', $component_count);
126
		Context::set('editor_config_default', $editor_config_default);
0 ignored issues
show
Documentation introduced by
$editor_config_default is of type array<string,string,{"ed...t_font_size":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
128
		$security = new Security();
129
		$security->encodeHTML('component_list....');
130
131
		$this->setTemplatePath($this->module_path.'tpl');
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
132
		$this->setTemplateFile('admin_index');
133
	}
134
135
	/**
136
	 * @brief Component setup
137
	 */
138
	function dispEditorAdminSetupComponent()
139
	{
140
		$site_module_info = Context::get('site_module_info');
141
		$site_srl = (int)$site_module_info->site_srl;
142
143
		$component_name = Context::get('component_name');
144
		// Get information of the editor component
145
		$oEditorModel = getModel('editor');
146
		$component = $oEditorModel->getComponent($component_name,$site_srl);
147
		Context::set('component', $component);
148
		// Get a group list to set a group
149
		$oMemberModel = getModel('member');
150
		$group_list = $oMemberModel->getGroups($site_srl);
151
		Context::set('group_list', $group_list);
152
		// Get a mid list
153
		$oModuleModel = getModel('module');
154
155
		$args =new stdClass();
156
		$args->site_srl = $site_srl;
157
		$columnList = array('module_srl', 'mid', 'module_category_srl', 'browser_title');
158
		$mid_list = $oModuleModel->getMidList($args, $columnList);
159
		// Combination of module_category and module
160 View Code Duplication
		if(!$args->site_srl)
161
		{
162
			// Get a list of module category
163
			$module_categories = $oModuleModel->getModuleCategories();
164
165
			if(!is_array($mid_list)) $mid_list = array($mid_list);
166
			foreach($mid_list as $module_srl => $module)
167
			{
168
				if($module) $module_categories[$module->module_category_srl]->list[$module_srl] = $module; 
169
			}
170
		}
171
		else
172
		{
173
			$module_categories[0]->list = $mid_list;
0 ignored issues
show
Bug introduced by
The variable $module_categories seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
174
		}
175
176
		Context::set('mid_list',$module_categories);
0 ignored issues
show
Bug introduced by
The variable $module_categories 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...
177
178
		//Security
179
		$security = new Security();
180
		$security->encodeHTML('group_list..title');
181
		$security->encodeHTML('component...');
182
		$security->encodeHTML('mid_list..title','mid_list..list..browser_title');
183
184
		$this->setTemplatePath($this->module_path.'tpl');
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
185
		$this->setTemplateFile('setup_component');
186
	}
187
}
188
/* End of file editor.admin.view.php */
189
/* Location: ./modules/editor/editor.admin.view.php */
190