Total Complexity | 12 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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() |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get most shared topic. |
||
73 | * |
||
74 | * @return null|Topic |
||
75 | */ |
||
76 | public function getMostSharedTopic() |
||
89 | } |
||
90 | } |
||
91 |