Passed
Push — main ( a92fbe...d29be2 )
by N.
05:41 queued 01:24
created

Generera   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 37
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generera_kluster() 0 7 2
A rektanglar() 0 18 5
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
	protected function rektanglar(array $koordinater): void {
21
		$rektanglar = [];
22
		foreach ($this->rektanglar as [$x_min, $y_min, $x_max, $y_max]) {
23
			$rektanglar[] = implode(',', [$x_min, $y_min, $x_max, $y_max]);
24
			foreach ($koordinater as $index => [$x, $y]) {
25
				if (in($x, $x_min, $x_max) && in($y, $y_min, $y_max)) {
26
					$this->klustrade_rader++;
27
					unset($koordinater[$index]);
28
				}
29
			}
30
		}
31
32
		$this->db_preferenser->spara_preferens('kluster.rektanglar', implode(',', $rektanglar));
33
		$this->db_preferenser->spara_preferens('kluster.area', (string) $this->area);
34
		$this->db_preferenser->spara_preferens('kluster.antal_rader', (string) $this->antal_rader);
35
		$this->db_preferenser->spara_preferens('kluster.klustrade_rader', (string) $this->klustrade_rader);
36
		$this->graf->spara_tipsgraf($this->kombinationsgraf);
37
		$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
	protected function generera_kluster($koordinater): array {
46
		$kluster = [];
47
		while (count($koordinater)) {
48
			$kluster[] = $this->kluster((array) array_pop($koordinater), $koordinater);
49
		}
50
		rsort($kluster);
51
		return $kluster;
52
	}
53
}
54