| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 19 | public function register() |
||
|
|
|||
| 20 | { |
||
| 21 | $this->getContainer()->share('config', function () { |
||
| 22 | return [ |
||
| 23 | 'environment' => $_ENV['ENV'], |
||
| 24 | 'base_url' => $_ENV['BASE_URL'], |
||
| 25 | 'logger' => $_ENV['LOGGER'], |
||
| 26 | 'slack_api' => $_ENV['SLACK_API'], |
||
| 27 | 'slack_channel' => $_ENV['SLACK_CHANNEL'], |
||
| 28 | 'slack_bot_name' => $_ENV['SLACK_BOT_NAME'], |
||
| 29 | 'database' => [ |
||
| 30 | 'host' => $_ENV['DB_HOST'], |
||
| 31 | 'port' => $_ENV['DB_PORT'], |
||
| 32 | 'user' => $_ENV['DB_USER'], |
||
| 33 | 'password' => $_ENV['DB_PASS'], |
||
| 34 | 'schema' => $_ENV['DB_NAME'] |
||
| 35 | ], |
||
| 36 | 'database_data' => [ |
||
| 37 | 'host' => $_ENV['DB_HOST'], |
||
| 38 | 'port' => $_ENV['DB_PORT'], |
||
| 39 | 'user' => $_ENV['DB_USER'], |
||
| 40 | 'password' => $_ENV['DB_PASS'], |
||
| 41 | 'schema' => $_ENV['DB_NAME_DATA'] |
||
| 42 | ], |
||
| 43 | 'database_archive' => [ |
||
| 44 | 'host' => $_ENV['DB_ARCHIVE_HOST'], |
||
| 45 | 'port' => $_ENV['DB_ARCHIVE_PORT'], |
||
| 46 | 'user' => $_ENV['DB_ARCHIVE_USER'], |
||
| 47 | 'password' => $_ENV['DB_ARCHIVE_PASS'], |
||
| 48 | 'schema' => $_ENV['DB_ARCHIVE_NAME'] |
||
| 49 | ], |
||
| 50 | 'redis' => [ |
||
| 51 | 'enabled' => $_ENV['REDIS_ENABLED'], |
||
| 52 | 'host' => $_ENV['REDIS_HOST'], |
||
| 53 | 'port' => $_ENV['REDIS_PORT'], |
||
| 54 | 'pass' => $_ENV['REDIS_PASS'], |
||
| 55 | 'db' => $_ENV['REDIS_DB'], |
||
| 56 | ], |
||
| 57 | 'servers' => [1, 10, 13, 17, 25, 1000, 2000], |
||
| 58 | 'zones' => [2, 4, 6, 8], |
||
| 59 | 'classes' => [1, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21], |
||
| 60 | 'classesGroups' => [ |
||
| 61 | 'infiltrator' => [1, 8, 15], |
||
| 62 | 'la' => [3, 10, 17], |
||
| 63 | 'medic' => [4, 11, 18], |
||
| 64 | 'engineer' => [5, 12, 19], |
||
| 65 | 'ha' => [6, 13, 20], |
||
| 66 | 'max' => [7, 14, 21] |
||
| 67 | ], |
||
| 68 | 'classesFactions' => [ |
||
| 69 | 'nc' => [1, 3, 4, 5, 6, 7], |
||
| 70 | 'tr' => [8, 10, 11, 12, 13, 14], |
||
| 71 | 'vs' => [15, 17, 18, 19, 20, 21] |
||
| 72 | ], |
||
| 73 | 'factions' => ['vs', 'nc', 'tr', 'draw'], |
||
| 74 | 'brackets' => ['MOR', 'AFT', 'PRI'], |
||
| 75 | 'db_query_debug' => $_ENV['DB_QUERY_DEBUG'], |
||
| 76 | 'commands_path' => $_ENV['COMMANDS_PATH'], |
||
| 77 | 'census_service_id' => $_ENV['CENSUS_SERVICE_ID'] |
||
| 78 | ]; |
||
| 79 | }); |
||
| 80 | } |
||
| 81 | } |
||
| 82 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: