Passed
Push — master ( 3fa770...2b13f3 )
by Matias
117:50 queued 13:36
created

Admin::getForm()   B

Complexity

Conditions 9
Paths 128

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 9
eloc 22
c 4
b 0
f 0
nc 128
nop 0
dl 0
loc 36
ccs 0
cts 26
cp 0
crap 90
rs 7.8222
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2018-2020 Matias De lellis <[email protected]>
5
 *
6
 * @author Matias De lellis <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\FaceRecognition\Settings;
26
27
use OCP\AppFramework\Http\TemplateResponse;
28
use OCP\IL10N;
29
use OCP\Settings\ISettings;
30
use OCP\Util as OCP_Util;
31
32
use OCA\FaceRecognition\Helper\MemoryLimits;
33
34
use OCA\FaceRecognition\Model\IModel;
35
use OCA\FaceRecognition\Model\ModelManager;
36
37
use OCA\FaceRecognition\Service\SettingsService;
38
39
class Admin implements ISettings {
40
41
	/** @var ModelManager */
42
	public $modelManager;
43
44
	/** @var SettingsService */
45
	public $settingsService;
46
47
	/** @var MemoryLimits */
48
	public $memoryLimits;
49
50
	/** @var IL10N */
51
	protected $l10n;
52
53
	public function __construct(ModelManager    $modelManager,
54
	                            SettingsService $settingsService,
55
	                            MemoryLimits    $memoryLimits,
56
	                            IL10N           $l10n)
57
	{
58
		$this->modelManager    = $modelManager;
59
		$this->settingsService = $settingsService;
60
		$this->memoryLimits    = $memoryLimits;
61
		$this->l10n            = $l10n;
62
	}
63
64
	public function getPriority() {
65
		return 20;
66
	}
67
68
	public function getSection() {
69
		return 'facerecognition';
70
	}
71
72
	public function getForm() {
73
74
		$meetDependencies = true;
75
		$resume = "";
76
77
		$model = $this->modelManager->getCurrentModel();
78
79
		if (is_null($model)) {
80
			$resume = $this->l10n->t("It seems you don't have any model installed.");
81
			// TODO: Document models and add link here.
82
		}
83
84
		$error_message = '';
85
		if (!is_null($model) && !$model->meetDependencies($error_message)) {
86
			$resume .= $this->l10n->t("It seems that you do not meet the dependencies to use the current model.");
87
			// TODO: Apply message
88
			$meetDependencies = false;
89
		}
90
91
		$pdlibVersion = phpversion('pdlib');
92
93
		$systemMemory = $this->memoryLimits->getSystemMemory();
94
		$phpMemory = $this->memoryLimits->getPhpMemory();
95
		$availableMemory = $this->memoryLimits->getAvailableMemory();
96
97
		$params = [
98
			'meet-dependencies' => $meetDependencies,
99
			'model-version' => is_null($model) ? $this->l10n->t("Not installed") : $model->getId(),
100
			'pdlib-version' => $pdlibVersion ? $pdlibVersion : $this->l10n->t("Not installed"),
101
			'system-memory' => $systemMemory > 0 ? OCP_Util::humanFileSize($systemMemory) : $this->l10n->t("Unknown"),
0 ignored issues
show
Bug introduced by
$systemMemory of type double is incompatible with the type integer expected by parameter $bytes of OCP\Util::humanFileSize(). ( Ignorable by Annotation )

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

101
			'system-memory' => $systemMemory > 0 ? OCP_Util::humanFileSize(/** @scrutinizer ignore-type */ $systemMemory) : $this->l10n->t("Unknown"),
Loading history...
102
			'php-memory' => $phpMemory > 0 ? OCP_Util::humanFileSize($phpMemory) : $this->l10n->t("Unknown"),
103
			'available-memory' => $availableMemory > 0 ? OCP_Util::humanFileSize($availableMemory) : $this->l10n->t("Unknown"),
104
			'resume' => $resume,
105
		];
106
107
		return new TemplateResponse('facerecognition', 'settings/admin', $params, '');
108
109
	}
110
111
}