Test Failed
Push — master ( 7d2376...38002a )
by Johan
04:04
created

Histogram   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 60
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSerie() 0 49 2
1
<?php
2
3
declare(strict_types=1);
4
5
// Folder \Controllers containing classes
6
namespace Joki20\Http\Controllers;
7
8
use Joki20\Models\Pokerhighscore;
9
10
/**
11
 * Generating histogram data.
12
 */
13
14
class Histogram implements HistogramInterface
15
{
16
    private $serie = [];
17
    private $differentHands;
18
19
    /**
20
    * Get the serie.
21
    *
22
    * @return array with the serie.
23
    */
24
    public function getSerie()
25
    {
26
        $pokerhighscores = Pokerhighscore::all();
27
28
        $royalstraightflush = $pokerhighscores->sum('count_royalstraightflush');
29
        $straightflush = $pokerhighscores->sum('count_straightflush');
30
        $fourofakind = $pokerhighscores->sum('count_fourofakind');
31
        $fullhouse = $pokerhighscores->sum('count_fullhouse');
32
        $flush = $pokerhighscores->sum('count_flush');
33
        $straight = $pokerhighscores->sum('count_straight');
34
        $threeofakind = $pokerhighscores->sum('count_threeofakind');
35
        $twopairs = $pokerhighscores->sum('count_twopairs');
36
        $pair = $pokerhighscores->sum('count_pair');
37
        $nothing = $pokerhighscores->sum('count_nothing');
38
        $sumAll = (
39
            $royalstraightflush +
40
            $straightflush +
41
            $fourofakind +
42
            $fullhouse +
43
            $flush +
44
            $straight +
45
            $threeofakind +
46
            $twopairs +
47
            $pair +
48
            $nothing
49
        );
50
51
        $this->serie = [
52
            ['Royal straight flush', round(($royalstraightflush / $sumAll) * 100, 1) . '%', $royalstraightflush],
53
            ['Straight flush', round(($straightflush / $sumAll) * 100, 1) . '%', $straightflush],
54
            ['Four of a kind', round(($fourofakind / $sumAll) * 100, 1) . '%',$fourofakind],
55
            ['Full house', round(($fullhouse / $sumAll) * 100, 1) . '%',$fullhouse],
56
            ['Flush', round(($flush / $sumAll) * 100, 1) . '%',$flush],
57
            ['Straight', round(($straight / $sumAll) * 100, 1) . '%',$straight],
58
            ['Three of a kind', round(($threeofakind / $sumAll) * 100, 1) . '%',$threeofakind],
59
            ['Two pairs', round(($twopairs / $sumAll) * 100, 1) . '%',$twopairs],
60
            ['Pair', round(($pair / $sumAll) * 100, 1) . '%',$pair],
61
            ['Nothing', round(($nothing / $sumAll) * 100, 1) . '%',$nothing],
62
        ];
63
64
        $this->differentHands = count($this->serie);
65
66
        for ($hand = 0; $hand < $this->differentHands; $hand++) {
67
            // change third element with count in each above series to * output
68
            $this->serie[$hand][2] = str_repeat("*", $this->serie[$hand][2]);
69
        }
70
71
        return $this->serie;
72
    }
73
}
74