Completed
Push — master ( aa9657...bb9832 )
by Sebastian
05:21
created

Base   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 4
dl 0
loc 62
c 0
b 0
f 0
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setIO() 0 4 1
A getIO() 0 7 2
A getConfig() 0 13 3
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianFeldmann\CaptainHook\Console\Command;
11
12
use SebastianFeldmann\CaptainHook\Config;
13
use SebastianFeldmann\CaptainHook\Console\IO;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Class Base
20
 *
21
 * @package CaptainHook
22
 * @author  Sebastian Feldmann <[email protected]>
23
 * @link    https://github.com/sebastianfeldmann/captainhook
24
 * @since   Class available since Release 0.9.0
25
 */
26
class Base extends Command
27
{
28
    /**
29
     * Input output handler.
30
     *
31
     * @var \SebastianFeldmann\CaptainHook\Console\IO
32
     */
33
    private $io;
34
35
    /**
36
     * CaptainHook configuration
37
     *
38
     * @var \SebastianFeldmann\CaptainHook\Config
39
     */
40
    private $config;
41
42
    /**
43
     * IO setter.
44
     *
45
     * @param \SebastianFeldmann\CaptainHook\Console\IO $io
46
     */
47 10
    public function setIO(IO $io)
48
    {
49 10
        $this->io = $io;
50 10
    }
51
52
    /**
53
     * IO interface getter.
54
     *
55
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
56
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
57
     * @return \SebastianFeldmann\CaptainHook\Console\IO
58
     */
59 12
    public function getIO(InputInterface $input, OutputInterface $output)
60
    {
61 12
        if (null === $this->io) {
62 2
            $this->io = new IO\DefaultIO($input, $output, $this->getHelperSet());
63
        }
64 12
        return $this->io;
65
    }
66
67
    /**
68
     * CaptainHook config getter.
69
     *
70
     * @param  string $path
71
     * @param  bool   $failIfNotFound
72
     * @return \SebastianFeldmann\CaptainHook\Config
73
     */
74 12
    protected function getConfig(string $path = '', bool $failIfNotFound = false)
75
    {
76 12
        $this->config = Config\Factory::create($path);
77
78 12
        if ($failIfNotFound && !$this->config->isLoadedFromFile()) {
79 1
            throw new \RuntimeException(
80 1
                'Please create a captainhook configuration first' . PHP_EOL .
81 1
                'Run \'captainhook configure\'' . PHP_EOL .
82 1
                'If you have a configuration located elsewhere use the --configuration option'
83
            );
84
        }
85 11
        return $this->config;
86
    }
87
}
88