Passed
Push — master ( f80586...f4cd30 )
by Jon
07:56 queued 12s
created

Article   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getComponents() 0 3 2
A getJson() 0 8 1
A addComponent() 0 6 2
1
<?php namespace FlatPlan;
2
3
use FlatPlan\Components\AbstractComponent;
4
use FlatPlan\Components\Ad;
5
use FlatPlan\Components\Audio;
6
use FlatPlan\Components\Gallery;
7
use FlatPlan\Components\Image;
8
use FlatPlan\Components\Location;
9
use FlatPlan\Components\Social;
10
use FlatPlan\Components\Structure;
11
use FlatPlan\Components\Table;
12
use FlatPlan\Components\Text;
13
use FlatPlan\Components\Video;
14
15
class Article {
16
17
    private $components = array();
18
    private $defer;
19
    private $articleId;
20
21
    public function __construct($articleId, $defer = false)
22
    {
23
        $this->articleId = $articleId;
24
        $this->defer     = $defer;
25
    }
26
27
    public function getJson()
28
    {
29
        $article = new \stdClass();
30
        $article->publisher_article_id = $this->articleId;
31
        $article->defer = $this->defer;
32
        $article->components = $this->getComponents();
33
34
        return json_encode($article);
35
    }
36
37
    public function getComponents($format = null)
38
    {
39
        return $format === 'json' ? json_encode($this->components) : $this->components;
40
    }
41
42
    /**
43
     * @param AbstractComponent $component
44
     * @throws \ErrorException
45
     * @return void
46
     */
47
    public function addComponent($component)
48
    {
49
        if ($component instanceof AbstractComponent) {
0 ignored issues
show
introduced by
$component is always a sub-type of FlatPlan\Components\AbstractComponent.
Loading history...
50
            array_push($this->components, $component);
51
        } else {
52
            throw new \ErrorException('Invalid component supplied.');
53
        }
54
    }
55
}
56