Message   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 32
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubject() 0 3 1
A __construct() 0 2 1
A fromString() 0 5 1
A __toString() 0 9 2
A getBody() 0 3 2
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Biurad opensource projects.
5
 *
6
 * @copyright 2022 Biurad Group (https://biurad.com/)
7
 * @license   https://opensource.org/licenses/BSD-3-Clause License
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Biurad\Git\Commit;
14
15
/**
16
 * A git commit message.
17
 *
18
 * @author Divine Niiquaye Ibok <[email protected]>
19
 */
20
class Message implements \Stringable
21
{
22
    public function __construct(private string $subject, private ?string $body = null)
23
    {
24
    }
25
26
    public function __toString(): string
27
    {
28
        $full = $this->subject;
29
30
        if (!empty($this->body)) {
31
            $full .= "\n\n".$this->body;
32
        }
33
34
        return $full;
35
    }
36
37
    public static function fromString(string $message): self
38
    {
39
        $data = \explode("\n\n", $message, 2);
40
41
        return new self($data[0] ?? '', $data[2] ?? null);
42
    }
43
44
    public function getSubject(): string
45
    {
46
        return $this->subject;
47
    }
48
49
    public function getBody(): ?string
50
    {
51
        return empty($this->body) ? null : \rtrim($this->body, "\n");
52
    }
53
}
54