Passed
Push — install-models-command ( 8db816...c056b7 )
by Matias
105:51 queued 104:27
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 27
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
30
class ModelService {
31
32
	/** @var IConfig */
33
	private $config;
34
35
	/** @var IAppData */
36
	private $appData;
37
38
	/** @var IRootFolder */
39
	private $rootFolder;
40
41
	/** @var string */
42
	private $modelsFolder;
43
44
	public function __construct(IConfig     $config,
45
	                            IAppData    $appData,
46
	                            IRootFolder $rootFolder) {
47
		$this->config     = $config;
48
		$this->appData    = $appData;
49
		$this->rootFolder = $rootFolder;
50
51
		$this->prepareAppDataFolders();
52
	}
53
54
	/**
55
	 * @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...
56
	 */
57
	public function useModelVersion (int $version) {
58
		try {
59
			$this->appData->getFolder('/models/' . $version);
60
		} catch (NotFoundException $e) {
0 ignored issues
show
Bug introduced by
The type OCA\FaceRecognition\Service\NotFoundException 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...
61
			$this->appData->newFolder('/models/' . $version);
62
		}
63
64
		$instanceId = $this->config->getSystemValue('instanceid', null);
65
		$appData = $this->rootFolder->get('appdata_'.$instanceId)->getPath();
66
		$dataDir = $this->config->getSystemValue('datadirectory', null);
67
68
		$this->modelsFolder = $dataDir . $appData . '/facerecognition/models/' . $version . '/';
69
	}
70
71
	/**
72
	 * @return String
73
	 */
74
	public function getModelPath(string $file): string {
75
		return $this->modelFolder . $file;
0 ignored issues
show
Bug introduced by
The property modelFolder does not exist on OCA\FaceRecognition\Service\ModelService. Did you mean modelsFolder?
Loading history...
76
	}
77
78
	/**
79
	 * @return none
80
	 */
81
	private function prepareAppDataFolders() {
82
		try {
83
			$this->appData->getFolder('/models');
84
		} catch (NotFoundException $e) {
85
			$this->appData->newFolder('/models');
86
		}
87
	}
88
89
}