WriteCacheFile::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
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\EventHandler;
13
14
use CaptainHook\App\Event;
15
use CaptainHook\App\Event\Handler;
16
17
/**
18
 * Writes to commit message cache file to load it for a later commit
19
 *
20
 * @package CaptainHook
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/captainhook-git/captainhook
23
 * @since   Class available since Release 5.11.0
24
 */
25
class WriteCacheFile implements Handler
26
{
27
    /**
28
     * Path to the commit message cache file
29
     *
30
     * @var string
31
     */
32
    private $file;
33
34
    /**
35
     * @param string $file
36
     */
37 2
    public function __construct(string $file)
38
    {
39 2
        $this->file = $file;
40
    }
41
    /**
42
     * Writes the commit message to a cache file to reuse it for the next commit
43
     *
44
     * @return void
45
     */
46 1
    public function handle(Event $event)
47
    {
48 1
        $msg  = $event->repository()->getCommitMsg()->getRawContent();
49 1
        $path = $event->repository()->getRoot() . '/' . $this->file;
50 1
        file_put_contents($path, $msg);
51
    }
52
}
53