Passed
Push — master ( b89ee9...82ea21 )
by Sebastian
03:18
created

RepositoryAware::createRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[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
12
namespace CaptainHook\App\Console\Command;
13
14
use CaptainHook\App\Console\Runtime\Resolver;
15
use SebastianFeldmann\Git\Repository;
16
use Symfony\Component\Console\Input\InputOption;
17
18
/**
19
 * Trait RepositoryAware
20
 *
21
 * Trait for all commands that needs to be aware of the git repository.
22
 *
23
 * @package CaptainHook\App\Console\Command
24
 */
25
class RepositoryAware extends ConfigAware
26
{
27
    /**
28
     * Runtime resolver to check for PHAR or lib execution
29
     *
30
     * @var \CaptainHook\App\Console\Runtime\Resolver
31
     */
32
    protected $resolver;
33
34
    /**
35
     * RepositoryAware constructor
36
     *
37
     * @param \CaptainHook\App\Console\Runtime\Resolver $resolver
38
     */
39
    public function __construct(Resolver $resolver)
40
    {
41
        $this->resolver = $resolver;
42
        parent::__construct();
43
    }
44
45
    /**
46
     * Configure method to setup the git-directory command option
47
     *
48
     * @return void
49
     */
50
    protected function configure(): void
51
    {
52
        parent::configure();
53
54
        $this->addOption(
55
            'git-directory',
56
            'g',
57
            InputOption::VALUE_OPTIONAL,
58
            'Path to your .git directory'
59
        );
60
    }
61
62
    /**
63
     * Create a new git repository representation
64
     *
65
     * @param  string $path
66
     * @return \SebastianFeldmann\Git\Repository
67
     */
68
    protected function createRepository(string $path): Repository
69
    {
70
        return Repository::createVerified($path);
71
    }
72
}
73