Passed
Push — master ( 3bf788...763f00 )
by Jon
02:39 queued 10s
created

Article   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 150
rs 10
c 0
b 0
f 0
wmc 22

12 Methods

Rating   Name   Duplication   Size   Complexity  
A addGalleryComponent() 0 6 2
A __construct() 0 4 1
A addTextComponent() 0 6 2
A addImageComponent() 0 6 2
A getComponents() 0 3 2
A addAudioComponent() 0 6 2
A getJson() 0 8 1
A addStructureComponent() 0 6 2
A addAdComponent() 0 6 2
A addMapComponent() 0 6 2
A addVideoComponent() 0 6 2
A addSocialComponent() 0 6 2
1
<?php namespace FlatPlan;
2
3
use FlatPlan\Components\Ad;
4
use FlatPlan\Components\Audio;
5
use FlatPlan\Components\Gallery;
6
use FlatPlan\Components\Image;
7
use FlatPlan\Components\Location;
8
use FlatPlan\Components\Social;
9
use FlatPlan\Components\Structure;
10
use FlatPlan\Components\Table;
0 ignored issues
show
Bug introduced by
The type FlatPlan\Components\Table was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use FlatPlan\Components\Text;
12
use FlatPlan\Components\Video;
13
14
class Article {
15
16
    private $components = array();
17
    private $defer;
18
    private $articleId;
19
20
    public function __construct($articleId, $defer = false)
21
    {
22
        $this->articleId = $articleId;
23
        $this->defer     = $defer;
24
    }
25
26
    public function getJson()
27
    {
28
        $article = new \stdClass();
29
        $article->publisher_article_id = $this->articleId;
30
        $article->defer = $this->defer;
31
        $article->components = $this->getComponents();
32
33
        return json_encode($article);
34
    }
35
36
    public function getComponents($format = null)
37
    {
38
        return $format === 'json' ? json_encode($this->components) : $this->components;
39
    }
40
41
    /**
42
     * @param Text $component
43
     * @throws \ErrorException
44
     * @return void
45
     */
46
    public function addTextComponent($component)
47
    {
48
        if ($component instanceof Text) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Text.
Loading history...
49
            array_push($this->components, $component);
50
        } else {
51
            throw new \ErrorException('Invalid component supplied.');
52
        }
53
    }
54
55
    /**
56
     * @param Image $component
57
     * @throws \ErrorException
58
     * @return void
59
     */
60
    public function addImageComponent($component)
61
    {
62
        if ($component instanceof Image) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Image.
Loading history...
63
            array_push($this->components, $component);
64
        } else {
65
            throw new \ErrorException('Invalid component supplied.');
66
        }
67
    }
68
69
    /**
70
     * @param Gallery $component
71
     * @throws \ErrorException
72
     * @return void
73
     */
74
    public function addGalleryComponent($component)
75
    {
76
        if ($component instanceof Gallery) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Gallery.
Loading history...
77
            array_push($this->components, $component);
78
        } else {
79
            throw new \ErrorException('Invalid component supplied.');
80
        }
81
    }
82
83
    /**
84
     * @param Audio $component
85
     * @throws \ErrorException
86
     * @return void
87
     */
88
    public function addAudioComponent($component)
89
    {
90
        if ($component instanceof Audio) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Audio.
Loading history...
91
            array_push($this->components, $component);
92
        } else {
93
            throw new \ErrorException('Invalid component supplied.');
94
        }
95
    }
96
97
    /**
98
     * @param Video $component
99
     * @throws \ErrorException
100
     * @return void
101
     */
102
    public function addVideoComponent($component)
103
    {
104
        if ($component instanceof Video) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Video.
Loading history...
105
            array_push($this->components, $component);
106
        } else {
107
            throw new \ErrorException('Invalid component supplied.');
108
        }
109
    }
110
111
    /**
112
     * @param Map $component
113
     * @throws \ErrorException
114
     * @return void
115
     */
116
    public function addMapComponent($component)
117
    {
118
        if ($component instanceof Map) {
0 ignored issues
show
Bug introduced by
The type FlatPlan\Map was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
119
            array_push($this->components, $component);
120
        } else {
121
            throw new \ErrorException('Invalid component supplied.');
122
        }
123
    }
124
125
    /**
126
     * @param Social $component
127
     * @throws \ErrorException
128
     * @return void
129
     */
130
    public function addSocialComponent($component)
131
    {
132
        if ($component instanceof Social) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Social.
Loading history...
133
            array_push($this->components, $component);
134
        } else {
135
            throw new \ErrorException('Invalid component supplied.');
136
        }
137
    }
138
139
    /**
140
     * @param Ad $component
141
     * @throws \ErrorException
142
     * @return void
143
     */
144
    public function addAdComponent($component)
145
    {
146
        if ($component instanceof Ad) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Ad.
Loading history...
147
            array_push($this->components, $component);
148
        } else {
149
            throw new \ErrorException('Invalid component supplied.');
150
        }
151
    }
152
153
    /**
154
     * @param Structure $component
155
     * @throws \ErrorException
156
     * @return void
157
     */
158
    public function addStructureComponent($component)
159
    {
160
        if ($component instanceof Structure) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\Structure.
Loading history...
161
            array_push($this->components, $component);
162
        } else {
163
            throw new \ErrorException('Invalid component supplied.');
164
        }
165
    }
166
}
167