Completed
Push — master ( bbfb28...e849e1 )
by Hannes
01:48
created

CodeBlock   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __tostring() 0 4 1
A prepend() 0 12 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester\Parser;
6
7
/**
8
 * Immutable value object representing a block of code
9
 */
10
class CodeBlock
11
{
12
    /**
13
     * @var string
14
     */
15
    private $code;
16
17
    public function __construct(string $code)
18
    {
19
        $this->code = $code;
20
    }
21
22
    public function __tostring(): string
23
    {
24
        return $this->code;
25
    }
26
27
    /**
28
     * Create a new object with the contents of $codeBlock prepended to this block
29
     */
30
    public function prepend(CodeBlock $codeBlock): CodeBlock
31
    {
32
        return new CodeBlock(
33
            sprintf(
34
                "%s\n%s%s\n%s",
35
                'ob_start();',
36
                $codeBlock,
37
                'ob_end_clean();',
38
                $this
39
            )
40
        );
41
    }
42
}
43