Passed
Push — self-contained-model ( d8299d...34afa8 )
by Matias
03:49
created

SetupCommand::execute()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 41
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 6
eloc 28
c 3
b 0
f 0
nc 18
nop 2
dl 0
loc 41
ccs 0
cts 33
cp 0
crap 42
rs 8.8497
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\DlibCnn5Model;
31
use OCA\FaceRecognition\Model\DlibCnn68Model;
32
33
class SetupCommand extends Command {
34
35
	/** @var  DlibCnn5Model */
36
	protected $dlibCnn5Model;
37
38
	/** @var  DlibCnn68Model */
39
	protected $dlibCnn68Model;
40
41
	/** @var OutputInterface */
42
	protected $logger;
43
44
	/**
45
	 * @param DlibCnn5Model $model
46
	 * @param DlibCnn68Model $model
47
	 */
48
	public function __construct(DlibCnn5Model  $dlibCnn5Model,
49
	                            DlibCnn68Model $dlibCnn68Model)
50
	{
51
		parent::__construct();
52
53
		$this->dlibCnn5Model  = $dlibCnn5Model;
54
		$this->dlibCnn68Model = $dlibCnn68Model;
55
	}
56
57
	protected function configure() {
58
		$this
59
			->setName('face:setup')
60
			->setDescription('Download and Setup the model 1 used for the analysis')
61
			->addOption(
62
				'model',
63
				'm',
64
				InputOption::VALUE_REQUIRED,
65
				'The identifier number of the model to install',
66
				null
67
			);
68
	}
69
70
	/**
71
	 * @param InputInterface $input
72
	 * @param OutputInterface $output
73
	 * @return int
74
	 */
75
	protected function execute(InputInterface $input, OutputInterface $output) {
76
		$this->logger = $output;
77
78
		$modelId = $input->getOption('model');
79
		if (is_null($modelId)) {
80
			$modelId = 1;
81
		}
82
83
		switch ($modelId) {
84
			case 1:
85
				$model = $this->dlibCnn5Model;
86
				break;
87
			case 2:
88
				$model = $this->dlibCnn68Model;
89
				break;
90
			default:
91
				$model = null;
92
				break;
93
		}
94
95
		if (is_null($model)) {
96
			$this->logger->writeln('Invalid model Id');
97
			return 1;
98
		}
99
100
		$this->logger->writeln('We will install the model '. $model->getId());
101
102
		if ($model->isInstalled()) {
103
			$this->logger->writeln('Model ' . $model->getId() . ' files are already installed');
104
			$model->setDefault();
105
			$this->logger->writeln('This model was configured as default');
106
			return 0;
107
		}
108
109
		$model->install();
110
		$this->logger->writeln('Install model ' . $model->getId() .  ' successfully done');
111
112
		$model->setDefault();
113
		$this->logger->writeln('The new model was configured as default');
114
115
		return 0;
116
	}
117
118
}
119