| Conditions | 10 |
| Paths | 14 |
| Total Lines | 31 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 40 | public function getReferencableViews($views, EntityManager $em) |
||
| 41 | { |
||
| 42 | $referencableViews = []; |
||
| 43 | if (!$views instanceof \Traversable && !is_array($views)) { |
||
| 44 | $views = [$views]; |
||
| 45 | } |
||
| 46 | |||
| 47 | $businessPages = $this->findBusinessPages($views); |
||
| 48 | foreach ($views as $key => $view) { |
||
| 49 | if ($view instanceof BusinessTemplate) { |
||
| 50 | $entities = $this->businessPageHelper->getEntitiesAllowed($view, $em); |
||
| 51 | |||
| 52 | // for each business entity |
||
| 53 | foreach ($entities as $k => $entity) { |
||
| 54 | $currentPattern = clone $view; |
||
| 55 | $page = $this->businessPageBuilder->generateEntityPageFromTemplate($currentPattern, $entity, $em); |
||
| 56 | $this->businessPageBuilder->updatePageParametersByEntity($page, $entity); |
||
|
|
|||
| 57 | if (!array_key_exists(ViewReferenceHelper::generateViewReferenceId($page, $entity), $businessPages)) { |
||
| 58 | $referencableViews[] = ['view' => $page]; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } elseif ($view instanceof WebViewInterface) { |
||
| 62 | $referencableViews[$key] = ['view' => $view]; |
||
| 63 | } |
||
| 64 | if (isset($referencableViews[$key]) && $view->hasChildren()) { |
||
| 65 | $referencableViews[$key]['children'] = $this->getReferencableViews($view->getChildren(), $em); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | return $referencableViews; |
||
| 70 | } |
||
| 71 | |||
| 87 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: