BaseCommand::getClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Commands;
4
5
use Bobbyshaw\WatsonVisualRecognition\Client;
6
use Bobbyshaw\WatsonVisualRecognition\ClientInterface;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
11
/**
12
 * Class BaseCommand
13
 * @package Bobbyshaw\WatsonVisualRecognition\Commands
14
 */
15
abstract class BaseCommand extends Command
16
{
17
18
    /** @var ClientInterface  */
19
    protected $client;
20
21
    /**
22
     * GetClassifiersCommand constructor.
23
     *
24
     * @param null|string $name
25
     * @param ClientInterface $client
26
     */
27 8
    public function __construct($name = null, ClientInterface $client = null)
28
    {
29 8
        $this->client = isset($client) ? $client : $this->getDefaultClient();
30
31 8
        parent::__construct($name);
32 8
    }
33
34
    /**
35
     * Configure command
36
     */
37 8
    protected function configure()
38
    {
39 8
        $this
40 8
            ->addArgument(
41 8
                'username',
42 8
                InputArgument::REQUIRED,
43
                'IBM Watson Service credentials username.'
44 8
            )
45 8
            ->addArgument(
46 8
                'password',
47 8
                InputArgument::REQUIRED,
48
                'IBM Watson Service credentials password.'
49 8
            )
50 8
            ->addOption(
51 8
                'version-date',
52 8
                '-d',
53 8
                InputOption::VALUE_REQUIRED,
54
                'API version date, defaults to current date i.e. latest release'
55 8
            );
56 8
    }
57
58
    /**
59
     * @return ClientInterface
60
     */
61 1
    public function getDefaultClient()
62
    {
63 1
        return new Client();
64
    }
65
66
    /**
67
     * @return ClientInterface
68
     */
69 1
    public function getClient()
70
    {
71 1
        return $this->client;
72
    }
73
}
74