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

Preferenser::visa_preferenser()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 16
nc 8
nop 0
dl 0
loc 30
ccs 16
cts 16
cp 1
crap 4
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass Preferenser.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Klasser;
11
12
use SQLite3;
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
use Tips\Egenskaper\Eka;
15
16
/**
17
 * Klass Preferenser.
18
 * Flik med diverse inställningar.
19
 */
20
final class Preferenser {
21
	use Varden;
22
	use Eka;
23
24
	/**
25
	 * Initiera.
26
	 */
27 1
	public function __construct(public Databas $db) {
28 1
		$this->hämta_värden($this->db);
29 1
		$this->trådar = in_array($this->trådar, TRÅDMÄNGD, true) ? $this->trådar : 9;
0 ignored issues
show
Bug Best Practice introduced by
The property trådar does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The constant Tips\Klasser\TRÅDMÄNGD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30 1
		$this->visa_preferenser();
31
	}
32
33
	/**
34
	 * Visa preferenser.
35
	 */
36 1
	private function visa_preferenser(): void {
37 1
		$databaser = '';
38
39
		/**
40
		 * Info om databaser.
41
		 */
42 1
		$glob = glob(DB . '/*.db');
0 ignored issues
show
Bug introduced by
The constant Tips\Klasser\DB was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
43 1
		$glob = ($glob !== false && $glob !== []) ? $glob : [];
44 1
		foreach ($glob as $fil) {
45 1
			$databaser .= t(8, "<em>{$this->eka($fil)}</em> ({$this->eka(intval(filesize($fil)) / 1024 . ' kB')})<br>");
46
		}
47
48 1
		echo <<< EOT
49 1
			<div id="flikar-preferenser">
50 1
{$this->övre_grid()}
51
				<div class="generell-nedre-grid">
52
					<div class="generell-nedre">
53
						<div style="color: #444; font-size: 90%;">
54
							<p>
55 1
								Tips version {$this->eka(VERSION)} {$this->eka(VERSIONSDATUM)}<br>
0 ignored issues
show
Bug introduced by
The constant Tips\Klasser\VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Tips\Klasser\VERSIONSDATUM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
56 1
								{$this->eka(trim((string) shell_exec('httpd -version | cut -d " " -f3')))}<br>
57 1
								PHP {$this->eka(phpversion() . ' | ' . $this->php)}<br>
58 1
								SQLite3 {$this->eka(SQLite3::version()['versionString'])}<br>
59 1
								SAPI {$this->eka(PHP_SAPI . ' | ' . $this->fcgi)}</p>
60
						</div>
61
						<hr class="kort">
62
						<div>
63 1
							<p>Databas: {$this->eka($this->db->integritetskontroll())}</p>
64
							<p>
65 1
$databaser							</p>
66
						</div>
67
					</div> <!-- generell-nedre -->
68
				</div> <!-- generell-nedre-grid -->
69
			</div> <!-- flikar-preferenser -->
70
71 1
EOT;
72
	}
73
74
	/**
75
	 * Övre grid i flik med preferenser.
76
	 */
77 1
	private function övre_grid(): string {
78
		/**
79
		 * Parallella trådar.
80
		 */
81 1
		$trådar = array_fill_keys(TRÅDMÄNGD, '');
0 ignored issues
show
Bug introduced by
The constant Tips\Klasser\TRÅDMÄNGD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
82 1
		$trådar[$this->trådar] = ' checked="checked"';
83
84
		/**
85
		 * Eka ut.
86
		 */
87 1
		return <<< EOT
88 1
				<div class="generell-övre-grid">
89
					<div class="generell-övre">
90
						<h1>Preferenser</h1>
91
						<div id="preferenser-tradar">
92
							<p>Parallella trådar:
93 1
							<label>1<input type="radio" value="1" name="trådar"{$trådar[1]}></label>
94 1
							<label>3<input type="radio" value="3" name="trådar"{$trådar[3]}></label>
95 1
							<label>9<input type="radio" value="9" name="trådar"{$trådar[9]}></label>
96 1
							<label>27<input type="radio" value="27" name="trådar"{$trådar[27]}></label>
97 1
							<label>81<input type="radio" value="81" name="trådar"{$trådar[81]}></label></p>
98
						</div>
99
						<hr class="kort">
100
						<div>
101
							<table>
102
								<tr>
103
									<th class="ramfri">PHP:</th>
104 1
									<td class="ramfri"><input type="text" size="50" value="{$this->php}" id="preferenser-php"></td>
105
								</tr>
106
								<tr>
107
									<th class="ramfri">FCGI:</th>
108 1
									<td class="ramfri"><input type="text" size="50" value="{$this->fcgi}" id="preferenser-fcgi"></td>
109
								</tr>
110
								<tr>
111
									<td colspan="2" class="ramfri">
112
										<p><button id="preferenser-spara-php" type="submit">Spara</button></p>
113
									</td>
114
								</tr>
115
							</table>
116
						</div>
117
						<hr class="kort">
118
						<div>
119 1
							<p>API: <input type="text" size="45" value="{$this->api}" id="preferenser-api">
120
								<button id="preferenser-spara-api" type="submit">Spara</button></p>
121
						</div>
122
					</div> <!-- generell-övre -->
123
				</div> <!-- generell-övre-grid -->
124 1
EOT;
125
	}
126
}
127