ContextualViewWarmer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A warm() 0 20 4
1
<?php
2
3
namespace Victoire\Bundle\WidgetMapBundle\Warmer;
4
5
use Victoire\Bundle\CoreBundle\Entity\View;
6
use Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap;
7
8
/**
9
 * ContextualViewWarmer.
10
 *
11
 * Ref: victoire_widget_map.contextual_view_warmer
12
 */
13
class ContextualViewWarmer
14
{
15
    /**
16
     * Give a contextual View to each WidgetMap used in a View and its Templates.
17
     *
18
     * @param View      $viewToWarm
19
     * @param View|null $contextualView Used in recursive call only
20
     *
21
     * @return WidgetMap[]
22
     */
23
    public function warm(View $viewToWarm, View $contextualView = null)
24
    {
25
        $widgetMaps = [];
26
27
        if (null === $contextualView) {
28
            $contextualView = $viewToWarm;
29
        }
30
31
        foreach ($viewToWarm->getWidgetMaps() as $_widgetMap) {
32
            $_widgetMap->setContextualView($contextualView);
33
            $widgetMaps[] = $_widgetMap;
34
        }
35
36
        if ($template = $viewToWarm->getTemplate()) {
37
            $templateWidgetMaps = $this->warm($template, $contextualView);
0 ignored issues
show
Documentation introduced by
$template is of type string, but the function expects a object<Victoire\Bundle\CoreBundle\Entity\View>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
            $widgetMaps = array_merge($widgetMaps, $templateWidgetMaps);
39
        }
40
41
        return $widgetMaps;
42
    }
43
}
44