Conditions | 12 |
Paths | 30 |
Total Lines | 69 |
Code Lines | 46 |
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 |
||
35 | protected function execute(InputInterface $input, OutputInterface $output) |
||
36 | { |
||
37 | $table = new Table($output); |
||
38 | $table->setHeaders([ |
||
39 | 'Contextual View', |
||
40 | 'WidgetMaps in conflict', |
||
41 | 'Parent WidgetMap', |
||
42 | 'Slot', |
||
43 | 'Position', |
||
44 | ]); |
||
45 | |||
46 | /** @var EntityManager $entityManager */ |
||
47 | $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
48 | $contextualViewWarmer = $this->getContainer()->get('victoire_widget_map.contextual_view_warmer'); |
||
49 | |||
50 | $conflictNb = 0; |
||
51 | |||
52 | $views = $entityManager->getRepository('Victoire\Bundle\CoreBundle\Entity\View')->findAll(); |
||
53 | foreach ($views as $view) { |
||
54 | $widgetMaps = $contextualViewWarmer->warm($view); |
||
55 | |||
56 | foreach ($widgetMaps as $widgetMap) { |
||
57 | $positions = [WidgetMap::POSITION_BEFORE, WidgetMap::POSITION_AFTER]; |
||
58 | $children = []; |
||
59 | foreach ($positions as $position) { |
||
60 | $children[$position] = null; |
||
61 | $matchingChildren = []; |
||
62 | |||
63 | foreach ($widgetMap->getContextualChildren($position) as $_child) { |
||
64 | if (null === $_child->getSubstituteForView($view)) { |
||
65 | $children[$position] = $_child; |
||
66 | $matchingChildren[] = $_child->getId(); |
||
67 | $parent = $_child->getParent()->getId(); |
||
68 | $slot = $_child->getSlot(); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | if (!$children[$position] && $widgetMap->getReplaced()) { |
||
73 | foreach ($widgetMap->getReplaced()->getContextualChildren($position) as $_child) { |
||
74 | if (null === $_child->getSubstituteForView($view)) { |
||
75 | $matchingChildren[] = $_child->getId(); |
||
76 | $parent = $_child->getParent()->getId(); |
||
77 | $slot = $_child->getSlot(); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | if (count($matchingChildren) > 1) { |
||
83 | $conflictNb++; |
||
84 | $table->addRow([ |
||
85 | $view->getId(), |
||
86 | implode(', ', $matchingChildren), |
||
87 | $parent, |
||
88 | $slot, |
||
89 | $position, |
||
90 | ]); |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | |||
96 | if ($conflictNb > 0) { |
||
97 | $output->writeln(sprintf('<error>%s WidgetMaps conflicts found.</error>', $conflictNb)); |
||
98 | $output->writeln('<error>At least one of those WidgetMaps must have a replace_id with action "overwrite".</error>'); |
||
99 | $table->render(); |
||
100 | } else { |
||
101 | $output->writeln('<info>No conflict found.</info>'); |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 |