Plotta::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 5
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass Plotta.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Klasser\Generera;
11
12
use Tips\Egenskaper\Varden;
13
use Tips\Klasser\Tips;
14
use Tips\Klasser\Graf;
15
16
/**
17
 * Klass Plotta.
18
 */
19
class Plotta extends Tipsrader {
20
	use Varden;
21
22
	protected Graf $graf;
23
	protected string $bildfil = '';
24
	protected string $kombinerad_bildfil = '';
25
	protected int $antal_utvalda_rader = 0;
26
27
	/**
28
	 * Uppdatera konstruktor.
29
	 */
30 1
	public function __construct(protected Tips $tips) {
31 1
		parent::__construct($tips);
32 1
		$this->graf = new Graf();
33 1
		$this->bildfil = GENERERADE . "/{$this->tips->spel->filnamn}.png";
34 1
		$this->kombinerad_bildfil = GENERERADE . "/{$this->tips->spel->filnamn}-kombinerad.png";
35
	}
36
37
	/**
38
	 * Rendera tipsgraf.
39
	 */
40 1
	protected function plotta_genererad_tipsgraf(): void {
41 1
		$this->pixla_rader($this->graf->gul);
42 1
		$this->välj_ut_rader();
43 1
		$this->pixla_rader($this->graf->röd);
44
	}
45
46
	/**
47
	 * Pixla enskilda rader.
48
	 */
49 1
	private function pixla_rader(int $färg): void {
50 1
		foreach ($this->tips->spelade->tipsvektor as $tipsrad_012) {
51
			[$x, $y] = $this->graf->tipsgrafskoordinater($tipsrad_012);
52
			$this->graf->sätt_pixel($x, $y, $färg);
53
		}
54
	}
55
56
	/**
57
	 * Välj max_rader slumpade rader.
58
	 */
59 1
	private function välj_ut_rader(): void {
60 1
		if ($this->antal_genererade > $this->max_rader) {
61
			shuffle($this->tips->spelade->tipsvektor);
62
			$this->tips->spelade->tipsvektor = array_slice($this->tips->spelade->tipsvektor, 0, (int) $this->max_rader);
63
			sort($this->tips->spelade->tipsvektor, SORT_STRING);
64
		}
65 1
		$this->antal_utvalda_rader = count($this->tips->spelade->tipsvektor);
66
	}
67
}
68