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

Generera::generera_kluster()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass Generera.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler\Kluster;
11
12
/**
13
 * Klass Generera.
14
 */
15
class Generera extends Kluster {
16
	/**
17
	 * Generera rektanglar från koordinater.
18
	 * @param array<int, int[]> $koordinater
19
	 */
20 1
	protected function rektanglar(array $koordinater): void {
21 1
		$rektanglar = [];
22 1
		foreach ($this->rektanglar as [$x_min, $y_min, $x_max, $y_max]) {
23 1
			$rektanglar[] = implode(',', [$x_min, $y_min, $x_max, $y_max]);
24 1
			foreach ($koordinater as $index => [$x, $y]) {
25 1
				if (in($x, $x_min, $x_max) && in($y, $y_min, $y_max)) {
26 1
					$this->klustrade_rader++;
27 1
					unset($koordinater[$index]);
28
				}
29
			}
30
		}
31
32 1
		$this->db_preferenser->spara_preferens('kluster.rektanglar', implode(',', $rektanglar));
33 1
		$this->db_preferenser->spara_preferens('kluster.area', (string) $this->area);
34 1
		$this->db_preferenser->spara_preferens('kluster.antal_rader', (string) $this->antal_rader);
35 1
		$this->db_preferenser->spara_preferens('kluster.klustrade_rader', (string) $this->klustrade_rader);
36 1
		$this->graf->spara_tipsgraf($this->kombinationsgraf);
37 1
		$this->odds->spel->db->logg->logga(self::class . ': ✅ Fann kluster.');
38
	}
39
40
	/**
41
	 * Generera kluster från hämtade koordinater.
42
	 * @param array<int, int[]> $koordinater
43
	 * @return array<int, mixed[]>
44
	 */
45 1
	protected function generera_kluster($koordinater): array {
46 1
		$kluster = [];
47 1
		while (count($koordinater)) {
48 1
			$kluster[] = $this->kluster((array) array_pop($koordinater), $koordinater);
49
		}
50 1
		rsort($kluster);
51 1
		return $kluster;
52
	}
53
}
54