StatusCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 48
ccs 0
cts 33
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
B execute() 0 24 3
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