| Conditions | 7 |
| Paths | 2 |
| Total Lines | 66 |
| Code Lines | 35 |
| 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 |
||
| 27 | public function register(Container $app) |
||
| 28 | { |
||
| 29 | |||
| 30 | $app['intaro_pinba.script_name_configure.class'] = 'Intaro\PinbaBundle\EventListener\ScriptNameConfigureListener'; |
||
| 31 | $app['intaro_pinba.stopwatch.class'] = 'Intaro\PinbaBundle\Stopwatch\Stopwatch'; |
||
| 32 | $app['intaro_pinba.templating.engine.twig.class'] = 'SilexPinbaProvider\Twig\TimedTwigEnvironment'; |
||
| 33 | $app['intaro_pinba.dbal.logger.class'] = 'Intaro\PinbaBundle\Logger\DbalLogger'; |
||
| 34 | $app['intaro_pinba.server.name'] = 'localhost'; |
||
| 35 | $app['intaro_pinba.script_name_configure.enable'] = true; |
||
| 36 | |||
| 37 | |||
| 38 | $app['intaro_pinba.script_name_configure.listener'] = function () use ($app) { |
||
| 39 | return new $app['intaro_pinba.script_name_configure.class']; |
||
| 40 | }; |
||
| 41 | |||
| 42 | $app['intaro_pinba.stopwatch'] = function () use ($app) { |
||
| 43 | return new $app['intaro_pinba.stopwatch.class']; |
||
| 44 | }; |
||
| 45 | |||
| 46 | $app['doctrine.dbal.logger'] = function () use ($app) { |
||
| 47 | /** |
||
| 48 | * @see \Intaro\PinbaBundle\Logger\DbalLogger |
||
| 49 | */ |
||
| 50 | $className = $app['intaro_pinba.dbal.logger.class']; |
||
| 51 | $host = isset($app["intaro_pinba.doctrine.database_host"]) ? $app["intaro_pinba.doctrine.database_host"] : $app['intaro_pinba.server.name']; |
||
| 52 | return new $className($app["intaro_pinba.stopwatch"], $host); |
||
| 53 | }; |
||
| 54 | |||
| 55 | $app['dbs.config'] = function ($app) { |
||
| 56 | $app['dbs.options.initializer'](); |
||
| 57 | |||
| 58 | $configs = new Container(); |
||
| 59 | foreach ($app['dbs.options'] as $name => $options) { |
||
| 60 | $configs[$name] = new Configuration(); |
||
| 61 | |||
| 62 | if (isset($app['logger']) && class_exists('Intaro\PinbaBundle\Logger\DbalLogger')) { |
||
| 63 | $configs[$name]->setSQLLogger($app['doctrine.dbal.logger']); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | return $configs; |
||
| 68 | }; |
||
| 69 | |||
| 70 | $app['twig.environment_factory'] = $app->protect(function ($app) { |
||
| 71 | $className = $app['intaro_pinba.templating.engine.twig.class']; |
||
| 72 | $twig = new $className($app['twig.loader'], $app['twig.options']); |
||
| 73 | if($twig instanceof TimedTwigEnvironment) { |
||
| 74 | $twig |
||
| 75 | ->setStopwatch( $app['intaro_pinba.stopwatch']) |
||
| 76 | ->setServerName($app['intaro_pinba.server.name']) |
||
| 77 | ; |
||
| 78 | } |
||
| 79 | return $twig; |
||
| 80 | }); |
||
| 81 | |||
| 82 | |||
| 83 | if (PHP_SAPI !== 'cli') { |
||
| 84 | $app->extend('dispatcher', function ($dispatcher) use ($app) { |
||
| 85 | /** |
||
| 86 | * @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface |
||
| 87 | */ |
||
| 88 | $dispatcher->addListener('kernel.request', array($app['intaro_pinba.script_name_configure.listener'], 'onRequest')); |
||
| 89 | return $dispatcher; |
||
| 90 | }); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |