Tracker_Base_Model::getEnabledCategories()   B
last analyzed

Complexity

Conditions 6
Paths 18

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 18
nop 1
dl 0
loc 25
rs 8.8977
c 0
b 0
f 0
ccs 0
cts 13
cp 0
crap 42
1
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class Tracker_Base_Model extends CI_Model {
4
	public $sites;
5
	public $enabledCategories;
6
7
	//FIXME: This entire enabledCategories thing could be done better.
8
9 96
	public function __construct() {
10 96
		parent::__construct();
11
12 96
		$this->load->database();
13
14 96
		$this->enabledCategories = [
15
			'reading'      => 'Reading',
16
			'on-hold'      => 'On-Hold',
17
			'plan-to-read' => 'Plan to Read'
18
		];
19 96
		if($this->User_Options->get('category_custom_1') == 'enabled') {
20
			$this->enabledCategories['custom1'] = $this->User_Options->get('category_custom_1_text');
21
		}
22 96
		if($this->User_Options->get('category_custom_2') == 'enabled') {
23
			$this->enabledCategories['custom2'] = $this->User_Options->get('category_custom_2_text');
24
		}
25 96
		if($this->User_Options->get('category_custom_3') == 'enabled') {
26
			$this->enabledCategories['custom3'] = $this->User_Options->get('category_custom_3_text');
27
		}
28
29 96
		foreach (glob(APPPATH.'models/Tracker/Sites/*.php') as $filename) {
30
			/** @noinspection PhpIncludeInspection */
31 96
			include_once $filename;
32
		}
33 96
		$this->sites = new Tracker_Sites_Model;
34
35 96
	}
36
37
	public function getEnabledCategories(?int $userID = NULL) : array {
38
		$userID = (is_null($userID) ? (int) $this->User->id : $userID);
39
40
		$enabledCategories = [];
0 ignored issues
show
Unused Code introduced by
$enabledCategories 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...
41
		if(is_null($userID)) {
42
			$enabledCategories = $this->enabledCategories;
43
		} else {
44
			$enabledCategories = [
45
				'reading'      => 'Reading',
46
				'on-hold'      => 'On-Hold',
47
				'plan-to-read' => 'Plan to Read'
48
			];
49
			if($this->User_Options->get('category_custom_1', $userID) == 'enabled') {
50
				$enabledCategories['custom1'] = $this->User_Options->get('category_custom_1_text', $userID);
51
			}
52
			if($this->User_Options->get('category_custom_2', $userID) == 'enabled') {
53
				$enabledCategories['custom2'] = $this->User_Options->get('category_custom_2_text', $userID);
54
			}
55
			if($this->User_Options->get('category_custom_3', $userID) == 'enabled') {
56
				$enabledCategories['custom3'] = $this->User_Options->get('category_custom_3_text', $userID);
57
			}
58
		}
59
60
		return $enabledCategories;
61
	}
62
}
63