1 | <?php |
||
11 | class Settings extends Component |
||
12 | { |
||
13 | /** |
||
14 | * @event SettingsEvent an event that is triggered before execute command. |
||
15 | */ |
||
16 | const EVENT_BEFORE_EXECUTE = 'beforeExecute'; |
||
17 | |||
18 | /* |
||
19 | * @var array The settings cache |
||
20 | */ |
||
21 | private $_data = []; |
||
22 | |||
23 | /** |
||
24 | * @var string Name of the table where configurations will be stored |
||
25 | */ |
||
26 | public $tableName = '{{%setting}}'; |
||
27 | |||
28 | /** |
||
29 | * @var string Name of column where keys will be stored |
||
30 | */ |
||
31 | public $keyColumnName = 'key'; |
||
32 | |||
33 | /** |
||
34 | * @var string Name of column where values will be stored |
||
35 | */ |
||
36 | public $valueColumnName = 'value'; |
||
37 | |||
38 | /** |
||
39 | * @return Connection the DB connection instance |
||
40 | */ |
||
41 | 2 | protected function getDb() |
|
45 | |||
46 | /** |
||
47 | * Whether the setting exists in the database |
||
48 | * @param string $name the setting name |
||
49 | * @return bool |
||
50 | */ |
||
51 | 2 | protected function exists($name) |
|
60 | |||
61 | /** |
||
62 | * Returns setting value from database |
||
63 | * @param string $name setting name |
||
64 | * @return mixed $defaultValue |
||
65 | */ |
||
66 | 1 | public function get($name, $defaultValue = null) |
|
89 | |||
90 | /** |
||
91 | * Store setting value to database |
||
92 | * @param string $name |
||
93 | * @param mixed $value |
||
94 | */ |
||
95 | 2 | public function set($name, $value) |
|
121 | |||
122 | /** |
||
123 | * Retrieves all setting stored in database |
||
124 | * @return array |
||
125 | */ |
||
126 | 1 | public function all() |
|
145 | |||
146 | /** |
||
147 | * Store all settings in database |
||
148 | * @param array $names |
||
149 | */ |
||
150 | 1 | public function save($names) |
|
156 | |||
157 | /** |
||
158 | * Remove specified setting |
||
159 | * @param array|string $name |
||
160 | */ |
||
161 | 1 | public function remove($name) |
|
177 | |||
178 | /** |
||
179 | * Removes all settings |
||
180 | */ |
||
181 | 1 | public function removeAll() |
|
193 | |||
194 | /** |
||
195 | * Creates query to find settings value |
||
196 | * @param string $name |
||
197 | * @return \yii\db\Query |
||
198 | */ |
||
199 | 2 | protected function createQuery($name = null) |
|
217 | |||
218 | /** |
||
219 | * This method is called at the before execute db command |
||
220 | * @return yii\base\Event |
||
221 | */ |
||
222 | 2 | protected function beforeExecute() |
|
228 | |||
229 | } |
||
230 |
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.