Passed
Push — main ( d29be2...38376b )
by N.
03:16
created

GridResultatTipsresultat::tipsresultat()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 44
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 5.0026

Importance

Changes 0
Metric Value
cc 5
eloc 20
nc 6
nop 0
dl 0
loc 44
ccs 20
cts 21
cp 0.9524
crap 5.0026
rs 9.2888
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass GridResultatTipsresultat.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Klasser\Omgang;
11
12
/**
13
 * Klass GridResultatTipsresultat.
14
 */
15
class GridResultatTipsresultat extends GridResultatVinstrader {
16
	/**
17
	 * Visa tipsresultat.
18
	 * Antal rätt per vinstkategori, förväntat resultat med mera.
19
	 */
20 1
	protected function tipsresultat(): string {
21 1
		if (!$this->spelad) {
22
			return '';
23
		}
24
25
		/**
26
		 * Förväntat resultat, slumpmässig fördelning.
27
		 * Exempel, 100 spelade rader:
28
		 * 5 r: 21 %
29
		 * 6 r: 14 %
30
		 * 7 r: 7 %
31
		 * 8 r: 2.6 %
32
		 * 9 r: 0.7 %
33
		 * 10 r: 0.14 %
34
		 * 11 r: 0.02 %
35
		 */
36 1
		$förväntat_antal = array_map(
37 1
			fn (float $n): float => $n / (3 ** MATCHANTAL / $this->antal_rader),
0 ignored issues
show
Bug introduced by
The constant Tips\Klasser\Omgang\MATCHANTAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38 1
			array_reverse(UTFALL_PER_HALVGARDERINGAR[MATCHANTAL])
0 ignored issues
show
Bug introduced by
The constant Tips\Klasser\Omgang\UTFALL_PER_HALVGARDERINGAR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Tips\Klasser\Omgang\MATCHANTAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39 1
		);
40
41 1
		$tipsresultat = $this->tabellhuvud();
42
43 1
		for ($i = MATCHANTAL; $i >= 0; $i--) {
44 1
			$förväntade = number_format($förväntat_antal[$i], 4);
45 1
			$faktor = number_format($this->rättvektor[$i] / $förväntat_antal[$i], 2, '.', '');
46 1
			$stil = ($i >= 10 && $this->rättvektor[$i] > 0) ? " class=\"vinst$i\"" : '';
47
48
			/**
49
			 * Tabellrad.
50
			 */
51 1
			$tipsresultat .= <<< EOT
52 1
							<tr class="höger">
53 1
								<td>$i</td>
54 1
								<td$stil>{$this->rättvektor[$i]}</td>
55 1
								<td>$förväntade</td>
56 1
								<td>$faktor</td>
57
							</tr>
58
59 1
EOT;
60
		}
61
62 1
		return <<< EOT
63 1
$tipsresultat						</table>
64
65 1
EOT;
66
	}
67
68
	/**
69
	 * Tabellhuvud.
70
	 * Dela upp rutiner.
71
	 */
72 1
	private function tabellhuvud(): string {
73 1
		$vinst_netto = $this->vinst - $this->antal_rader;
74 1
		$stil = $vinst_netto > 0 ? ['<span class="nettovinst">', '</span>'] : ['', ''];
75
76
		/**
77
		 * Skicka tillbaka.
78
		 */
79 1
		return <<< EOT
80 1
						<p>Vinst: {$stil[0]}$vinst_netto{$stil[1]} ({$this->vinst}) kr</p>
81
						<table class="ram">
82
							<tr class="match">
83
								<th>Rätt</th>
84
								<th>Antal</th>
85 1
								<th>E[r|{$this->antal_rader}]</th>
86
								<th>Faktor</th>
87
							</tr>
88
89 1
EOT;
90
	}
91
}
92