| Conditions | 10 |
| Paths | 2 |
| Total Lines | 47 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 56 | public function register(): void |
||
| 57 | { |
||
| 58 | $this->app->bind(PhpTelegramBotContract::class, static function ($app) { |
||
| 59 | $config = $app['config']->get('phptelegrambot'); |
||
| 60 | |||
| 61 | $bot = new PhpTelegramBot($config['bot']['api_key'], ! empty($config['bot']['name']) ? $config['bot']['name'] : ''); |
||
| 62 | |||
| 63 | // Add commands if paths are given |
||
| 64 | if (! empty($config['commands']['paths'])) { |
||
| 65 | $bot->addCommandsPaths($config['commands']['paths']); |
||
| 66 | } |
||
| 67 | |||
| 68 | // Set command related configs |
||
| 69 | if (! empty($config['commands']['configs'])) { |
||
| 70 | foreach ($config['commands']['configs'] as $commandName => $commandConfig) { |
||
| 71 | $bot->setCommandConfig($commandName, $commandConfig); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | // Set database connection |
||
| 76 | if ($config['database']['enabled'] === true) { |
||
| 77 | /** @var \Illuminate\Database\Connection $connection */ |
||
| 78 | $connection = $app['db']->connection($config['database']['connection']); |
||
| 79 | // Ability to use custom table prefix |
||
| 80 | $tablePrefix = $config['database']['prefix'] ?? ''; |
||
| 81 | $bot->enableExternalMySql($connection->getPdo(), $tablePrefix); |
||
| 82 | } |
||
| 83 | |||
| 84 | // Enable admins if provided |
||
| 85 | if (! empty($config['admins'])) { |
||
| 86 | $bot->enableAdmins($config['admins']); |
||
| 87 | } |
||
| 88 | |||
| 89 | // Set paths |
||
| 90 | if (! empty($config['download_path'])) { |
||
| 91 | $bot->setDownloadPath($config['download_path']); |
||
| 92 | } |
||
| 93 | if (! empty($config['upload_path'])) { |
||
| 94 | $bot->setUploadPath($config['upload_path']); |
||
| 95 | } |
||
| 96 | |||
| 97 | return $bot; |
||
| 98 | }); |
||
| 99 | |||
| 100 | if ($this->app->runningInConsole()) { |
||
| 101 | $this->commands([ |
||
| 102 | WebhookCommand::class, |
||
| 103 | ]); |
||
| 117 |