Passed
Push — main ( 38376b...7b37bf )
by N.
03:15
created

Radera   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 35
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A radera_omgång() 0 8 3
A radera_fil() 0 6 2
A radera_sekvens() 0 6 1
1
<?php
2
3
/**
4
 * Klass Radera.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler\Distribution;
11
12
use Tips\Klasser\Speltyp;
13
use Tips\Moduler\DistributionGenerera\Generera;
14
15
/**
16
 * Klass Radera.
17
 */
18
class Radera extends Hamta {
19
	/**
20
	 * Radera omgång.
21
	 */
22
	public function radera_omgång(int $omgång, Speltyp $speltyp): void {
23
		$this->odds->spel->db->radera_omgång('distribution', $omgång, $speltyp);
24
		$this->odds->spel->db->logg->logga(self::class . ": ✅ Raderade distribution. ({$this->odds->spel->omgång})");
25
26
		$mönster = "*-t{$speltyp->value}-o$omgång-*";
27
		$glob = (array) glob(GRAF . DISTRIBUTION . "/$mönster.png");
28
		foreach ($glob as $fil) {
29
			is_string($fil) and $this->radera_fil($fil);
30
		}
31
	}
32
33
	/**
34
	 * Radera sekvens.
35
	 */
36
	public function radera_sekvens(int $omgång, Speltyp $speltyp, int $sekvens): void {
37
		$this->odds->spel->db->radera_sekvens('distribution', $omgång, $speltyp, $sekvens);
38
		$filnamn = $this->odds->spel->filer->filnamn($omgång, $speltyp, $sekvens);
39
40
		$fil = GRAF . DISTRIBUTION . "/$filnamn.png";
41
		$this->radera_fil($fil);
42
	}
43
44
	/**
45
	 * Radera fil.
46
	 */
47
	private function radera_fil(string $fil): void {
48
		$kommentar = match (file_exists($fil) && unlink($fil)) {
49
			true => ": ✅ Raderade fil",
50
			false => ": ❌ Kunde inte radera fil"
51
		};
52
		$this->odds->spel->db->logg->logga(self::class . "$kommentar $fil");
53
	}
54
}
55