Passed
Push — main ( e5e48e...78d8c3 )
by N.
05:08
created

Prediktionsdata::prediktionsdata()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 3
dl 0
loc 13
ccs 12
cts 12
cp 1
crap 2
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass Prediktionsdata.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Klasser\Prediktioner;
11
12
use PDO;
13
14
/**
15
 * Klass Prediktionsdata.
16
 */
17
class Prediktionsdata extends Sannolikheter {
18
	/**
19
	 * Hämta prediktioner för alla omgångar.
20
	 * @return array<string, array<int, float[]>>
21
	 */
22 1
	public function prediktionsdata(string $tabell, int $u13_min = 0, int $u13_max = MAXVINST): array {
23 1
		$prediktionsdata = [];
24 1
		$pred = implode(', ', array_map(fn (int $i): string => "`p$i`", PLATT_ODDSMATRIS)); // `p1`, `p2`, …, `p39`
25 1
		$sats = $this->spel->db->instans->prepare("SELECT $pred, `omgång` FROM `$tabell` NATURAL JOIN `utdelning`
26 1
			WHERE `$tabell`.`komplett` AND `tipsrad_012` AND `u13` BETWEEN :u13_min AND :u13_max ORDER BY `omgång`");
27 1
		$sats->bindValue(':u13_min', $u13_min, PDO::PARAM_INT);
28 1
		$sats->bindValue(':u13_max', $u13_max, PDO::PARAM_INT);
29 1
		$sats->execute();
30 1
		foreach ($sats->fetchAll(PDO::FETCH_ASSOC) as $rad) {
31 1
			$prediktionsdata[(string) $rad['omgång']] =
32 1
				array_chunk(array_map(fn (int $n): float => $rad["p$n"], PLATT_ODDSMATRIS), 3);
33
		}
34 1
		return $prediktionsdata;
35
	}
36
}
37