Passed
Push — master ( 7a0ac3...8d02ee )
by Morris
14:29 queued 11s
created

CheckUserCertificates::severity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2020 Morris Jobke <[email protected]>
7
 *
8
 * @author Morris Jobke <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Settings\SetupChecks;
28
29
use OCP\IConfig;
30
use OCP\IL10N;
31
use OCP\IURLGenerator;
32
33
class CheckUserCertificates {
34
	/** @var IL10N */
35
	private $l10n;
36
	/** @var string */
37
	private $configValue;
38
	/** @var IURLGenerator */
39
	private $urlGenerator;
40
41
	public function __construct(IL10N $l10n, IConfig $config, IURLGenerator $urlGenerator) {
42
		$this->l10n = $l10n;
43
		$configValue = $config->getAppValue('files_external', 'user_certificate_scan', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $default of OCP\IConfig::getAppValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
		$configValue = $config->getAppValue('files_external', 'user_certificate_scan', /** @scrutinizer ignore-type */ false);
Loading history...
44
		if (!is_string($configValue)) {
0 ignored issues
show
introduced by
The condition is_string($configValue) is always true.
Loading history...
45
			$configValue = '';
46
		}
47
		$this->configValue = $configValue;
48
		$this->urlGenerator = $urlGenerator;
49
	}
50
51
	public function description(): string {
52
		if ($this->configValue === '') {
53
			return '';
54
		}
55
		if ($this->configValue === 'not-run-yet') {
56
			return $this->l10n->t('A background job is pending that checks for user imported SSL certificates. Please check back later.');
57
		}
58
		return $this->l10n->t('There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.');
59
	}
60
61
	public function severity(): string {
62
		return 'warning';
63
	}
64
65
	public function run(): bool {
66
		// all fine if neither "not-run-yet" nor a result
67
		return $this->configValue === '';
68
	}
69
70
	public function elements(): array {
71
		if ($this->configValue === '' || $this->configValue === 'not-run-yet') {
72
			return [];
73
		}
74
		$data = json_decode($this->configValue);
75
		if (!is_array($data)) {
76
			return [];
77
		}
78
		return $data;
79
	}
80
}
81