Completed
Push — master ( e1942b...994c00 )
by Anton
03:32
created

StemplerSource::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
8
namespace Spiral\Stempler;
9
10
/**
11
 * Default implementation for ContextInterface.
12
 */
13
final class StemplerSource
14
{
15
    /**
16
     * Must be local stream.
17
     *
18
     * @var string
19
     */
20
    private $filename;
21
22
    /**
23
     * @var null|string
24
     */
25
    private $source = null;
26
27
    /**
28
     * @param string $filename
29
     * @param string $code
30
     */
31
    public function __construct(string $filename, string $code = null)
32
    {
33
        $this->filename = $filename;
34
        $this->source = $code;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getFilename(): string
41
    {
42
        return $this->filename;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getCode(): string
49
    {
50
        return $this->source ?? file_get_contents($this->filename);
51
    }
52
}