Completed
Push — master ( 28862c...f2c661 )
by Sebastian
02:18
created

Beams   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 14

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 14
dl 0
loc 35
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 23 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 SebastianFeldmann\CaptainHook\Hook\Message\Action;
11
12
use SebastianFeldmann\CaptainHook\Config;
13
use SebastianFeldmann\CaptainHook\Console\IO;
14
use SebastianFeldmann\CaptainHook\Exception\ActionFailed;
15
use SebastianFeldmann\CaptainHook\Hook\Message\Rule;
16
use SebastianFeldmann\CaptainHook\Hook\Message\RuleBook;
17
use SebastianFeldmann\Git\Repository;
18
19
/**
20
 * Class Beams
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/sebastianfeldmann/captainhook
25
 * @since   Class available since Release 0.9.0
26
 */
27
class Beams extends Book
28
{
29
    /**
30
     * Execute the configured action.
31
     *
32
     * @param  \SebastianFeldmann\CaptainHook\Config         $config
33
     * @param  \SebastianFeldmann\CaptainHook\Console\IO     $io
34
     * @param  \SebastianFeldmann\Git\Repository             $repository
35
     * @param  \SebastianFeldmann\CaptainHook\Config\Action  $action
36
     * @throws \Exception
37
     */
38 2
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
39
    {
40 2
        $options = $action->getOptions();
41 2
        $book    = new RuleBook();
42 2
        $book->setRules(
43
            [
44 2
                new Rule\CapitalizeSubject(),
45 2
                new Rule\LimitSubjectLength($options->get('subjectLength', 50)),
46 2
                new Rule\NoPeriodOnSubjectEnd(),
47 2
                new Rule\UseImperativeMood(),
48 2
                new Rule\LimitBodyLineLength($options->get('bodyLineLength', 72)),
49 2
                new Rule\SeparateSubjectFromBodyWithBlankLine(),
50
            ]
51
        );
52
53
        try {
54 2
            $this->validate($book, $repository);
55 1
        } catch (ActionFailed $exception) {
56 1
            $io->writeError(['Commit message does not match style', '', 'Message was:']);
57 1
            $io->writeError($repository->getCommitMsg()->getLines());
58 1
            throw ActionFailed::fromPrevious($exception);
59
        }
60 1
    }
61
}
62