Conditions | 11 |
Paths | 8 |
Total Lines | 44 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
31 | public static function config($c) |
||
32 | { |
||
33 | self::$config = self::$config ?: [ |
||
34 | 'APP' => 'App', |
||
35 | 'DB_COLLATION_CI' => 'utf8mb4_general_ci', //UTF8_GENERAL_CI |
||
36 | 'EMPTY_TABLE_MSG' => 'No results found.', |
||
37 | 'EXPORT_FILE_NAME' => ':app - :items export (:datetime)', |
||
38 | 'FILTER_ACTIVE' => true, |
||
39 | 'FILTER_CASE_SENSITIVE' => false, |
||
40 | 'SAVES' => ['CSV', 'Excel'], |
||
41 | 'UTF8_ASC_SYMBOL' => '▲', |
||
42 | 'UTF8_DESC_SYMBOL' => '▼', |
||
43 | 'UTF8_LEFT_SYMBOL' => '‹', |
||
44 | 'UTF8_RIGHT_SYMBOL' => '›' |
||
45 | ]; |
||
46 | |||
47 | $getValid = function($k, $v = null) { |
||
48 | if (!array_key_exists($k, self::$config)) { |
||
49 | throw new Exception('Request to undefined value: ' . $k); |
||
50 | } |
||
51 | |||
52 | if ($v !== null) { |
||
53 | if (empty($v) || gettype($v) !== gettype(self::$config[$k])) { |
||
54 | throw new Exception("Setting invalid value: $v (:$k)"); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | return $v === null ? self::$config[$k] : $v; |
||
59 | }; |
||
60 | |||
61 | try { |
||
62 | switch (gettype($c)) { |
||
63 | case 'array'; |
||
64 | foreach ($c as $k => $v) { |
||
65 | self::$config[$k] = $getValid((string) $k, $v); |
||
66 | } |
||
67 | break; |
||
68 | case 'string': |
||
69 | return $getValid($c); |
||
70 | default: |
||
71 | throw new Exception("Invalid value type."); |
||
72 | } |
||
73 | } catch (Exception $e) { |
||
74 | self::err('ERROR: ' . $e->getMessage()); |
||
75 | } |
||
149 |