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

Radera::radera_fil()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 10
c 0
b 0
f 0
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");
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\Distribution\DISTRIBUTION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Tips\Moduler\Distribution\GRAF was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
28
		foreach ($glob as $fil) {
29
			is_string($fil) and $this->radera_fil($fil);
30
		}
31
	}
32
33
	/**
34
	 * Radera sekvens.
35
	 */
36 1
	public function radera_sekvens(int $omgång, Speltyp $speltyp, int $sekvens): void {
37 1
		$this->odds->spel->db->radera_sekvens('distribution', $omgång, $speltyp, $sekvens);
38 1
		$filnamn = $this->odds->spel->filer->filnamn($omgång, $speltyp, $sekvens);
39
40 1
		$fil = GRAF . DISTRIBUTION . "/$filnamn.png";
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\Distribution\DISTRIBUTION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Tips\Moduler\Distribution\GRAF was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41 1
		$this->radera_fil($fil);
42
	}
43
44
	/**
45
	 * Radera fil.
46
	 */
47 1
	private function radera_fil(string $fil): void {
48 1
		$kommentar = match (file_exists($fil) && unlink($fil)) {
49
			true => ": ✅ Raderade fil",
50 1
			false => ": ❌ Kunde inte radera fil"
51 1
		};
52 1
		$this->odds->spel->db->logg->logga(self::class . "$kommentar $fil");
53
	}
54
}
55