Completed
Push — 1.4 ( 6a61c0...59673b )
by Paweł
15s
created

ArticleStatistics   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Importance

Changes 0
Metric Value
wmc 15
lcom 3
cbo 3
dl 0
loc 140
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getEvents() 0 4 1
A setEvents() 0 4 1
A addEvent() 0 4 1
A __construct() 0 4 1
A getId() 0 4 1
A getArticle() 0 4 1
A setArticle() 0 4 1
A getImpressionsNumber() 0 8 2
A setImpressionsNumber() 0 4 1
A getPageViewsNumber() 0 8 2
A setPageViewsNumber() 0 4 1
A getInternalClickRate() 0 4 1
A setInternalClickRate() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Analytics Bundle.
5
 *
6
 * Copyright 2017 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2017 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\AnalyticsBundle\Model;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use SWP\Bundle\ContentBundle\Model\ArticleInterface;
20
use SWP\Component\Common\Model\TimestampableInterface;
21
use SWP\Component\Common\Model\TimestampableTrait;
22
23
/**
24
 * Class ArticleStatistics.
25
 */
26
class ArticleStatistics implements ArticleStatisticsInterface, TimestampableInterface
27
{
28
    use TimestampableTrait;
29
30
    /**
31
     * @var int
32
     */
33
    protected $id;
34
35
    /**
36
     * @var ArticleInterface
37
     */
38
    protected $article;
39
40
    /**
41
     * @var int
42
     */
43
    protected $impressionsNumber = 0;
44
45
    /**
46
     * @var int
47
     */
48
    protected $pageViewsNumber = 0;
49
50
    /**
51
     * @var float
52
     */
53
    protected $internalClickRate = 0;
54
55
    /**
56
     * @var Collection
57
     */
58
    protected $events;
59
60
    /**
61
     * ArticleStatistics constructor.
62
     */
63
    public function __construct()
64
    {
65
        $this->events = new ArrayCollection();
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getId()
72
    {
73
        return $this->id;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getArticle(): ArticleInterface
80
    {
81
        return $this->article;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function setArticle(ArticleInterface $article): void
88
    {
89
        $this->article = $article;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function getImpressionsNumber(): int
96
    {
97
        if (null === $this->impressionsNumber) {
98
            return 0;
99
        }
100
101
        return $this->impressionsNumber;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function setImpressionsNumber(int $impressionsNumber): void
108
    {
109
        $this->impressionsNumber = $impressionsNumber;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function getPageViewsNumber(): int
116
    {
117
        if (null === $this->pageViewsNumber) {
118
            return 0;
119
        }
120
121
        return $this->pageViewsNumber;
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    public function setPageViewsNumber(int $pageViewsNumber): void
128
    {
129
        $this->pageViewsNumber = $pageViewsNumber;
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function getEvents(): Collection
136
    {
137
        return $this->events;
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143
    public function setEvents(Collection $events): void
144
    {
145
        $this->events = $events;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151
    public function addEvent(ArticleEventInterface $articleEvent): void
152
    {
153
        $this->events->add($articleEvent);
154
    }
155
156
    public function getInternalClickRate(): float
157
    {
158
        return $this->internalClickRate;
159
    }
160
161
    public function setInternalClickRate(float $internalClickRate): void
162
    {
163
        $this->internalClickRate = $internalClickRate;
164
    }
165
}
166