StatusCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
3
namespace LWI\DeliveryTracking\Command;
4
5
use LWI\DeliveryTracking\Adapter\ChronopostAdapter;
6
use LWI\DeliveryTracking\DeliveryTracking;
7
use League\CLImate\CLImate;
8
9
/**
10
 * Class StatusCommand
11
 */
12
class StatusCommand extends BaseCommand
13
{
14
    /**
15
     *  Command configuration
16
     */
17
    public function configure()
18
    {
19
        $this
20
            ->setName('status')
21
            ->setDescription('Get delivery status from the tracking number')
22
            ->setArgumentsDefinition([
23
                'trackingNumber' => [
24
                    'description'   => 'The tracking number provided by the delivery service.',
25
                ],
26
            ])
27
        ;
28
    }
29
30
    /**
31
     * @param CLImate $cli
32
     * @param array $arguments
33
     * @return void
34
     */
35
    public function execute(CLImate $cli, $arguments)
36
    {
37
        if (!$arguments['trackingNumber']) {
38
            $cli->error('ERROR. No tracking number provided.');
39
            return null;
40
        }
41
42
        $chronopostAdapter = new ChronopostAdapter();
43
        $deliveryTracking = new DeliveryTracking($chronopostAdapter);
44
45
        $cli->br();
46
        try {
47
            $status = $deliveryTracking->getDeliveryStatus($arguments['trackingNumber']);
48
49
            $cli->out(sprintf(
50
                'Delivery #%s is <green>%s</green>',
51
                $arguments['trackingNumber'],
52
                $status
53
            ));
54
        } catch (\Exception $e) {
55
            $cli->error(sprintf('ERROR. %s', $e->getMessage()));
56
        }
57
        $cli->br();
58
    }
59
}
60