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 = []; |
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.