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

Prova::annonsera()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass Prova.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler\System;
11
12
use Tips\Egenskaper\Tick;
13
14
/**
15
 * Klass Prova.
16
 */
17
class Prova extends ReduceradKod {
18
	use Tick;
19
20
	/**
21
	 * Pröva tipsrad.
22
	 */
23 3
	public function pröva_tipsrad(string $tipsrad_012): bool {
24 3
		$ok = true;
25 3
		$this->pröva_reduktion and $ok = isset($this->reducerad_kod[$this->reducera_kodord($tipsrad_012)]);
26
27 3
		if ($ok && $this->pröva_garderingar) {
28
			$ok = $this->pröva_garderingar($tipsrad_012);
29
		}
30
31 3
		return $ok || $this->tick();
32
	}
33
34
	/**
35
	 * Pröva garderingar.
36
	 * Reducera komplexitet.
37
	 */
38
	private function pröva_garderingar(string $tipsrad_012): bool {
39
		$ok = true;
40
41
		/**
42
		 * Iterera över garderingar.
43
		 */
44
		foreach (array_keys($this->garderingar) as $index) {
45
			$ok and $this->andel_garderingar[$index] > 0 and $ok = $this->pröva_gardering(
46
				$this->garderingar[$index],
47
				$this->andel_garderingar[$index],
48
				$tipsrad_012
49
			);
50
		}
51
52
		return $ok;
53
	}
54
55
	/**
56
	 * Pröva gardering.
57
	 * @param array<int, string[]> $garderingar
58
	 */
59
	private function pröva_gardering(array $garderingar, int $andel_garderingar, string $tipsrad_012): bool {
60
		$antal_garderade = 0;
61
		foreach ($garderingar as $index => $gardering) {
62
			if ($gardering[(int) $tipsrad_012[$index]] > '') {
63
				$antal_garderade++;
64
			}
65
		}
66
		return $antal_garderade >= $andel_garderingar;
67
	}
68
69
	/**
70
	 * Annonsera modul.
71
	 */
72 3
	public function annonsera(): string {
73 3
		return $this->kod->name . ' ' . $this->attraktionsfaktor($this->attraktionsfaktor, 'system_attraktionsfaktor');
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Tips\Moduler\System\RKod.
Loading history...
74
	}
75
76
	/**
77
	 * Visa kommentar.
78
	 */
79 1
	public function kommentar(): string {
80 1
		return self::class . " {$this->kod->name} | a={$this->attraktionsfaktor}";
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Tips\Moduler\System\RKod.
Loading history...
81
	}
82
}
83