TopicCollection   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getClosedTopicsCount() 0 11 3
A getMostSharedTopic() 0 13 3
A getTopTopic() 0 13 3
A getMostActiveTopic() 0 13 3
1
<?php
2
3
namespace PhpEarth\Stats\Collection;
4
5
use PhpEarth\Stats\Collection;
6
use PhpEarth\Stats\Model\Topic;
7
8
/**
9
 * Class TopicCollection.
10
 */
11
class TopicCollection extends Collection
12
{
13
    /**
14
     * Get most active topic.
15
     *
16
     * @return null|Topic
17
     */
18
    public function getMostActiveTopic()
19
    {
20
        $commentsTopCount = 0;
21
        $mostActiveTopic = null;
22
23
        foreach ($this->data as $topic) {
24
            if ($topic->getCommentsCount() > $commentsTopCount) {
25
                $commentsTopCount = $topic->getCommentsCount();
26
                $mostActiveTopic = $topic;
27
            }
28
        }
29
30
        return $mostActiveTopic;
31
    }
32
33
    /**
34
     * Get top topic with most reactions.
35
     *
36
     * return null|Topic
37
     */
38
    public function getTopTopic()
39
    {
40
        $topCount = 0;
41
        $mostLikedTopic = null;
42
43
        foreach ($this->data as $topic) {
44
            if ($topic->getReactionsCount() > $topCount) {
45
                $topCount = $topic->getReactionsCount();
46
                $mostLikedTopic = $topic;
47
            }
48
        }
49
50
        return $mostLikedTopic;
51
    }
52
53
    /**
54
     * Get number of closed topics.
55
     *
56
     * @return int
57
     */
58
    public function getClosedTopicsCount()
59
    {
60
        $count = 0;
61
62
        foreach ($this->data as $topic) {
63
            if (!$topic->getCanComment()) {
64
                ++$count;
65
            }
66
        }
67
68
        return $count;
69
    }
70
71
    /**
72
     * Get most shared topic.
73
     *
74
     * @return null|Topic
75
     */
76
    public function getMostSharedTopic()
77
    {
78
        $topCount = 0;
79
        $mostSharedTopic = null;
80
81
        foreach ($this->data as $topic) {
82
            if ($topic->getSharesCount() > $topCount) {
83
                $topCount = $topic->getSharesCount();
84
                $mostSharedTopic = $topic;
85
            }
86
        }
87
88
        return $mostSharedTopic;
89
    }
90
}
91