Completed
Pull Request — master (#15)
by Andreas
02:21
created

Hook::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
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 CaptainHook\App\Console\Command;
11
12
use CaptainHook\App\Config;
13
use CaptainHook\App\Runner;
14
use CaptainHook\App\Console\IO;
15
use SebastianFeldmann\Git\Repository;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Class Hook
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/sebastianfeldmann/captainhook
25
 * @since   Class available since Release 0.9.0
26
 */
27
abstract class Hook extends Base
28
{
29
    /**
30
     * Hook to execute
31
     *
32
     * @var string
33
     */
34
    protected $hookName;
35
36
    /**
37
     * Path to the configuration file to use.
38
     *
39
     * @var string
40
     */
41
    protected $configFile;
42
43
    /**
44
     * Path to the git repository to use.
45
     *
46
     * @var string
47
     */
48
    protected $repositoryPath;
49
50
    /**
51
     * Hook constructor.
52
     *
53
     * @param string $configFile
54
     * @param string $repositoryPath
55 5
     */
56
    public function __construct(string $configFile, string $repositoryPath)
57 5
    {
58 5
        $this->configFile     = $configFile;
59 5
        $this->repositoryPath = $repositoryPath;
60 5
        parent::__construct();
61
    }
62
63
    /**
64
     * Configure the command.
65 5
     */
66
    protected function configure()
67 5
    {
68 5
        $this->setName($this->hookName)
69 5
             ->setDescription('Run git ' . $this->hookName . ' hook.')
70 5
             ->setHelp('This command executes the ' . $this->hookName . ' hook.');
71
    }
72
73
    /**
74
     * Execute the command.
75
     *
76
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
77
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
78
     * @return void
79
     * @throws \CaptainHook\App\Exception\InvalidHookName
80 5
     */
81
    protected function execute(InputInterface $input, OutputInterface $output)
82 5
    {
83 5
        $io         = $this->getIO($input, $output);
84 5
        $config     = $this->getConfig($this->configFile, true);
85
        $repository = new Repository($this->repositoryPath);
86
87 4
        // handle command specific setup
88
        $this->setup($input, $output, $config, $repository);
89
90 4
        // execute the hook
91 4
        $hook = new Runner\Hook($io, $config, $repository);
92 4
        $hook->setHook($this->hookName);
93 4
        $hook->run();
94
    }
95
96
    /**
97
     * Setup the command.
98
     *
99
     * @param \Symfony\Component\Console\Input\InputInterface   $input
100
     * @param \Symfony\Component\Console\Output\OutputInterface $output
101
     * @param \CaptainHook\App\Config                           $config
102
     * @param \SebastianFeldmann\Git\Repository                 $repository
103 2
     */
104
    protected function setup(InputInterface $input, OutputInterface $output, Config $config, Repository $repository)
105
    {
106 2
        // do something fooish
107
    }
108
109
    protected function tearDown(IO $io, Config $config, Repository $repository)
2 ignored issues
show
Unused Code introduced by
The parameter $io is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
110
    {
111
        // do some more foolish things.
112
    }
113
114
}
115