HamtaSpikar   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 90.63%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 34
dl 0
loc 76
ccs 29
cts 32
cp 0.9063
rs 10
c 4
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A hämta_spikar() 0 53 5
1
<?php
2
3
/**
4
 * Klass HamtaSpikar.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler\TT;
11
12
use Tips\Moduler\TT\Konstanter;
13
14
/**
15
 * Klass HamtaSpikar.
16
 */
17
class HamtaSpikar extends HamtaData {
18
	use Konstanter;
19
20
	/**
21
	 * @var int[] $antal_spikar
22
	 */
23
	public array $antal_spikar;
24
	/**
25
	 * @var int[] $andel_spikar
26
	 */
27
	public array $andel_spikar;
28
	/**
29
	 * @var array<int, array<int, array<int, string>>> $spikar
30
	 */
31
	public array $spikar;
32
	/**
33
	 * @var array<int, string[]> $reduktion
34
	 */
35
	public array $reduktion;
36
37
	/**
38
	 * Hämta spikar.
39
	 */
40 20
	protected function hämta_spikar(): void {
41 20
		$this->spikar = array_fill(
42 20
			0,
43 20
			self::TT_MAX_SPIKFÄLT,
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\TT\HamtaSpikar::TT_MAX_SPIKFÄLT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44 20
			array_fill(0, self::TT_MATCHANTAL, TOM_STRÄNGVEKTOR)
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\TT\HamtaSpikar::TT_MATCHANTAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45 20
		);
46 20
		$spikar = $this->db_preferenser->hämta_preferens("topptips.spikar");
47
48
		/**
49
		 * Spara tom struktur om spikar inte redan sparade.
50
		 * Packa annars upp spikar i fält och ersätt tom struktur.
51
		 */
52
		match ($spikar) {
53 20
			'' => $this->db_preferenser->spara_preferens(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->db_preferenser->s...ay(), $this->spikar)))) targeting Tips\Klasser\DBPreferens...nOut::spara_preferens() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
54 20
				"topptips.spikar",
55 20
				implode(',', array_merge([], ...array_merge([], ...$this->spikar)))
56 20
			),
57 20
			default => $this->spikar = array_chunk(
58 20
				array_chunk(explode(',', $spikar), 3),
59 20
				self::TT_MATCHANTAL
60 20
			)
61
		};
62
63 20
		$this->antal_spikar = array_fill(0, self::TT_MAX_SPIKFÄLT, 0);
64 20
		$this->andel_spikar = $this->antal_spikar;
65 20
		$andel_spikar = $this->db_preferenser->hämta_preferens("topptips.andel_spikar");
66
67 20
		if ($andel_spikar !== '') {
68 20
			$this->andel_spikar = array_map('intval', explode(',', $andel_spikar));
69
		}
70
71 20
		foreach ($this->spikar as $index => $gardering) {
72 20
			foreach ($gardering as $match) {
73
				// Halvgardering = en ruta tom.
74 20
				if (count(array_unique($match)) > 1) {
75 20
					$this->antal_spikar[$index]++;
76
				}
77
			}
78
79 20
			$this->antal_spikar[$index] = max($this->antal_spikar[$index], $this->andel_spikar[$index]);
80
		}
81
82 20
		$this->reduktion = array_fill(0, self::TT_MATCHANTAL, TOM_STRÄNGVEKTOR);
83 20
		$reduktion = $this->db_preferenser->hämta_preferens("topptips.reduktion");
84
85
		/**
86
		 * Finns reduktion i preferenser är allt väl.
87
		 */
88 20
		match ($reduktion !== '') {
89 20
			true => $this->reduktion = array_chunk(explode(',', $reduktion), 3),
90
			false => $this->db_preferenser->spara_preferens(
91
				"topptips.reduktion",
92
				implode(',', array_merge([], ...$this->reduktion))
93
			)
94 20
		};
95
	}
96
}
97