Completed
Push — master ( 023e21...5ec956 )
by Guillaume
07:09
created

RunHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 1
cbo 7
dl 0
loc 52
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 24 2
1
<?php
2
3
namespace Hogosha\Monitor\Console\Handler;
4
5
use Hogosha\Monitor\Client\GuzzleClient;
6
use Hogosha\Monitor\Configuration\ConfigurationLoader;
7
use Hogosha\Monitor\DependencyInjection\Exception\ConfigurationLoadingException;
8
use Hogosha\Monitor\Model\UrlProvider;
9
use Hogosha\Monitor\Renderer\RendererFactory;
10
use Hogosha\Monitor\Runner\Runner;
11
use Webmozart\Console\Api\Args\Args;
12
use Webmozart\Console\Api\IO\IO;
13
14
/**
15
 * @author Guillaume Cavana <[email protected]>
16
 */
17
class RunHandler
18
{
19
    /**
20
     * $configurationLoader.
21
     *
22
     * @var ConfigurationLoader
23
     */
24
    protected $configurationLoader;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param ConfigurationLoader $configurationLoader
30
     */
31
    public function __construct(ConfigurationLoader $configurationLoader)
32
    {
33
        $this->configurationLoader = $configurationLoader;
34
    }
35
36
    /**
37
     * handle.
38
     *
39
     * @param Args $args
40
     * @param IO   $io
41
     *
42
     * @return int
43
     */
44
    public function handle(Args $args, IO $io)
45
    {
46
        $this->configurationLoader->setRootDirectory($args->getOption('config'));
47
48
        try {
49
50
            $runner = new Runner(
51
                new UrlProvider($this->configurationLoader),
52
                GuzzleClient::createClient()
53
            );
54
55
            $renderer = RendererFactory::create($args->getOption('format'), $io);
56
            $results = $runner->run();
57
            $renderer->render($results);
58
59
        } catch (ConfigurationLoadingException $e) {
60
            $io->writeLine(
61
                sprintf(
62
                    '<info>There is no configuration file in</info> "%s"',
63
                    $this->configurationLoader->getRootDirectory()
64
                )
65
            );
66
        }
67
    }
68
}
69