Passed
Push — shared-storage-experiments ( 711936...cbb9c9 )
by Matias
16:42
created

ModelService::getModelPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
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 1
	public function __construct(IConfig     $config,
46
	                            IAppData    $appData,
47
	                            IRootFolder $rootFolder) {
48 1
		$this->config     = $config;
49 1
		$this->appData    = $appData;
50 1
		$this->rootFolder = $rootFolder;
51
52 1
		$this->prepareAppDataFolders();
53 1
	}
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 4
	public function useModelVersion (int $version) {
59
		try {
60 4
			$this->appData->getFolder('/models/' . $version);
61 1
		} catch (NotFoundException $e) {
62 1
			$this->appData->newFolder('/models/' . $version);
63
		}
64
65 4
		$instanceId = $this->config->getSystemValue('instanceid', null);
66 4
		$appData = $this->rootFolder->get('appdata_'.$instanceId)->getPath();
67 4
		$dataDir = $this->config->getSystemValue('datadirectory', null);
68
69 4
		$this->modelsFolder = $dataDir . $appData . '/facerecognition/models/' . $version . '/';
70 4
	}
71
72
	/**
73
	 * @return String
74
	 */
75 4
	public function getModelPath(string $file): string {
76 4
		return $this->modelsFolder . $file;
77
	}
78
79
	/**
80
	 * @return none
81
	 */
82 1
	private function prepareAppDataFolders() {
83
		try {
84 1
			$this->appData->getFolder('/models');
85 1
		} catch (NotFoundException $e) {
86 1
			$this->appData->newFolder('/models');
87
		}
88 1
	}
89
90
}