Passed
Push — master ( 7c61fd...4bc778 )
by Sebastian
02:04
created

StagedFiles::replacement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
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\Runner\Action\Cli\Command\Placeholder;
13
14
use CaptainHook\App\Runner\Action\Cli\Command\Placeholder;
15
use SebastianFeldmann\Git\Repository;
16
17
/**
18
 * Class UpdatedFiles
19
 *
20
 * @package CaptainHook
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/captainhookphp/captainhook
23
 * @since   Class available since Release 5.0.0
24
 */
25
class StagedFiles implements Placeholder
26
{
27
    /**
28
     * Git repository
29
     *
30
     * @var \SebastianFeldmann\Git\Repository
31
     */
32
    private $repository;
33
34
    /**
35
     * UpdatedFiles constructor
36
     *
37
     * @param \SebastianFeldmann\Git\Repository $repository
38
     */
39
    public function __construct(Repository $repository)
40
    {
41
        $this->repository = $repository;
42
    }
43
44
    /**
45
     * @param  array $options
46
     * @return string
47
     */
48
    public function replacement(array $options): string
49
    {
50
        $files = isset($options['of-type'])
51
               ? $this->repository->getIndexOperator()->getStagedFilesOfType($options['of-type'])
52
               : $this->repository->getIndexOperator()->getStagedFiles();
53
54
        return implode(($options['separated-by'] ?? ' '), $files);
55
    }
56
}
57