| Conditions | 5 |
| Paths | 1 |
| Total Lines | 57 |
| 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 |
||
| 37 | public function xmlAction(Request $request) |
||
| 38 | { |
||
| 39 | $em = $this->getDoctrine()->getManager(); |
||
| 40 | $homepage = $em->getRepository('VictoirePageBundle:BasePage') |
||
| 41 | ->findOneByHomepage($request->getLocale()); |
||
| 42 | |||
| 43 | /** @var ViewReference $tree */ |
||
| 44 | $tree = $this->get('victoire_view_reference.repository')->getOneReferenceByParameters( |
||
| 45 | ['viewId' => $homepage->getId()], |
||
| 46 | true, |
||
| 47 | true |
||
| 48 | ); |
||
| 49 | |||
| 50 | $ids = [$tree->getViewId()]; |
||
| 51 | |||
| 52 | $getChildrenIds = function (ViewReference $tree) use (&$getChildrenIds, $ids) { |
||
| 53 | foreach ($tree->getChildren() as $child) { |
||
| 54 | $ids[] = $child->getViewId(); |
||
| 55 | $ids = array_merge($ids, $getChildrenIds($child)); |
||
|
|
|||
| 56 | } |
||
| 57 | |||
| 58 | return $ids; |
||
| 59 | }; |
||
| 60 | |||
| 61 | $pages = $em->getRepository('VictoirePageBundle:BasePage') |
||
| 62 | ->getAll(true) |
||
| 63 | ->joinSeo() |
||
| 64 | ->filterByIds($getChildrenIds($tree)) |
||
| 65 | ->run(); |
||
| 66 | |||
| 67 | /** @var PageHelper $pageHelper */ |
||
| 68 | $pageHelper = $this->get('victoire_page.page_helper'); |
||
| 69 | $entityManager = $this->getDoctrine()->getManager(); |
||
| 70 | |||
| 71 | $getBusinessPages = function (ViewReference $tree) use (&$getBusinessPages, $pageHelper, $entityManager) { |
||
| 72 | $businessPages = []; |
||
| 73 | foreach ($tree->getChildren() as $child) { |
||
| 74 | if ($child instanceof BusinessPageReference |
||
| 75 | && $child->getViewNamespace() == 'Victoire\Bundle\BusinessPageBundle\Entity\VirtualBusinessPage') { |
||
| 76 | $entity = $entityManager->getRepository($child->getEntityNamespace())->find($child->getEntityId()); |
||
| 77 | /** @var WebViewInterface $businessPage */ |
||
| 78 | $businessPage = $pageHelper->findPageByReference($child, $entity); |
||
| 79 | $businessPage->setReference($child); |
||
| 80 | $businessPages[] = $businessPage; |
||
| 81 | } |
||
| 82 | $businessPages = array_merge($businessPages, $getBusinessPages($child)); |
||
| 83 | } |
||
| 84 | |||
| 85 | return $businessPages; |
||
| 86 | }; |
||
| 87 | |||
| 88 | $pages = array_merge($pages, $getBusinessPages($tree)); |
||
| 89 | |||
| 90 | return $this->render('VictoireSitemapBundle:Sitemap:sitemap.xml.twig', [ |
||
| 91 | 'pages' => $pages, |
||
| 92 | ]); |
||
| 93 | } |
||
| 94 | |||
| 219 |
It seems like you are assigning to a variable which was imported through a
usestatement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope