Completed
Push — master ( a2bd00...ff1505 )
by Jean
02:44
created

SkyscannerCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
lcom 2
cbo 5
dl 0
loc 64
ccs 0
cts 46
cp 0
rs 10
c 4
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A execute() 0 17 2
A getValidator() 0 6 1
A getMultiDeal() 0 5 1
A getLogger() 0 6 1
1
<?php
2
/**
3
 * @author Jean Silva <[email protected]>
4
 * @license MIT
5
 */
6
namespace Jeancsil\FlightSpy\Command;
7
8
use Jeancsil\FlightSpy\Command\Entity\Parameter;
9
use Jeancsil\FlightSpy\Facade\MultiDealFacade;
10
use Jeancsil\FlightSpy\Validator\ValidatorInterface;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Psr\Log\LoggerInterface;
15
16
class SkyscannerCommand extends ContainerAwareCommand
17
{
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('flightspy:skyscanner:live_prices')
22
            ->setDescription('Look for live prices in Skyscanner for the determined filters')
23
            ->addOption(
24
                Parameter::FILE,
25
                null,
26
                InputOption::VALUE_OPTIONAL,
27
                'Load all your trips watcher from a config file (JSON)'
28
            )
29
        ;
30
    }
31
32
    /** @inheritdoc*/
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $this->getValidator()
36
            ->setTarget($input)
37
            ->validate();
38
39
        try {
40
            $this->getMultiDeal()->process($input);
41
        } catch (\InvalidArgumentException $e) {
42
            $this->getLogger()
43
                ->critical(
44
                    'Exception caught:' . PHP_EOL .
45
                    $e->getMessage() . PHP_EOL .
46
                    $e->getFile() . ':' . $e->getLine() . PHP_EOL
47
                );
48
        }
49
    }
50
51
    /**
52
     * @return ValidatorInterface
53
     */
54
    private function getValidator()
55
    {
56
        return $this
57
            ->getContainer()
58
            ->get('jeancsil_flight_spy.validator.command_line_parameter');
59
    }
60
61
    /**
62
     * @return MultiDealFacade
63
     */
64
    private function getMultiDeal()
65
    {
66
        return $this->getContainer()
67
            ->get('jeancsil_flight_spy.facade.multi_deal');
68
    }
69
70
    /**
71
     * @return LoggerInterface
72
     */
73
    private function getLogger()
74
    {
75
        return $this
76
            ->getContainer()
77
            ->get('jeancsil_flight_spy.logger.array_logger');
78
    }
79
}
80