Passed
Push — shared-storage-experiments ( 606554...2addb2 )
by Matias
08:21
created

ModelService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 56
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getModelPath() 0 2 1
A prepareAppDataFolders() 0 5 2
A useModelVersion() 0 12 2
A __construct() 0 8 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2019, Matias De lellis <[email protected]>
4
 *
5
 * @author Matias De lellis <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\FaceRecognition\Service;
25
26
use OCP\IConfig;
27
use OCP\Files\IAppData;
28
use OCP\Files\IRootFolder;
29
use OCP\Files\NotFoundException;
30
31
class ModelService {
32
33
	/** @var IConfig */
34
	private $config;
35
36
	/** @var IAppData */
37
	private $appData;
38
39
	/** @var IRootFolder */
40
	private $rootFolder;
41
42
	/** @var string */
43
	private $modelsFolder;
44
45
	public function __construct(IConfig     $config,
46
	                            IAppData    $appData,
47
	                            IRootFolder $rootFolder) {
48
		$this->config     = $config;
49
		$this->appData    = $appData;
50
		$this->rootFolder = $rootFolder;
51
52
		$this->prepareAppDataFolders();
53
	}
54
55
	/**
56
	 * @return none
0 ignored issues
show
Bug introduced by
The type OCA\FaceRecognition\Service\none 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...
57
	 */
58
	public function useModelVersion (int $version) {
59
		try {
60
			$this->appData->getFolder('/models/' . $version);
61
		} catch (NotFoundException $e) {
62
			$this->appData->newFolder('/models/' . $version);
63
		}
64
65
		$instanceId = $this->config->getSystemValue('instanceid', null);
66
		$appData = $this->rootFolder->get('appdata_'.$instanceId)->getPath();
67
		$dataDir = $this->config->getSystemValue('datadirectory', null);
68
69
		$this->modelsFolder = $dataDir . $appData . '/facerecognition/models/' . $version . '/';
70
	}
71
72
	/**
73
	 * @return String
74
	 */
75
	public function getModelPath(string $file): string {
76
		return $this->modelsFolder . $file;
77
	}
78
79
	/**
80
	 * @return none
81
	 */
82
	private function prepareAppDataFolders() {
83
		try {
84
			$this->appData->getFolder('/models');
85
		} catch (NotFoundException $e) {
86
			$this->appData->newFolder('/models');
87
		}
88
	}
89
90
}