Passed
Push — main ( 40d4d0...b1f2dd )
by N.
05:04
created

Spara   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 86.36%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 42
ccs 19
cts 22
cp 0.8636
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A spara_genererade_tipsrader() 0 19 1
A kommentar() 0 9 3
1
<?php
2
3
/**
4
 * Klass Spara.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Klasser\Generera;
11
12
use PDO;
13
use Tips\Egenskaper\Varden;
0 ignored issues
show
Bug introduced by
The type Tips\Egenskaper\Varden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * Klass Spara.
17
 */
18
class Spara extends Plotta {
19
	use Varden;
20
21
	/**
22
	 * Spara tipsrader till databas.
23
	 * Raderna sparas i temporär databas innan de godkänns som spel.
24
	 */
25 1
	protected function spara_genererade_tipsrader(): void {
26 1
		$sats = $this->tips->spel->db->temp->prepare("REPLACE INTO `genererat`
27
			(`omgång`, `speltyp`, `sekvens`, `tipsrader`, `datum`, `genererade`, `valda`, `kommentar`)
28 1
			VALUES (:omgang, :speltyp, :sekvens, :tipsrader, :datum, :genererade, :valda, :kommentar)");
29 1
		$sats->bindValue(':omgang', $this->tips->spel->omgång, PDO::PARAM_INT);
30 1
		$sats->bindValue(':speltyp', $this->tips->spel->speltyp->value, PDO::PARAM_INT);
31 1
		$sats->bindValue(':sekvens', $this->tips->spel->sekvens, PDO::PARAM_INT);
32 1
		$sats->bindValue(':tipsrader', implode(',', bas3till36($this->tips->spelade->tipsvektor)), PDO::PARAM_STR);
33 1
		$sats->bindValue(':datum', date("Y-m-d H:i:s"), PDO::PARAM_STR);
34 1
		$sats->bindValue(':genererade', $this->antal_genererade, PDO::PARAM_INT);
35 1
		$sats->bindValue(':valda', $this->antal_utvalda_rader, PDO::PARAM_INT);
36 1
		$sats->bindValue(':kommentar', $this->kommentar(), PDO::PARAM_STR);
37
38 1
		$kommentar = match ($sats->execute()) {
39 1
			true => ": ✅ Sparade tipsrader.",
40
			false => ": ❌ Kunde inte spara tipsrader."
41 1
		};
42
43 1
		$this->tips->spel->db->logg->logga(self::class . "$kommentar ({$this->tips->spel->omgång})");
44
	}
45
46
	/**
47
	 * Hämta kommentar från modul.
48
	 * Informationen visas i ruta för strategi.
49
	 * Visar antal rader, nyttjat vinstintervall, samt aktiva moduler med parametrar.
50
	 */
51 1
	private function kommentar(): string {
52 1
		$kommentar = ["r={$this->max_rader}, [{$this->u13_min}–{$this->u13_max}]"];
53 1
		foreach ($this->tips->moduler->m_moduler as $modul) {
54
			if (method_exists($modul, 'kommentar')) {
55
				$kommentar[] = $modul->kommentar();
56
			}
57
		}
58
59 1
		return implode("\n", $kommentar);
60
	}
61
}
62