Conditions | 3 |
Paths | 1 |
Total Lines | 58 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
25 | public function getFactories() |
||
26 | { |
||
27 | $aggregateThemeFactory = null; |
||
28 | $aggregateThemeUnserializer = null; |
||
29 | return [ |
||
30 | AggregateThemeFactory::class => function(ContainerInterface $container) use (&$aggregateThemeFactory): AggregateThemeFactory |
||
31 | { |
||
32 | if ($aggregateThemeFactory !== null) { |
||
33 | return $aggregateThemeFactory; |
||
34 | } |
||
35 | $aggregateThemeFactory = new AggregateThemeFactory([]); |
||
36 | |||
37 | $subThemeFactory = new SubThemeFactory($aggregateThemeFactory); |
||
38 | $twigThemeFactory = new TwigThemeFactory($container->get(\Twig_Environment::class), $container->get(BlockRendererInterface::class)); |
||
39 | |||
40 | $aggregateThemeFactory->addThemeFactory($twigThemeFactory); |
||
41 | $aggregateThemeFactory->addThemeFactory($subThemeFactory); |
||
42 | return $aggregateThemeFactory; |
||
43 | }, |
||
44 | ThemeFactoryInterface::class => new Alias(AggregateThemeFactory::class), |
||
45 | BlockRendererInterface::class => new Alias(BlockRenderer::class), |
||
46 | BlockRenderer::class => function(ContainerInterface $container) use (&$aggregateThemeFactory): BlockRenderer |
||
47 | { |
||
48 | if ($aggregateThemeFactory === null) { |
||
49 | $aggregateThemeFactory = new AggregateThemeFactory([]); |
||
50 | } |
||
51 | |||
52 | $blockRenderer = new BlockRenderer($aggregateThemeFactory); |
||
53 | |||
54 | $subThemeFactory = new SubThemeFactory($aggregateThemeFactory); |
||
55 | $twigThemeFactory = new TwigThemeFactory($container->get(\Twig_Environment::class), $blockRenderer); |
||
56 | |||
57 | $aggregateThemeFactory->addThemeFactory($subThemeFactory); |
||
58 | $aggregateThemeFactory->addThemeFactory($twigThemeFactory); |
||
59 | |||
60 | return $blockRenderer; |
||
61 | }, |
||
62 | |||
63 | AggregateThemeUnserializer::class => function() use (&$aggregateThemeUnserializer): AggregateThemeUnserializer |
||
64 | { |
||
65 | list($aggregateThemeUnserializer, $blockUnserializer) = $this->getBlockAndAggregateUnserializer(); |
||
66 | |||
67 | |||
68 | $subThemeFactory = new SubThemeUnserializer($blockUnserializer, $aggregateThemeUnserializer); |
||
69 | $twigThemeFactory = new TwigThemeUnserializer(); |
||
70 | |||
71 | $aggregateThemeUnserializer->addUnserializer('twig', $twigThemeFactory); |
||
72 | $aggregateThemeUnserializer->addUnserializer('subTheme', $subThemeFactory); |
||
73 | return $aggregateThemeUnserializer; |
||
|
|||
74 | }, |
||
75 | ThemeUnserializerInterface::class => new Alias(AggregateThemeUnserializer::class), |
||
76 | BlockUnserializer::class => function(ContainerInterface $container) use (&$aggregateThemeUnserializer): BlockUnserializer |
||
77 | { |
||
78 | list($aggregateThemeUnserializer, $blockUnserializer) = $this->getBlockAndAggregateUnserializer(); |
||
79 | |||
80 | // Force resolving the aggregateThemeUnserializer |
||
81 | $container->get(AggregateThemeUnserializer::class); |
||
82 | return $blockUnserializer; |
||
83 | }, |
||
113 |