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

Hook::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
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\Runner;
14
use SebastianFeldmann\Git\Repository;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Class Hook
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
abstract class Hook extends Base
27
{
28
    /**
29
     * Hook to execute
30
     *
31
     * @var string
32
     */
33
    protected $hookName;
34
35
    /**
36
     * Path to the configuration file to use.
37
     *
38
     * @var string
39
     */
40
    protected $configFile;
41
42
    /**
43
     * Path to the git repository to use.
44
     *
45
     * @var string
46
     */
47
    protected $repositoryPath;
48
49
    /**
50
     * Hook constructor.
51
     *
52
     * @param string $configFile
53
     * @param string $repositoryPath
54
     */
55 4
    public function __construct(string $configFile, string $repositoryPath)
56
    {
57 4
        $this->configFile     = $configFile;
58 4
        $this->repositoryPath = $repositoryPath;
59 4
        parent::__construct();
60 4
    }
61
62
    /**
63
     * Configure the command.
64
     */
65 4
    protected function configure()
66
    {
67 4
        $this->setName($this->hookName)
68 4
             ->setDescription('Run git ' . $this->hookName . ' hook.')
69 4
             ->setHelp('This command executes the ' . $this->hookName . ' hook.');
70 4
    }
71
72
    /**
73
     * Execute the command.
74
     *
75
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
76
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
77
     * @return void
78
     */
79 4
    protected function execute(InputInterface $input, OutputInterface $output)
80
    {
81 4
        $io         = $this->getIO($input, $output);
82 4
        $config     = $this->getConfig($this->configFile, true);
83 4
        $repository = new Repository($this->repositoryPath);
84
85
        // handle command specific setup
86 3
        $this->setup($input, $output, $config, $repository);
87
88
        // execute the hook
89 3
        $hook = new Runner\Hook($io, $config, $repository);
90 3
        $hook->setHook($this->hookName);
91 3
        $hook->run();
92 3
    }
93
94
    /**
95
     * Setup the command.
96
     *
97
     * @param \Symfony\Component\Console\Input\InputInterface   $input
98
     * @param \Symfony\Component\Console\Output\OutputInterface $output
99
     * @param \SebastianFeldmann\CaptainHook\Config             $config
100
     * @param \SebastianFeldmann\Git\Repository                 $repository
101
     */
102
    protected function setup(InputInterface $input, OutputInterface $output, Config $config, Repository $repository)
103 2
    {
104
        // do something fooish
105
    }
106
}
107