Passed
Push — master ( a467a6...de53c5 )
by Sebastian
02:03
created

Builder::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
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
declare(strict_types=1);
11
12
namespace CaptainHook\App\Hook\Template;
13
14
use CaptainHook\App\Config;
15
use CaptainHook\App\Hook\Template;
16
use SebastianFeldmann\Git\Repository;
17
use Symfony\Component\Console\Input\InputInterface;
18
19
/**
20
 * Builder class
21
 *
22
 * Creates git hook Template objects regarding some provided input.
23
 *
24
 * @package CaptainHook
25
 * @author  Sebastian Feldmann <[email protected]>
26
 * @link    https://github.com/captainhookphp/captainhook
27
 * @since   Class available since Release 4.3.0
28
 */
29
abstract class Builder
30
{
31
    /**
32
     * Creates a template that is responsible for the git hook template
33
     *
34
     * @param \Symfony\Component\Console\Input\InputInterface $input
35
     * @param \CaptainHook\App\Config                         $config
36
     * @param \SebastianFeldmann\Git\Repository               $repository
37
     *
38
     * @return \CaptainHook\App\Hook\Template
39
     */
40 5
    public static function build(InputInterface $input, Config $config, Repository $repository): Template
41
    {
42 5
        if ($input->getOption('run-mode') === Template::DOCKER) {
43 1
            return new Docker(
44 1
                realpath($repository->getRoot()),
45 1
                getcwd() . '/vendor',
46 1
                $input->getOption('container')
47
            );
48
        }
49
50 4
        return new Local(
51 4
            realpath($repository->getRoot()),
52 4
            getcwd() . '/vendor',
53 4
            realpath($config->getPath())
54
        );
55
    }
56
}
57