| Conditions | 11 |
| Paths | 10 |
| Total Lines | 39 |
| Code Lines | 26 |
| 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 |
||
| 42 | public function getReferencableViews($views, EntityManager $em) |
||
| 43 | { |
||
| 44 | $referencableViews = []; |
||
| 45 | if (!$views instanceof \Traversable && !is_array($views)) { |
||
| 46 | $views = [$views]; |
||
| 47 | } |
||
| 48 | |||
| 49 | $businessPages = $this->findBusinessPages($views); |
||
| 50 | foreach ($views as $view) { |
||
| 51 | if ($view instanceof BusinessTemplate) { |
||
| 52 | $entities = $this->businessPageHelper->getEntitiesAllowed($view, $em); |
||
| 53 | |||
| 54 | // for each business entity |
||
| 55 | foreach ($entities as $k => $entity) { |
||
|
|
|||
| 56 | $currentTemplate = clone $view; |
||
| 57 | $page = $this->businessPageBuilder->generateEntityPageFromTemplate($currentTemplate, $entity, $em); |
||
| 58 | $this->businessPageBuilder->updatePageParametersByEntity($page, $entity); |
||
| 59 | $entityId = null; |
||
| 60 | if (method_exists($entity, 'getId')) { |
||
| 61 | $entityId = $entity->getId(); |
||
| 62 | } elseif ($page->getBusinessEntity()->getType() === APIBusinessEntity::TYPE) { |
||
| 63 | $accessor = new PropertyAccessor(); |
||
| 64 | $entityId = $accessor->getValue($entity, $page->getBusinessEntity()->getBusinessIdentifiers()->first()->getName()); |
||
| 65 | } |
||
| 66 | if (!array_key_exists(ViewReferenceHelper::generateViewReferenceId($page, $entityId), $businessPages)) { |
||
| 67 | $referencableViews[] = ['view' => $page]; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } elseif ($view instanceof WebViewInterface) { |
||
| 71 | $referencableView = ['view' => $view]; |
||
| 72 | if ($view->getChildren()) { |
||
| 73 | $referencableView['children'] = $this->getReferencableViews($view->getChildren(), $em); |
||
| 74 | } |
||
| 75 | $referencableViews[] = $referencableView; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | return $referencableViews; |
||
| 80 | } |
||
| 81 | |||
| 97 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.