Test Failed
Push — master ( ac9ff0...806846 )
by Johan
03:01
created

Histogram   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 7.02 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 4
loc 57
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
* Card class
5
*/
6
7
declare(strict_types=1);
8
9
// Folder \Controllers containing classes
10
namespace Joki20\Http\Controllers;
11
12
use Joki20\Models\Pokerhighscore;
13
14
/**
15
 * Generating histogram data.
16
 */
17
18
class Histogram implements HistogramInterface
19
{
20
    private $serie = [];
21
    private int $differentHands;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
22
23
    /**
24
    * Get the serie.
25
    *
26
    * @return array with the serie.
27
    */
28
    public function getSerie()
29
    {
30
        $pokerhighscores = Pokerhighscore::all();
31
32
        $royalstraightflush = $pokerhighscores->sum('count_royalstraightflush');
33
        $straightflush = $pokerhighscores->sum('count_straightflush');
34
        $fourofakind = $pokerhighscores->sum('count_fourofakind');
35
        $fullhouse = $pokerhighscores->sum('count_fullhouse');
36
        $flush = $pokerhighscores->sum('count_flush');
37
        $straight = $pokerhighscores->sum('count_straight');
38
        $threeofakind = $pokerhighscores->sum('count_threeofakind');
39
        $twopairs = $pokerhighscores->sum('count_twopairs');
40
        $pair = $pokerhighscores->sum('count_pair');
41
        $nothing = $pokerhighscores->sum('count_nothing');
42
        $sumAll = (
43
            $royalstraightflush +
44
            $straightflush +
45
            $fourofakind +
46
            $fullhouse +
47
            $flush +
48
            $straight +
49
            $threeofakind +
50
            $twopairs +
51
            $pair +
52
            $nothing
53
        );
54
55
        $this->serie = [
56
            ['Royal straight flush', round(($royalstraightflush / $sumAll) * 100, 1) . '%', $royalstraightflush],
57
            ['Straight flush', round(($straightflush / $sumAll) * 100, 1) . '%', $straightflush],
58
            ['Four of a kind', round(($fourofakind / $sumAll) * 100, 1) . '%',$fourofakind],
59
            ['Full house', round(($fullhouse / $sumAll) * 100, 1) . '%',$fullhouse],
60
            ['Flush', round(($flush / $sumAll) * 100, 1) . '%',$flush],
61
            ['Straight', round(($straight / $sumAll) * 100, 1) . '%',$straight],
62
            ['Three of a kind', round(($threeofakind / $sumAll) * 100, 1) . '%',$threeofakind],
63
            ['Two pairs', round(($twopairs / $sumAll) * 100, 1) . '%',$twopairs],
64
            ['Pair', round(($pair / $sumAll) * 100, 1) . '%',$pair],
65
            ['Nothing', round(($nothing / $sumAll) * 100, 1) . '%',$nothing],
66
        ];
67
68
        $this->differentHands = count($this->serie);
69
70
        for ($hand = 0; $hand < $this->differentHands; $hand++) {
71
            // change third element with count in each above series to * output
72
            $this->serie[$hand][2] = str_repeat("*", $this->serie[$hand][2]);
73
        }
74
75
        return $this->serie;
76
    }
77
}
78