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

GridResultatTipsresultat   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 96.43%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 71
ccs 27
cts 28
cp 0.9643
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tabellhuvud() 0 14 2
A tipsresultat() 0 44 5
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