Completed
Push — develop ( fe8c75...3bcd98 )
by Tom
02:26
created

GetClassifierCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 76
Duplicated Lines 35.53 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 4
dl 27
loc 76
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 27 27 1
B execute() 0 34 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Commands;
4
5
use Bobbyshaw\WatsonVisualRecognition\Message\ClassifierResponse;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Helper\Table;
11
use Bobbyshaw\WatsonVisualRecognition\Classifier;
12
13
/**
14
 * Command to get a classifier detail
15
 *
16
 * @package Bobbyshaw\WatsonVisualRecognition\Commands
17
 * @author Tom Robertshaw <[email protected]>
18
 */
19
class GetClassifierCommand extends BaseCommand
20
{
21
    /**
22
     * Configure command
23
     */
24 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...
25
    {
26
        $this
27
            ->setName('classifier:get')
28
            ->setDescription('Get Classifier')
29
            ->addArgument(
30
                'username',
31
                InputArgument::REQUIRED,
32
                'IBM Watson Service credentials username.'
33
            )
34
            ->addArgument(
35
                'password',
36
                InputArgument::REQUIRED,
37
                'IBM Watson Service credentials password.'
38
            )
39
            ->addArgument(
40
                'classifier_id',
41
                InputArgument::REQUIRED,
42
                'Classifier ID'
43
            )
44
            ->addOption(
45
                'version-date',
46
                '-d',
47
                InputOption::VALUE_REQUIRED,
48
                'API version date, defaults to current date i.e. latest release'
49
            );
50
    }
51
52
    /**
53
     * Execute command
54
     *
55
     * @param InputInterface $input
56
     * @param OutputInterface $output
57
     * @return void
58
     * @throws \Exception
59
     */
60
    protected function execute(InputInterface $input, OutputInterface $output)
61
    {
62
        $config = [
63
            'username' => $input->getArgument('username'),
64
            'password' => $input->getArgument('password'),
65
        ];
66
67
        if ($version = $input->getOption('version-date')) {
68
            $config['version'] = $version;
69
        }
70
71
        $this->client->initialize($config);
72
73
        $request = $this->client->getClassifier(['classifier_id' => $input->getArgument('classifier_id')]);
74
75
        /** @var ClassifierResponse $response */
76
        $response = $request->send();
77
78
        /** @var Classifier $classifier */
79
        $classifier = $response->getClassifier();
80
81
        $headers = ['ID', 'Name', 'Owner', 'Created At'];
82
        $tableRows = [
83
            [
84
                $classifier->getId(),
85
                $classifier->getName(),
86
                $classifier->getOwner(),
87
                $classifier->getCreated()->format('Y-m-d H:i:s')
88
            ]
89
        ];
90
91
        $table = new Table($output);
92
        $table->setHeaders($headers)->setRows($tableRows)->render();
93
    }
94
}
95