Slide   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0
Metric Value
wmc 16
lcom 2
cbo 0
dl 0
loc 103
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A fromScheduledShow() 0 9 1
A fromEvent() 0 9 1
A playOrder() 0 4 1
A displayText() 0 19 4
A image() 0 9 2
A textStyle() 0 9 2
A url() 0 9 2
A type() 0 4 1
A index() 0 4 1
A displayIndex() 0 10 1
1
<?php
2
3
namespace WITR\Slideshow;
4
5
class Slide
6
{
7
    protected $show;
8
    protected $type;
9
    protected $playOrder;
10
    protected $index;
11
12
    public static function fromScheduledShow($show)
13
    {
14
        $slide = new Slide();
15
16
        $slide->type = 'SHOW';
17
        $slide->show = $show;
18
19
        return $slide;
20
    }
21
22
    public static function fromEvent($event)
23
    {
24
        $slide = new Slide();
25
26
        $slide->type = 'EVENT';
27
        $slide->event = $event;
0 ignored issues
show
Bug introduced by
The property event does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
29
        return $slide;
30
    }
31
32
    public function playOrder($playOrder)
33
    {
34
        $this->playOrder = $playOrder;
35
    }
36
37
    public function displayText()
38
    {
39
        if ($this->type == 'EVENT')
40
        {
41
            return;
42
        }
43
44
        if ($this->playOrder == 0)
45
        {
46
            return '&#9658;&nbsp;Now Playing';
47
        }
48
49
        if ($this->playOrder == 1)
50
        {
51
            return 'Up Next:';
52
        }
53
54
        return $this->show->getRelativeAirDate() . ' ' . $this->show->timespan();
55
    }
56
57
    public function image()
58
    {
59
        if ($this->type == 'EVENT')
60
        {
61
            return $this->event->picture;
62
        }
63
64
        return $this->show->sliderPicture();
65
    }
66
67
    public function textStyle()
68
    {
69
        if ($this->type != 'SHOW')
70
        {
71
            return;
72
        }
73
        
74
        return $this->show->sliderStyle();
75
    }
76
77
    public function url()
78
    {
79
        if ($this->type != 'EVENT')
80
        {
81
            return;
82
        }
83
84
        return $this->event->url;
85
    }
86
87
    public function type()
88
    {
89
        return $this->type;
90
    }
91
92
    public function index($index)
93
    {
94
        $this->index = $index;
95
    }
96
97
    public function displayIndex()
98
    {
99
        $display = [
100
            0 => 'first',
101
            1 => 'second',
102
            2 => 'third',
103
            3 => 'fourth',
104
        ];
105
        return $display[$this->index];
106
    }
107
}
108