Passed
Push — main ( e5e48e...78d8c3 )
by N.
05:08
created

MatchdataAjax::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass MatchdataAjax.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Ajax;
11
12
use Tips\Klasser\Preludium;
13
use Tips\Klasser\Spel;
14
use Tips\Klasser\Speltyp;
15
use Tips\Klasser\Tips;
16
use Tips\Klasser\Sekvenser;
17
use Tips\Egenskaper\Ajax;
18
19
/**
20
 * Ajaxanrop ligger utanför ordinarie ordning.
21
 */
22 1
require_once dirname(__FILE__) . '/../../vendor/autoload.php';
23 1
new Preludium();
24
25
/**
26
 * Klass MatchdataAjax.
27
 * @SuppressWarnings("PHPMD.UnusedPrivateMethod", "PHPMD.UnusedPrivateField")
28
 */
29
final class MatchdataAjax extends Nedbrytning {
30
	use Ajax;
0 ignored issues
show
Bug introduced by
The trait Tips\Egenskaper\Ajax requires the property $logg which is not provided by Tips\Ajax\MatchdataAjax.
Loading history...
31
32
	private Spel $spel;
33
	private Tips $tips;
34
35
	/**
36
	 * Inititiera.
37
	 */
38 1
	public function __construct() {
39 1
		$this->spel = new Spel();
40 1
		$this->tips = new Tips($this->spel);
41 1
		$this->förgrena();
42
	}
43
44
	/**
45
	 * Spara matchdata.
46
	 * js/funktioner.js: spara_matchdata
47
	 */
48 1
	private function spara_matchdata(): void {
0 ignored issues
show
Unused Code introduced by
The method spara_matchdata() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
49 1
		$_REQUEST['spara_matchdata'] = (string) filter_var($_REQUEST['spara_matchdata'], FILTER_SANITIZE_URL);
50 1
		parse_str($_REQUEST['spara_matchdata'], $matchdata);
51
52
		/**
53
		 * Omgångsdata.
54
		 */
55 1
		$this->tips->spel->omgång = (int) $matchdata['omgång'];
56 1
		$this->tips->utdelning->år = (int) $matchdata['år'];
57 1
		$this->tips->utdelning->vecka = (int) $matchdata['vecka'];
58
59 1
		$this->tips->utdelning->tipsrad = (string) filter_var($matchdata['tipsrad'], FILTER_SANITIZE_SPECIAL_CHARS);
60 1
		$this->tips->utdelning->tipsrad_012 = symboler_till_siffror($this->tips->utdelning->tipsrad);
61
62
		/**
63
		 * Utdelning och antal vinnare i respektive vinstkategori.
64
		 */
65 1
		foreach (range(0, 2) as $i) {
66 1
			$this->tips->utdelning->utdelning[$i] = (int) filter_var($matchdata['utdelning'][$i], FILTER_VALIDATE_INT);
67 1
			$this->tips->utdelning->vinnare[$i] = (int) filter_var($matchdata['vinnare'][$i], FILTER_VALIDATE_INT);
68
		}
69
70
		/**
71
		 * Matchstatus.
72
		 */
73 1
		$this->tips->matcher->matchstatus = array_map(fn ($i): int =>
74 1
			(int) filter_var($matchdata['matchstatus'][$i], FILTER_VALIDATE_INT), range(0, MATCHANTAL - 1));
75
76
		/**
77
		 * Odds och streck.
78
		 */
79 1
		$this->bryt_ned_prediktioner($matchdata['odds'], $this->tips->odds->prediktioner);
80 1
		$this->bryt_ned_prediktioner($matchdata['streck'], $this->tips->streck->prediktioner);
81
82 1
		$this->tips->matcher->spelstopp = (string) filter_var($matchdata['spelstopp'], FILTER_SANITIZE_SPECIAL_CHARS);
83
84
		/**
85
		 * Matcher.
86
		 */
87 1
		$this->bryt_ned_vektor($matchdata['lag'], $this->tips->matcher->match);
88 1
		$this->bryt_ned_vektor($matchdata['resultat'], $this->tips->matcher->resultat);
89
90 1
		$this->tips->spara_tips();
91 1
		(new Sekvenser($this->tips->spel))->traversera_sekvenser();
92
93 1
		$this->spel->db->spara_backup();
94
	}
95
}
96
97
new MatchdataAjax();
98