Conditions | 11 |
Paths | 21 |
Total Lines | 63 |
Code Lines | 36 |
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 |
||
13 | protected function initializeBundles() |
||
14 | { |
||
15 | $loader = new BundleLoader($this); |
||
16 | $bundles = new ArrayCollection(); |
||
17 | |||
18 | |||
19 | WellCommerceStandardEditionBundle::registerBundles($bundles, $this->getEnvironment()); |
||
20 | $loader->registerBundles($bundles, $this->getEnvironment()); |
||
21 | |||
22 | $bundles = array_merge($this->registerBundles(), $bundles->toArray()); |
||
23 | |||
24 | // init bundles |
||
25 | $this->bundles = array(); |
||
26 | $topMostBundles = array(); |
||
27 | $directChildren = array(); |
||
28 | |||
29 | foreach ($bundles as $bundle) { |
||
30 | |||
31 | /** @var BundleInterface $bundle */ |
||
32 | $name = $bundle->getName(); |
||
33 | if (isset($this->bundles[$name])) { |
||
34 | throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name)); |
||
35 | } |
||
36 | $this->bundles[$name] = $bundle; |
||
37 | |||
38 | if ($parentName = $bundle->getParent()) { |
||
39 | if (isset($directChildren[$parentName])) { |
||
40 | throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName])); |
||
41 | } |
||
42 | if ($parentName == $name) { |
||
43 | throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name)); |
||
44 | } |
||
45 | $directChildren[$parentName] = $name; |
||
46 | } else { |
||
47 | $topMostBundles[$name] = $bundle; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | // look for orphans |
||
52 | if (!empty($directChildren) && count($diff = array_diff_key($directChildren, $this->bundles))) { |
||
53 | $diff = array_keys($diff); |
||
54 | |||
55 | throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0])); |
||
56 | } |
||
57 | |||
58 | // inheritance |
||
59 | $this->bundleMap = array(); |
||
60 | foreach ($topMostBundles as $name => $bundle) { |
||
61 | $bundleMap = array($bundle); |
||
62 | $hierarchy = array($name); |
||
63 | |||
64 | while (isset($directChildren[$name])) { |
||
65 | $name = $directChildren[$name]; |
||
66 | array_unshift($bundleMap, $this->bundles[$name]); |
||
67 | $hierarchy[] = $name; |
||
68 | } |
||
69 | |||
70 | foreach ($hierarchy as $hierarchyBundle) { |
||
71 | $this->bundleMap[$hierarchyBundle] = $bundleMap; |
||
72 | array_pop($bundleMap); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |