Sorteraren   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 37
c 0
b 0
f 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sorteraFragorOchSvar() 0 27 4
1
<?php
2
3
namespace KW\Inlagg;
4
5
class Sorteraren
6
{
7
8
    public function __construct($di)
9
    {
10
        $this->di = $di;
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
11
        $this->hamtaren = new Hamtaren($this->di);
0 ignored issues
show
Bug Best Practice introduced by
The property hamtaren does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
12
    }
13
14
    //samla fråga kommentarer, svar kommentarer i en tabell
15
    public function sorteraFragorOchSvar($slug, $sortsv, $sortko)
16
    {
17
        $res = [];
18
19
        $fragan = $this->hamtaren->hamtaEnFraga($slug);
20
21
        array_push($res, $fragan);
22
23
        //kommentarer till frågan
24
        $ktf = $this->hamtaren->hamtaKommentarer($res[0]->id, $sortko);
25
        foreach ($ktf as $value) {
26
            array_push($res, $value);
27
        }
28
29
        //olika svar och kommentarer till Dessa
30
        $svaren = $this->hamtaren->hamtaSvar($res[0]->id, $sortsv);
31
32
        //loopa i svaren och adda alla eventuella kommentarer
33
        foreach ($svaren as $value) {
34
            array_push($res, $value);//lägger till själva svaren ett och ett
35
            $kommentarerna = $this->hamtaren->hamtaKommentarer($value->id, $sortko);
36
            foreach ($kommentarerna as $komvalue) {
37
                array_push($res, $komvalue);//lägger till kommentarer ett och ett
38
            }
39
        }
40
41
        return $res;
42
    }
43
}
44