Passed
Push — self-contained-model ( 34afa8...32b4da )
by Matias
04:08
created

SetupCommand::execute()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 19
c 3
b 0
f 0
nc 6
nop 2
dl 0
loc 31
ccs 0
cts 23
cp 0
crap 20
rs 9.6333
1
<?php
2
/**
3
 * @copyright Copyright (c) 2019-2020 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
namespace OCA\FaceRecognition\Command;
24
25
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command 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...
26
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption 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...
27
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface 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...
28
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface 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...
29
30
use OCA\FaceRecognition\Model\DlibCnnModel;
31
32
use OCA\FaceRecognition\Model\ModelManager;
33
34
class SetupCommand extends Command {
35
36
	/** @var ModelManager */
37
	protected $modelManager;
38
39
	/** @var OutputInterface */
40
	protected $logger;
41
42
	/**
43
	 * @param ModelManager
44
	 */
45
	public function __construct(ModelManager $modelManager)
46
	{
47
		parent::__construct();
48
49
		$this->modelManager = $modelManager;
50
	}
51
52
	protected function configure() {
53
		$this
54
			->setName('face:setup')
55
			->setDescription('Download and Setup the model 1 used for the analysis')
56
			->addOption(
57
				'model',
58
				'm',
59
				InputOption::VALUE_REQUIRED,
60
				'The identifier number of the model to install',
61
				null
62
			);
63
	}
64
65
	/**
66
	 * @param InputInterface $input
67
	 * @param OutputInterface $output
68
	 * @return int
69
	 */
70
	protected function execute(InputInterface $input, OutputInterface $output) {
71
		$this->logger = $output;
72
73
		$modelId = $input->getOption('model');
74
		if (is_null($modelId)) {
75
			$modelId = 1;
76
		}
77
78
		$model = $this->modelManager->getModel($modelId);
79
80
		if (is_null($model)) {
81
			$this->logger->writeln('Invalid model Id');
82
			return 1;
83
		}
84
85
		$this->logger->writeln('We will install the model '. $model->getId());
86
87
		if ($model->isInstalled()) {
88
			$this->logger->writeln('Model ' . $model->getId() . ' files are already installed');
89
			$model->setDefault();
90
			$this->logger->writeln('This model was configured as default');
91
			return 0;
92
		}
93
94
		$model->install();
95
		$this->logger->writeln('Install model ' . $model->getId() .  ' successfully done');
96
97
		$model->setDefault();
98
		$this->logger->writeln('The new model was configured as default');
99
100
		return 0;
101
	}
102
103
}
104