Question   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
c 1
b 0
f 0
dl 0
loc 101
ccs 0
cts 38
cp 0
rs 10
wmc 17

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLastThree() 0 7 2
A getMostTags() 0 18 5
B getMostActive() 0 40 10
1
<?php
2
3
namespace Aiur18\Question;
4
5
use Anax\DatabaseActiveRecord\ActiveRecordModel;
6
7
/**
8
 * A database driven model using the Active Record design pattern.
9
 */
10
class Question extends ActiveRecordModel
11
{
12
    /**
13
     * @var string $tableName name of the database table.
14
     */
15
    protected $tableName = "Question";
16
17
18
19
    /** variables
20
     */
21
    public $id;
22
    public $subject;
23
    public $question;
24
    public $facebook;
25
    public $youtube;
26
    public $twitter;
27
    public $user_id;
28
29
30
      /**
31
     * Method
32
     */
33
    public function getLastThree($obj)
34
    {
35
        $array = array();
36
        foreach ($obj as $key => $value) {
37
            array_push($array, $value);
38
        }
39
        return array_slice($array, -3, 3, true);
40
    }
41
42
43
44
      /**
45
     * Method
46
     */
47
    public function getMostTags($obj)
48
    {
49
        $facebook = 0;
50
        $youtube = 0;
51
        $twitter = 0;
52
        foreach ($obj as $key => $value) {
53
            if ($value->facebook) {
54
                $facebook++;
55
            }
56
            if ($value->youtube) {
57
                $youtube++;
58
            }
59
            if ($value->twitter) {
60
                $twitter++;
61
            }
62
        }
63
        $arr = ["facebook" => $facebook, "youtube" => $youtube, "twitter" => $twitter];
64
        return array_keys($arr, max($arr));
65
    }
66
67
68
      /**
69
     * Method
70
     */
71
    public function getMostActive($questions, $answers, $comments)
72
    {
73
        $array = array();
74
        foreach ($questions as $value) {
75
            if ($value->user_id != null) {
76
                if (array_key_exists($value->user_id, $array)) {
77
                    $array[$value->user_id]++;
78
                } else {
79
                    $array[$value->user_id] = 1;
80
                }
81
            }
82
        }
83
84
        foreach ($answers as $value) {
85
            if ($value->user_id != null) {
86
                if (array_key_exists($value->user_id, $array)) {
87
                    $array[$value->user_id]++;
88
                } else {
89
                    // $tempArray = array();
90
                    // $tempArray = array($value->user_id => 1);
91
                    $array[$value->user_id] = 1;
92
                }
93
            }
94
        }
95
96
        foreach ($comments as $value) {
97
            if ($value->user_id != null) {
98
                if (array_key_exists($value->user_id, $array)) {
99
                    $array[$value->user_id]++;
100
                } else {
101
                    // $tempArray = array();
102
                    // $tempArray = array($value->user_id => 1);
103
                    $array[$value->user_id] = 1;
104
                }
105
            }
106
        }
107
        $value = max($array);
108
        $key = array_search($value, $array);
109
110
        return $key;
111
    }
112
}
113