Conditions | 8 |
Paths | 2 |
Total Lines | 96 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
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 |
||
26 | public function register(Application $app) |
||
27 | { |
||
28 | if (isset($app['profiler'])) { |
||
29 | |||
30 | $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig) { |
||
31 | $twig->addExtension(new DoctrineExtension()); |
||
32 | |||
33 | return $twig; |
||
34 | })); |
||
35 | |||
36 | $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', |
||
37 | function (\Twig_Loader_Filesystem $twigLoaderFilesystem) { |
||
38 | $twigLoaderFilesystem->addPath(dirname(__DIR__). '/Resources/views', 'SaxulumWebProfilerProvider'); |
||
39 | |||
40 | return $twigLoaderFilesystem; |
||
41 | } |
||
42 | )); |
||
43 | |||
44 | $app['data_collectors'] = $app->extend('data_collectors', |
||
45 | $app->share(function(array $collectors) use ($app) { |
||
46 | if(isset($app['doctrine'])) { |
||
47 | $app['saxulum.orm.logger'] = function ($app) { |
||
48 | return new DbalLogger($app['monolog'], $app['stopwatch']); |
||
49 | }; |
||
50 | |||
51 | $collectors['db'] = $app->share(function ($app) { |
||
52 | $dataCollector = new DoctrineDataCollector($app['doctrine']); |
||
53 | foreach ($app['doctrine']->getConnectionNames() as $name) { |
||
54 | $logger = $app['saxulum.orm.logger']; |
||
55 | $app['doctrine']->getConnection($name)->getConfiguration()->setSQLLogger($logger); |
||
56 | $dataCollector->addLogger($name, $logger); |
||
57 | } |
||
58 | |||
59 | return $dataCollector; |
||
60 | }); |
||
61 | } |
||
62 | |||
63 | if(isset($app['doctrine_mongodb'])) { |
||
64 | $app['saxulum.webprofiler.mongodb.odm.logger.batchthreshold'] = 4; |
||
65 | |||
66 | $app['saxulum.mongodb.odm.logger'] = $app->share(function ($app) { |
||
67 | $logger = new DoctrineMongoDbLogger($app['monolog']); |
||
68 | $logger->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']); |
||
69 | |||
70 | return $logger; |
||
71 | }); |
||
72 | |||
73 | $app['saxulum.mongodb.odm.loggers'] = $app->share(function ($app) { |
||
74 | $loggers = array(); |
||
75 | $loggers[] = $app['saxulum.mongodb.odm.logger']; |
||
76 | $loggers[] = $app['saxulum.mongodb.odm.datacolletor']; |
||
77 | |||
78 | return $loggers; |
||
79 | }); |
||
80 | |||
81 | $app['saxulum.mongodb.odm.aggregatelogger'] = $app->share(function ($app) { |
||
82 | $logger = new DoctrineMongoDbAggregateLogger($app['saxulum.mongodb.odm.loggers']); |
||
83 | |||
84 | return $logger; |
||
85 | }); |
||
86 | |||
87 | $aggregatedLogger = $app['saxulum.mongodb.odm.aggregatelogger']; |
||
88 | $app['doctrine_mongodb'] = $app->extend('doctrine_mongodb', |
||
89 | $app->share(function(ManagerRegistry $registry) use($aggregatedLogger) { |
||
90 | foreach ($registry->getConnectionNames() as $name) { |
||
91 | $registry->getConnection($name)->getConfiguration()->setLoggerCallable(array($aggregatedLogger, 'logQuery')); |
||
92 | } |
||
93 | } |
||
94 | )); |
||
95 | |||
96 | $collectors['mongodb'] = $app->share(function ($app) { |
||
97 | $dataCollector = new DoctrineMongoDbDataCollector(); |
||
98 | $dataCollector->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']); |
||
99 | |||
100 | return $dataCollector; |
||
101 | }); |
||
102 | } |
||
103 | |||
104 | return $collectors; |
||
105 | } |
||
106 | )); |
||
107 | |||
108 | $app['data_collector.templates'] = $app->extend('data_collector.templates', |
||
109 | $app->share(function(array $dataCollectorTemplates) use ($app) { |
||
110 | if(isset($app['doctrine'])) { |
||
111 | $dataCollectorTemplates[] = array('db', '@SaxulumWebProfilerProvider/Collector/db.html.twig'); |
||
112 | } |
||
113 | if(isset($app['doctrine_mongodb'])) { |
||
114 | $dataCollectorTemplates[] = array('mongodb', '@SaxulumWebProfilerProvider/Collector/mongodb.html.twig'); |
||
115 | } |
||
116 | |||
117 | return $dataCollectorTemplates; |
||
118 | } |
||
119 | )); |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 |