Completed
Push — master ( dde524...92e3a2 )
by Sebastian
06:05
created

Prepare   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 9 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\Hook\Message\Action;
11
12
use CaptainHook\App\Config;
13
use CaptainHook\App\Console\IO;
14
use CaptainHook\App\Hook\Action;
15
use SebastianFeldmann\Git\CommitMessage;
16
use SebastianFeldmann\Git\Repository;
17
18
/**
19
 * Class Prepare
20
 *
21
 * @package CaptainHook
22
 * @author  Sebastian Feldmann <[email protected]>
23
 * @link    https://github.com/sebastianfeldmann/captainhook
24
 * @since   Class available since Release 3.1.0
25
 */
26
class Prepare implements Action
27
{
28
    /**
29
     * Executes the action.
30
     *
31
     * @param  \CaptainHook\App\Config           $config
32
     * @param  \CaptainHook\App\Console\IO       $io
33
     * @param  \SebastianFeldmann\Git\Repository $repository
34
     * @param  \CaptainHook\App\Config\Action    $action
35
     * @throws \Exception
36
     */
37
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
38
    {
39
        $options = $action->getOptions();
40
        $oldMsg  = $repository->getCommitMsg();
41
42
        if (!$repository->isMerging()) {
43
            $repository->setCommitMsg(new CommitMessage($options->get('message', ''), $oldMsg->getCommentCharacter()));
44
        }
45
    }
46
}
47