| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| Code Lines | 44 |
| Lines | 5 |
| Ratio | 7.14 % |
| 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 declare(strict_types=1); |
||
| 66 | protected function setupContainer() |
||
| 67 | { |
||
| 68 | $APP_DIR = realpath(__DIR__ . '/../../app'); |
||
| 69 | $APPCONF_DIR = realpath("{$APP_DIR}/appConf/"); |
||
| 70 | $CONF_DIR = realpath("{$APP_DIR}/config/"); |
||
| 71 | require_once $APPCONF_DIR . '/base_config.php'; // $base_config |
||
| 72 | |||
| 73 | $config = loadToml($CONF_DIR); |
||
| 74 | $config_array = array_merge($base_config, $config); |
||
|
|
|||
| 75 | |||
| 76 | $di = function ($config_array) use ($APP_DIR) { |
||
| 77 | $container = new Container(); |
||
| 78 | |||
| 79 | // ------------------------------------------------------------------------- |
||
| 80 | // Logging |
||
| 81 | // ------------------------------------------------------------------------- |
||
| 82 | |||
| 83 | $app_logger = new Logger('animeclient'); |
||
| 84 | $app_logger->pushHandler(new NullHandler); |
||
| 85 | $kitsu_request_logger = new Logger('kitsu-request'); |
||
| 86 | $kitsu_request_logger->pushHandler(new NullHandler); |
||
| 87 | $mal_request_logger = new Logger('mal-request'); |
||
| 88 | $mal_request_logger->pushHandler(new NullHandler); |
||
| 89 | $container->setLogger($app_logger, 'default'); |
||
| 90 | $container->setLogger($kitsu_request_logger, 'kitsu-request'); |
||
| 91 | $container->setLogger($mal_request_logger, 'mal-request'); |
||
| 92 | |||
| 93 | // Create Config Object |
||
| 94 | $container->set('config', function() use ($config_array) { |
||
| 95 | return new Config($config_array); |
||
| 96 | }); |
||
| 97 | |||
| 98 | // Create Cache Object |
||
| 99 | View Code Duplication | $container->set('cache', function($container) { |
|
| 100 | $logger = $container->getLogger(); |
||
| 101 | $config = $container->get('config')->get('cache'); |
||
| 102 | return new Pool($config, $logger); |
||
| 103 | }); |
||
| 104 | |||
| 105 | // Create session Object |
||
| 106 | $container->set('session', function() { |
||
| 107 | return (new SessionFactory())->newInstance($_COOKIE); |
||
| 108 | }); |
||
| 109 | |||
| 110 | // Models |
||
| 111 | $container->set('kitsu-model', function($container) { |
||
| 112 | $listItem = new Kitsu\ListItem(); |
||
| 113 | $listItem->setContainer($container); |
||
| 114 | $model = new Kitsu\Model($listItem); |
||
| 115 | $model->setContainer($container); |
||
| 116 | $cache = $container->get('cache'); |
||
| 117 | $model->setCache($cache); |
||
| 118 | return $model; |
||
| 119 | }); |
||
| 120 | $container->set('mal-model', function($container) { |
||
| 121 | $listItem = new MAL\ListItem(); |
||
| 122 | $listItem->setContainer($container); |
||
| 123 | $model = new MAL\Model($listItem); |
||
| 124 | $model->setContainer($container); |
||
| 125 | return $model; |
||
| 126 | }); |
||
| 127 | $container->set('util', function($container) { |
||
| 128 | return new Util($container); |
||
| 129 | }); |
||
| 130 | |||
| 131 | return $container; |
||
| 132 | }; |
||
| 133 | |||
| 134 | return $di($config_array); |
||
| 135 | } |
||
| 136 | } |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.