| Conditions | 17 |
| Paths | 1944 |
| Total Lines | 50 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 81 | public static function init (array|easySettings $settings): void { |
||
| 82 | if (!is_array($settings)) { |
||
|
|
|||
| 83 | $settings = $settings->getSettings(); |
||
| 84 | } |
||
| 85 | foreach ($settings as $setting => $value) { |
||
| 86 | try { |
||
| 87 | if ($setting === 'name') { |
||
| 88 | if (!is_dir(realpath('bots_files'))) { |
||
| 89 | mkdir('bots_files'); |
||
| 90 | } |
||
| 91 | if (!is_dir(realpath('bots_files/' . $value))) { |
||
| 92 | mkdir('bots_files/' . $value); |
||
| 93 | } |
||
| 94 | $value = 'bots_files/' . $value . '/'; |
||
| 95 | } |
||
| 96 | self::$$setting = $value; |
||
| 97 | } |
||
| 98 | catch (TypeError) { |
||
| 99 | logger::write("$setting setting has wrong type , its set to default value", loggerTypes::WARNING); |
||
| 100 | } |
||
| 101 | catch (Error) { |
||
| 102 | logger::write("$setting setting is not one of library settings", loggerTypes::WARNING); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | if (settings::$logger) { |
||
| 106 | logger::init(self::$name, self::$log_size); |
||
| 107 | } |
||
| 108 | if (self::$token === '') { |
||
| 109 | $secret = str_replace('---', ':', webhook::getSecret()); |
||
| 110 | if (!lock::exist('BPT-HOOK') || !tools::isToken($secret)) { |
||
| 111 | logger::write('You must specify token parameter in settings', loggerTypes::ERROR); |
||
| 112 | throw new bptException('TOKEN_NOT_FOUND'); |
||
| 113 | } |
||
| 114 | self::$token = $secret; |
||
| 115 | } |
||
| 116 | if (!tools::isToken(self::$token)) { |
||
| 117 | logger::write('token format is not right, check it and try again', loggerTypes::ERROR); |
||
| 118 | throw new bptException('TOKEN_NOT_TRUE'); |
||
| 119 | } |
||
| 120 | self::$bot_id = explode(':', self::$token)[0]; |
||
| 121 | self::security(); |
||
| 122 | self::secureFolder(); |
||
| 123 | if (!empty(settings::$db)) { |
||
| 124 | db::init(); |
||
| 125 | } |
||
| 126 | if (!empty(settings::$pay)) { |
||
| 127 | pay::init(); |
||
| 128 | } |
||
| 129 | if (!empty(self::$receiver)) { |
||
| 130 | self::$receiver !== receiver::GETUPDATES ? webhook::init() : self::getUpdates(); |
||
| 131 | } |
||
| 191 |