Completed
Push — develop ( bdc471...890a38 )
by Tom
02:35
created

DeleteClassifierCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 21

Duplication

Lines 27
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 27
loc 27
rs 8.8571
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Commands;
4
5
use Bobbyshaw\WatsonVisualRecognition\Message\DeleteClassifierRequest;
6
use Bobbyshaw\WatsonVisualRecognition\Message\Response;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Helper\Table;
12
use Bobbyshaw\WatsonVisualRecognition\Classifier;
13
14
/**
15
 * Command to delete a classifier
16
 *
17
 * @package Bobbyshaw\WatsonVisualRecognition\Commands
18
 * @author Tom Robertshaw <[email protected]>
19
 */
20
class DeleteClassifierCommand extends BaseCommand
21
{
22
    /**
23
     * Configure command
24
     */
25 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $this
28
            ->setName('classifier:delete')
29
            ->setDescription('Delete Classifier')
30
            ->addArgument(
31
                'username',
32
                InputArgument::REQUIRED,
33
                'IBM Watson Service credentials username.'
34
            )
35
            ->addArgument(
36
                'password',
37
                InputArgument::REQUIRED,
38
                'IBM Watson Service credentials password.'
39
            )
40
            ->addArgument(
41
                'classifier_id',
42
                InputArgument::REQUIRED,
43
                'Classifier ID'
44
            )
45
            ->addOption(
46
                'version-date',
47
                '-d',
48
                InputOption::VALUE_REQUIRED,
49
                'API version date, defaults to current date i.e. latest release'
50
            );
51
    }
52
53
    /**
54
     * Execute command
55
     *
56
     * @param InputInterface $input
57
     * @param OutputInterface $output
58
     * @return void
59
     * @throws \Exception
60
     */
61
    protected function execute(InputInterface $input, OutputInterface $output)
62
    {
63
        $config = [
64
            'username' => $input->getArgument('username'),
65
            'password' => $input->getArgument('password'),
66
        ];
67
68
        if ($version = $input->getOption('version-date')) {
69
            $config['version'] = $version;
70
        }
71
72
        $this->client->initialize($config);
73
74
        /** @var DeleteClassifierRequest $request */
75
        $request = $this->client->deleteClassifier(['classifier_id' => $input->getArgument('classifier_id')]);
76
77
        /** @var Response $response */
78
        $response = $request->send();
79
80
        if ($response->isSuccessful()) {
81
            $output->writeln(sprintf("<info>Classifier %s successfully deleted.</info>", $request->getClassifierId()));
82
        } elseif ($error = $response->getErrorMessage()) {
83
            $output->writeln(sprintf("<error>%s</error>", $error));
84
        }
85
    }
86
}
87