Prepare::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 4
crap 2
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\Hook\Message\Action;
13
14
use CaptainHook\App\Config;
15
use CaptainHook\App\Console\IO;
16
use CaptainHook\App\Hook\Action;
17
use SebastianFeldmann\Git\CommitMessage;
18
use SebastianFeldmann\Git\Repository;
19
20
/**
21
 * Class Prepare
22
 *
23
 * @package CaptainHook
24
 * @author  Sebastian Feldmann <[email protected]>
25
 * @link    https://github.com/captainhook-git/captainhook
26
 * @since   Class available since Release 3.1.0
27
 */
28
class Prepare implements Action
29
{
30
    /**
31
     * Executes the action
32
     *
33
     * @param  \CaptainHook\App\Config           $config
34
     * @param  \CaptainHook\App\Console\IO       $io
35
     * @param  \SebastianFeldmann\Git\Repository $repository
36
     * @param  \CaptainHook\App\Config\Action    $action
37
     * @return void
38
     * @throws \Exception
39
     */
40 2
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action): void
41
    {
42 2
        $options = $action->getOptions();
43 2
        $oldMsg  = $repository->getCommitMsg();
44
45 2
        if (!$repository->isMerging()) {
46 2
            $repository->setCommitMsg(new CommitMessage($options->get('message', ''), $oldMsg->getCommentCharacter()));
47
        }
48
    }
49
}
50