Completed
Push — master ( e8691f...abab0f )
by Angus
03:04
created

Options::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.216

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 5
cp 0.4
crap 1.216
rs 9.4285
c 0
b 0
f 0
1
<?php defined('BASEPATH') or exit('No direct script access allowed');
2
3
class Options extends Auth_Controller {
4 1
	public function __construct() {
5 1
		parent::__construct();
6
7
		$this->load->helper('form');
8
		$this->load->library('form_validation');
9
	}
10
11
	public function index() {
12
		$this->header_data['title'] = "Options";
13
		$this->header_data['page']  = "options";
14
15
		$customCategories = ['custom1' => 'category_custom_1', 'custom2' => 'category_custom_2', 'custom3' => 'category_custom_3'];
16
		$usedCategories   = $this->Tracker->getUsedCategories($this->User->id);
17
18
		//NOTE: The checkbox validation is handled in run()
19
		$this->form_validation->set_rules('category_custom_1_text',   'Custom Category 1 Text', 'trim|regex_match[/^[a-zA-Z0-9-_\\s]{0,16}$/]');
20
		$this->form_validation->set_rules('category_custom_2_text',  'Custom Category 2 Text',  'trim|regex_match[/^[a-zA-Z0-9-_\\s]{0,16}$/]');
21
		$this->form_validation->set_rules('category_custom_3_text',  'Custom Category 3 Text',  'trim|regex_match[/^[a-zA-Z0-9-_\\s]{0,16}$/]');
22
		$this->form_validation->set_rules('default_series_category', 'Default Series Category', 'required|is_valid_option_value[default_series_category]');
23
		$this->form_validation->set_rules('list_sort_type',          'List Sort Type',          'required|is_valid_option_value[list_sort_type]');
24
		$this->form_validation->set_rules('list_sort_order',         'List Sort Order',         'required|is_valid_option_value[list_sort_order]');
25
26
		if ($isValid = $this->form_validation->run() === TRUE) {
0 ignored issues
show
Unused Code introduced by
$isValid 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...
27
			foreach($customCategories as $categoryK => $category) {
28
				if(!in_array($categoryK, $usedCategories)) {
29
					$this->User_Options->set($category, $this->input->post($category) ? 'enabled' : 'disabled');
30
				}
31
32
				$this->User_Options->set($category.'_text', $this->input->post($category.'_text') ?? '');
33
			}
34
35
			$this->User_Options->set('default_series_category', $this->input->post('default_series_category'));
36
37
			$this->User_Options->set('enable_live_countdown_timer', $this->input->post('enable_live_countdown_timer'));
38
39
			$this->User_Options->set('list_sort_type',  $this->input->post('list_sort_type'));
40
			$this->User_Options->set('list_sort_order', $this->input->post('list_sort_order'));
41
		}
42
43
		/*** CUSTOM CATEGORIES ***/
44
		foreach($customCategories as $categoryK => $category) {
45
			$this->body_data[$category]               = ($this->User_Options->get($category) == 'enabled' ? TRUE : FALSE);
46
			$this->body_data[$category.'_text']       = $this->User_Options->get($category.'_text');
47
			$this->body_data[$category.'_has_series'] = (int) in_array($categoryK, $usedCategories);
48
		}
49
50
		/*** DEFAULT CATEGORY ***/
51
		$this->body_data['default_series_category'] = array_intersect_key(
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52
			array(
53
				'reading'      => 'Reading',
54
				'on-hold'      => 'On-Hold',
55
				'plan-to-read' => 'Plan to Read',
56
				'custom1'      => 'Custom Category 1',
57
				'custom2'      => 'Custom Category 2',
58
				'custom3'      => 'Custom Category 3'
59
			),
60
			array_flip(array_values($this->User_Options->options['default_series_category']['valid_options']))
61
		);
62
		$this->body_data['default_series_category_selected'] = $this->User_Options->get('default_series_category');
63
64
		/*** ENABLE LIVE JS COUNTDOWN TIMER ***/
65
		$this->body_data = array_merge($this->body_data, $this->User_Options->generate_radio_array(
66
			'enable_live_countdown_timer',
67
			$this->User_Options->get('enable_live_countdown_timer')
68
		));
69
70
71
		$this->body_data['list_sort_type'] = array_intersect_key(
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
72
			array(
73
				'unread'       => 'Unread',
74
				'alphabetical' => 'Alphabetical',
75
				'my_status'    => 'My Status',
76
				'latest'       => 'Latest Release'
77
			),
78
			array_flip(array_values($this->User_Options->options['list_sort_type']['valid_options']))
79
		);
80
		$this->body_data['list_sort_type_selected'] = $this->User_Options->get('list_sort_type');
81
82
		$this->body_data['list_sort_order'] = array_intersect_key(
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
83
			array(
84
				'asc'  => 'ASC',
85
				'desc' => 'DESC'
86
			),
87
			array_flip(array_values($this->User_Options->options['list_sort_order']['valid_options']))
88
		);
89
		$this->body_data['list_sort_order_selected'] = $this->User_Options->get('list_sort_order');
90
91
		$this->_render_page('User/Options');
92
	}
93
}
94