gallery_logs_module::main()   F
last analyzed

Complexity

Conditions 14
Paths 360

Size

Total Lines 137
Code Lines 86

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 210

Importance

Changes 0
Metric Value
eloc 86
c 0
b 0
f 0
dl 0
loc 137
rs 3.052
ccs 0
cts 115
cp 0
cc 14
nc 360
nop 2
crap 210

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
/**
3
 * phpBB Gallery - Core Extension
4
 *
5
 * @package   phpbbgallery/core
6
 * @author    nickvergessen
7
 * @author    satanasov
8
 * @author    Leinad4Mind
9
 * @copyright 2007-2012 nickvergessen, 2014- satanasov, 2018- Leinad4Mind
10
 * @license   GPL-2.0-only
11
 */
12
13
namespace phpbbgallery\core\acp;
14
15
/**
16
* @package acp
17
*/
18
class gallery_logs_module
19
{
20
	var $u_action;
21
22
	function main($id, $mode)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
	{
24
		global $auth, $template, $user, $request;
25
		global $phpbb_container;
26
27
		$this->language = $phpbb_container->get('language');
0 ignored issues
show
Bug Best Practice introduced by
The property language does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
		$this->language->add_lang(['info_acp_gallery_logs'], 'phpbbgallery/core');
29
30
		$this->tpl_name = 'gallery_logs';
0 ignored issues
show
Bug Best Practice introduced by
The property tpl_name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
		add_form_key('acp_logs');
0 ignored issues
show
Bug introduced by
The function add_form_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
		/** @scrutinizer ignore-call */ 
32
  add_form_key('acp_logs');
Loading history...
32
33
		$page				= $request->variable('page', 0);
34
		$filter_log		= $request->variable('lf', 'all');
35
		$sort_days		= $request->variable('st', 0);
36
		$sort_key		= $request->variable('sk', 't');
37
		$sort_dir		= $request->variable('sd', 'd');
38
		$deletemark		= $request->is_set_post('delmarked');
39
		$marked			= $request->variable('mark', []);
40
41
		$log = $phpbb_container->get('phpbbgallery.core.log');
42
43
		$valid_filters   = ['all', 'admin', 'moderator', 'system'];
44
		$valid_sort_keys = ['u', 't', 'i', 'o'];
45
		$valid_sort_dirs = ['a', 'd'];
46
47
		// Sanitize inputs
48
		if (!in_array($filter_log, $valid_filters))
49
		{
50
			$filter_log = 'all';
51
		}
52
		if (!in_array($sort_key, $valid_sort_keys))
53
		{
54
			$sort_key = 't';
55
		}
56
		if (!in_array($sort_dir, $valid_sort_dirs))
57
		{
58
			$sort_dir = 'd';
59
		}
60
61
		// Delete entries if requested and able
62
		if ($deletemark && $auth->acl_get('a_clearlogs') && !empty($marked))
63
		{
64
			if (!check_form_key('acp_logs'))
0 ignored issues
show
Bug introduced by
The function check_form_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
			if (!/** @scrutinizer ignore-call */ check_form_key('acp_logs'))
Loading history...
65
			{
66
				trigger_error($this->language->lang('FORM_INVALID'));
67
			}
68
69
			if (confirm_box(true))
0 ignored issues
show
Bug introduced by
The function confirm_box was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
			if (/** @scrutinizer ignore-call */ confirm_box(true))
Loading history...
70
			{
71
				$log->delete_logs($marked);
72
			}
73
			else
74
			{
75
				confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields([
0 ignored issues
show
Bug introduced by
The function build_hidden_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
				confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), /** @scrutinizer ignore-call */ build_hidden_fields([
Loading history...
76
					'page'		=> $page,
77
					'delmarked'	=> $deletemark,
78
					'mark'		=> $marked,
79
					'st'		=> $sort_days,
80
					'sk'		=> $sort_key,
81
					'sd'		=> $sort_dir,
82
					'i'			=> $id,
83
					'mode'		=> $mode,
84
					'action'		=> $this->u_action,
85
				]));
86
			}
87
		}
88
89
		switch ($mode)
90
		{
91
			case 'main':
92
				// Template vars based on filter
93
				$log_titles = [
94
					'all'      => ['ACP_GALLERY_LOGS', ''],
95
					'admin'    => ['ACP_LOG_GALLERY_ADM', 'ACP_LOG_GALLERY_ADM_EXP'],
96
					'moderator'=> ['ACP_LOG_GALLERY_MOD', 'ACP_LOG_GALLERY_MOD_EXP'],
97
					'system'   => ['ACP_LOG_GALLERY_SYSTEM', 'ACP_LOG_GALLERY_SYSTEM_EXP'],
98
				];
99
				$title = $log_titles[$filter_log][0];
100
101
				$template->assign_vars([
102
					'L_TITLE'         => $this->language->lang($log_titles[$filter_log][0]),
103
					'L_EXPLAIN'       => $log_titles[$filter_log][1] ? $this->language->lang($log_titles[$filter_log][1]) : '',
104
					'S_SELECT_OPTION' => $filter_log,
105
				]);
106
107
				// Sorting
108
				$limit_days = [
109
					0   => $this->language->lang('ALL_ENTRIES'),
110
					1   => $this->language->lang('1_DAY'),
111
					7   => $this->language->lang('7_DAYS'),
112
					14  => $this->language->lang('2_WEEKS'),
113
					30  => $this->language->lang('1_MONTH'),
114
					90  => $this->language->lang('3_MONTHS'),
115
					180 => $this->language->lang('6_MONTHS'),
116
					365 => $this->language->lang('1_YEAR'),
117
				];
118
				$sort_by_text = [
119
					'u' => $this->language->lang('SORT_USER_ID'),
120
					't' => $this->language->lang('SORT_DATE'),
121
					'i' => $this->language->lang('SORT_IP'),
122
					'o' => $this->language->lang('SORT_ACTION'),
123
				];
124
125
				$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
126
				gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
0 ignored issues
show
Bug introduced by
The function gen_sort_selects was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

126
				/** @scrutinizer ignore-call */ 
127
    gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
Loading history...
127
128
				$template->assign_vars(array(
129
					'S_LIMIT_DAYS'	=> $s_limit_days,
130
					'S_SORT_KEY'	=> $s_sort_key,
131
					'S_SORT_DIR'	=> $s_sort_dir,
132
					'S_CLEARLOGS'	=> $auth->acl_get('a_clearlogs'),
133
					'U_ACTION'		=> $this->u_action . "&amp;$u_sort_param&amp;page=$page",
134
				));
135
				$this->page_title = $this->language->lang($title);
0 ignored issues
show
Bug Best Practice introduced by
The property page_title does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
136
137
				// Build additional filters
138
				$additional = [];
139
				if ($sort_days > 0)
140
				{
141
					$additional['sort_days'] = $sort_days;
142
				}
143
				if ($sort_key !== 't')
144
				{
145
					$additional['sort_key'] = $sort_key;
146
				}
147
				if ($sort_dir !== 'd')
148
				{
149
					$additional['sort_dir'] = $sort_dir;
150
				}
151
152
				// Build list
153
				$log->build_list($filter_log, 0, $page, -1, 0, $additional);
154
			break;
155
156
			default:
157
				trigger_error('NO_MODE', E_USER_ERROR);
158
			break;
159
		}
160
	}
161
}
162