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

PGenerera::hämta_moduler()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 15
ccs 0
cts 8
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass PGenerera.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Parallellisering;
11
12
/**
13
 * Kontrollera inte nya moduler under parallell exekvering.
14
 */
15
define('GENERERA', true);
16
17
use Tips\Klasser\Preludium;
18
use Tips\Klasser\Spel;
19
use Tips\Klasser\Tips;
20
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...
21
22
require_once dirname(__FILE__) . '/../../vendor/autoload.php';
23
new Preludium();
24
25
/**
26
 * Klass PGenerera.
27
 * Generera tipsrader under parallell exekvering.
28
 */
29
final class PGenerera {
30
	use Varden;
31
32
	private Spel $spel;
33
	private Tips $tips;
34
35
	/**
36
	 * Initiera.
37
	 */
38
	public function __construct() {
39
		$this->spel = new Spel();
40
		$this->tips = new Tips($this->spel);
41
		$this->hämta_värden($this->spel->db);
42
		$this->pgenerera();
43
	}
44
45
	/**
46
	 * Parallellisera generering av tipsrader.
47
	 */
48
	private function pgenerera(): void {
49
		$vektorer = extrahera(); // hämta parametrar från querysträng.
50
		$tipsvektor = []; // håll tipsrader i ett fält.
51
52
		/**
53
		 * Definiera en rymd.
54
		 */
55
		$delrymd = [];
56
		for ($index = 4; $index >= 1; $index--) {
57
			$delrymd[$index] = ($this->trådar >= 3 ** $index) ? [$vektorer[$index - 1]] : TECKENRYMD;
0 ignored issues
show
Bug introduced by
The constant Tips\Parallellisering\TECKENRYMD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
		}
59
60
		$rymd = [...array_fill(0, MATCHANTAL - 4, TECKENRYMD), ...$delrymd];
0 ignored issues
show
Bug introduced by
The constant Tips\Parallellisering\MATCHANTAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
61
62
		/**
63
		 * Hämta moduldata.
64
		 */
65
		$moduler = $this->hämta_moduler();
66
67
		/**
68
		 * Använd generator för att generera tipsrader.
69
		 * Kontrollera mot varje modulmetod eller fortsätt.
70
		 */
71
		foreach (generera($rymd) as $tipsrad_012) {
72
			foreach ($moduler as $modul) {
73
				if (!method_exists($modul, 'pröva_tipsrad') || !$modul->pröva_tipsrad($tipsrad_012)) {
74
					continue 2;
75
				}
76
			}
77
			$tipsvektor[] = base_convert($tipsrad_012, 3, 36);
78
		}
79
80
		$this->tips->parallellisering->populera_databas(implode(',', $tipsvektor), $vektorer);
81
	}
82
83
	/**
84
	 * Hämta moduler.
85
	 * @return object[]
86
	 */
87
	private function hämta_moduler(): array {
88
		$moduler = [];
89
90
		/**
91
		 * Ladda moduler med en metod för att pröva tipsrader.
92
		 */
93
		foreach ($this->tips->moduler->skarpa_moduler as $modul) {
94
			$klass = "\\Tips\\Moduler\\$modul";
95
			$ny_modul = new $klass($this->tips->utdelning, $this->tips->odds, $this->tips->streck, $this->tips->matcher);
96
			if (method_exists($ny_modul, 'pröva_tipsrad')) {
97
				$moduler[] = $ny_modul;
98
			}
99
		}
100
101
		return $moduler;
102
	}
103
}
104
105
new PGenerera();
106