| Conditions | 15 |
| Paths | 504 |
| Total Lines | 43 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 70 | public static function init (array|stdClass $settings): void { |
||
| 71 | $settings = (array) $settings; |
||
| 72 | foreach ($settings as $setting => $value) { |
||
| 73 | try { |
||
| 74 | if ($setting === 'name') { |
||
| 75 | if (!is_dir(realpath('bots_files'))) { |
||
| 76 | mkdir('bots_files'); |
||
| 77 | } |
||
| 78 | if (!is_dir(realpath('bots_files/' . $value))) { |
||
| 79 | mkdir('bots_files/' . $value); |
||
| 80 | } |
||
| 81 | $value = 'bots_files/' . $value . '/'; |
||
| 82 | } |
||
| 83 | self::$$setting = $value; |
||
| 84 | } |
||
| 85 | catch (TypeError) { |
||
| 86 | logger::write("$setting setting has wrong type , its set to default value", loggerTypes::WARNING); |
||
| 87 | } |
||
| 88 | catch (Error) { |
||
| 89 | logger::write("$setting setting is not one of library settings", loggerTypes::WARNING); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | if (!(isset($settings['logger']) && $settings['logger'] == false)) { |
||
| 93 | logger::init(self::$log_size); |
||
| 94 | } |
||
| 95 | if (self::$token === '') { |
||
| 96 | logger::write('You must specify token parameter in settings', loggerTypes::ERROR); |
||
| 97 | throw new bptException('TOKEN_NOT_FOUND'); |
||
| 98 | } |
||
| 99 | if (!tools::isToken(self::$token)) { |
||
| 100 | logger::write('token format is not right, check it and try again', loggerTypes::ERROR); |
||
| 101 | throw new bptException('TOKEN_NOT_TRUE'); |
||
| 102 | } |
||
| 103 | self::security(); |
||
| 104 | self::secureFolder(); |
||
| 105 | if (!empty(settings::$db)) { |
||
| 106 | db::init(); |
||
| 107 | } |
||
| 108 | if (!empty(settings::$pay)) { |
||
| 109 | pay::init(); |
||
| 110 | } |
||
| 111 | if (!empty(self::$receiver)) { |
||
| 112 | self::$receiver !== receiver::GETUPDATES ? webhook::init() : self::getUpdates(); |
||
| 113 | } |
||
| 170 |