Column   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 63
c 0
b 0
f 0
wmc 9
lcom 1
cbo 4
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setMediumWidth() 0 4 1
A setSmallWidth() 0 4 1
A setExtraSmallWidth() 0 4 1
A render() 0 5 1
A headElements() 0 7 2
A makeWidthClasses() 0 7 2
1
<?php
2
namespace rtens\domin\delivery\web\renderers\dashboard\types;
3
4
use rtens\domin\delivery\RendererRegistry;
5
use rtens\domin\delivery\web\Element;
6
use rtens\domin\delivery\web\renderers\dashboard\DashboardItem;
7
use rtens\domin\delivery\web\WebRenderer;
8
9
class Column implements DashboardItem {
10
11
    /** @var mixed */
12
    public $content;
13
14
    /** @var int[] */
15
    private $widths;
16
17
    /**
18
     * @param mixed $content
19
     * @param int $width Out of 12
20
     */
21
    public function __construct($content, $width) {
22
        $this->content = $content;
23
        $this->widths = ['lg' => $width];
0 ignored issues
show
Documentation Bug introduced by
It seems like array('lg' => $width) of type array<string,integer,{"lg":"integer"}> is incompatible with the declared type array<integer,integer> of property $widths.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
    }
25
26
    public function setMediumWidth($width) {
27
        $this->widths['md'] = $width;
28
        return $this;
29
    }
30
31
    public function setSmallWidth($width) {
32
        $this->widths['sm'] = $width;
33
        return $this;
34
    }
35
36
    public function setExtraSmallWidth($width) {
37
        $this->widths['xs'] = $width;
38
        return $this;
39
    }
40
41
    /**
42
     * @param RendererRegistry $renderers
43
     * @return Element
44
     * @throws \Exception
45
     */
46
    public function render(RendererRegistry $renderers) {
47
        return new Element('div',
48
            ['class' => $this->makeWidthClasses()],
49
            [$renderers->getRenderer($this->content)->render($this->content)]);
50
    }
51
52
    /**
53
     * @param RendererRegistry $renderers
54
     * @return \rtens\domin\delivery\web\Element[]
55
     */
56
    public function headElements(RendererRegistry $renderers) {
57
        $renderer = $renderers->getRenderer($this->content);
58
        if ($renderer instanceof WebRenderer) {
59
            return $renderer->headElements($this->content);
60
        }
61
        return [];
62
    }
63
64
    private function makeWidthClasses() {
65
        $classes = [];
66
        foreach ($this->widths as $size => $width) {
67
            $classes[] = "col-$size-$width";
68
        }
69
        return implode(' ', $classes);
70
    }
71
}