GoCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 2
c 3
b 1
f 1
lcom 1
cbo 4
dl 0
loc 85
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B executeVisithor() 0 31 1
1
<?php
2
3
/*
4
 * This file is part of the Visithor package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * Feel free to edit as you please, and have fun.
10
 *
11
 * @author Marc Morera <[email protected]>
12
 */
13
14
namespace Visithor\Bundle\Command;
15
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
use Visithor\Command\GoCommand as OriginalGoCommand;
19
use Visithor\Executor\Executor;
20
use Visithor\Generator\UrlGenerator;
21
use Visithor\Renderer\RendererFactory;
22
23
/**
24
 * Class GoCommand
25
 */
26
class GoCommand extends OriginalGoCommand
27
{
28
    /**
29
     * @var UrlGenerator
30
     *
31
     * URL instances generator
32
     */
33
    protected $urlGenerator;
34
35
    /**
36
     * @var RendererFactory
37
     *
38
     * Renderer factory
39
     */
40
    protected $rendererFactory;
41
42
    /**
43
     * @var Executor
44
     *
45
     * Visithor Executor
46
     */
47
    protected $executor;
48
49
    /**
50
     * Construct
51
     *
52
     * @param UrlGenerator    $urlGenerator    Url generator
53
     * @param RendererFactory $rendererFactory Render factory
54
     * @param Executor        $executor        Executor
55
     */
56
    public function __construct(
57
        UrlGenerator $urlGenerator,
58
        RendererFactory $rendererFactory,
59
        Executor $executor
60
    ) {
61
        parent::__construct();
62
63
        $this->urlGenerator = $urlGenerator;
64
        $this->rendererFactory = $rendererFactory;
65
        $this->executor = $executor;
66
    }
67
68
    /**
69
     * Executes all business logic inside this command
70
     *
71
     * This method returns 0 if all executions passed. 1 otherwise.
72
     *
73
     * @param OutputInterface $output Output
74
     * @param array           $config Config
75
     * @param string          $format Format
76
     *
77
     * @return integer Execution return
78
     */
79
    protected function executeVisithor(
80
        OutputInterface $output,
81
        array $config,
82
        $format
83
    ) {
84
        $renderer = $this
85
            ->rendererFactory
86
            ->create($format);
87
88
        $this
89
            ->executor
90
            ->build();
91
92
        $urlChain = $this
93
            ->urlGenerator
94
            ->generate($config);
95
96
        $result = $this
97
            ->executor
98
            ->execute(
99
                $urlChain,
100
                $renderer,
101
                $output
102
            );
103
104
        $this
105
            ->executor
106
            ->destroy();
107
108
        return $result;
109
    }
110
}
111