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