Gallery   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
c 2
b 0
f 0
dl 0
loc 54
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setComponents() 0 12 5
A __construct() 0 3 1
A getComponent() 0 11 2
A getComponents() 0 11 2
1
<?php namespace FlatPlan\Components;
2
3
use FlatPlan\Components\Image;
4
5
class Gallery extends AbstractComponent {
6
7
    protected $components = array();
8
9
    protected $roles = ['gallery', 'mosaic'];
10
11
    /**
12
     * @param string $role
13
     * @return void
14
     */
15
    public function __construct($role)
16
    {
17
        $this->setRole($role);
18
    }
19
20
    public function setComponents($components)
21
    {
22
        if (is_array($components)) {
23
            foreach ($components as $component) {
24
                if ($component instanceof Image) {
25
                    $component->updateStyles($this->role);
26
                    array_push($this->components, $component);
27
                }
28
            }
29
        } else if ($components instanceof Image) {
30
            $components->updateStyles($this->role);
31
            array_push($this->components, $components);
32
        }
33
    }
34
35
    private function getComponents()
36
    {
37
        $componentList = array();
38
        foreach ($this->components as $subComponent) {
39
            $imageComponent = $subComponent->getComponent();
40
            $image          = new \stdClass();
41
            $image->URL     = $imageComponent->URL;
42
            $image->caption = $imageComponent->caption;
43
            array_push($componentList, $image);
44
        }
45
        return $componentList;
46
    }
47
48
    public function getComponent()
49
    {
50
        $component = new \stdClass();
51
        $component->role   = $this->getRole();
52
        $component->items  = $this->getComponents();
53
        $component->layout = $this->getLayout();
54
        $component->style  = $this->getStyle();
55
        if (!is_null($this->behaviour)) {
56
            $component->behaviour = $this->getBehaviour();
57
        }
58
        return $component;
59
    }
60
}
61