Completed
Push — master ( 25bde4...38c554 )
by Christian
02:39
created

AbstractController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 94
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getInputOutput() 0 8 2
A getOutput() 0 8 2
A getComposer() 0 9 2
A getTensideConfig() 0 4 1
A getTensideHome() 0 4 1
A getTensideDataDir() 0 4 1
A getTensideTasks() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of tenside/core-bundle.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core-bundle
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core-bundle/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core-bundle
18
 * @filesource
19
 */
20
21
namespace Tenside\CoreBundle\Controller;
22
23
use Composer\Composer;
24
use Composer\Factory as ComposerFactory;
25
use Composer\IO\BufferIO;
26
use Composer\IO\IOInterface;
27
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
28
use Tenside\Core\Config\TensideJsonConfig;
29
use Tenside\Core\Task\TaskList;
30
use Tenside\Core\Util\RuntimeHelper;
31
32
/**
33
 * Abstract controller class.
34
 */
35
abstract class AbstractController extends Controller
36
{
37
    /**
38
     * The io interface in use.
39
     *
40
     * @var IOInterface
41
     */
42
    private $inputOutput;
43
44
    /**
45
     * Retrieve the io instance or create a new one.
46
     *
47
     * @return IOInterface
48
     */
49
    public function getInputOutput()
50
    {
51
        if (!$this->inputOutput) {
52
            $this->inputOutput = new BufferIO();
53
        }
54
55
        return $this->inputOutput;
56
    }
57
58
    /**
59
     * Return the output from the buffer io, if any is set.
60
     *
61
     * @return string|null
62
     */
63
    protected function getOutput()
64
    {
65
        if ($this->inputOutput instanceof BufferIO) {
66
            return $this->inputOutput->getOutput();
67
        }
68
69
        return null;
70
    }
71
72
    /**
73
     * Retrieve a composer instance.
74
     *
75
     * @param null|IOInterface $inputOutput The input/output handler to use.
76
     *
77
     * @return Composer
78
     */
79
    public function getComposer(IOInterface $inputOutput = null)
80
    {
81
        if (null === $inputOutput) {
82
            $inputOutput = $this->getInputOutput();
83
        }
84
        RuntimeHelper::setupHome($this->getTensideHome());
85
86
        return ComposerFactory::create($inputOutput);
87
    }
88
89
    /**
90
     * Retrieve the tenside instance.
91
     *
92
     * @return TensideJsonConfig
93
     */
94
    public function getTensideConfig()
95
    {
96
        return $this->container->get('tenside.config');
97
    }
98
99
    /**
100
     * Retrieve the tenside instance.
101
     *
102
     * @return string
103
     */
104
    public function getTensideHome()
105
    {
106
        return $this->container->get('tenside.home')->homeDir();
107
    }
108
109
    /**
110
     * Retrieve the tenside instance.
111
     *
112
     * @return string
113
     */
114
    public function getTensideDataDir()
115
    {
116
        return $this->container->get('tenside.home')->tensideDataDir();
117
    }
118
119
    /**
120
     * Retrieve the tenside task list.
121
     *
122
     * @return TaskList
123
     */
124
    public function getTensideTasks()
125
    {
126
        return $this->container->get('tenside.tasks');
127
    }
128
}
129