Completed
Push — main ( d5d47c...a3bc44 )
by Sebastian
02:43
created

HomeModel::recentTopics()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Seb\Home;
4
5
/**
6
 * A sample controller to show how a controller class can be implemented.
7
 */
8
class HomeModel
9
{
10
11
    /**
12
     * Show all items.
13
     *
14
     * @return object as a response object
15
     */
16 2
    public function recentTopics($topics)
17
    {
18 2
        $arrayRes = [];
19 2
        foreach (array_reverse($topics) as $q) {
20
            if (count($topics)-3 < $q->id) {
21
                array_push($arrayRes, $q->topic);
22
            }
23
        }
24 2
        return $arrayRes;
25
    }
26
27
    /**
28
     * Show all items.
29
     *
30
     * @return object as a response object
31
     */
32 2
    public function topUsers($users)
33
    {
34 2
        $arrayRes = [];
35 2
        $array = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $array is dead and can be removed.
Loading history...
36 2
        foreach ($users as $u) {
37
            $arrayRes[$u->acronym] = $u->score;
38
        }
39 2
        arsort($arrayRes);
40 2
        $array = array_slice($arrayRes, 0, 3);
41 2
        return $array;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $array returns the type array which is incompatible with the documented return type object.
Loading history...
42
    }
43
44
    /**
45
     * Show all items.
46
     *
47
     * @return object as a response object
48
     */
49 2
    public function topTags($tags, $questions)
50
    {
51 2
        $arrayRes = [];
52 2
        $tagFrequency = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $tagFrequency is dead and can be removed.
Loading history...
53 2
        foreach ($tags as $tag) {
54 2
            $tagFrequency = 0;
55 2
            foreach ($questions as $q) {
56
                if ($tag->tag == $q->tag1 || $tag->tag == $q->tag2 || $tag->tag == $q->tag3) {
57
                    $tagFrequency += 1;
58
                }
59
            }
60 2
            if ($tagFrequency == !0) {
61
                $arrayRes[$tag->tag] = $tagFrequency;
62
            }
63
        }
64 2
        arsort($arrayRes);
65 2
        $arrayRes = array_slice($arrayRes, 0, 3);
66 2
        return $arrayRes;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $arrayRes returns the type array which is incompatible with the documented return type object.
Loading history...
67
    }
68
}
69