Passed
Push — master ( 72c793...7f699f )
by Kirill
03:22
created

ViewSource::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Views;
13
14
/**
15
 * Carries information about view.
16
 */
17
final class ViewSource
18
{
19
    /** @var string */
20
    private $filename;
21
22
    /** @var string */
23
    private $name;
24
25
    /** @var string */
26
    private $namespace;
27
28
    /** @var string|null */
29
    private $code = null;
30
31
    /**
32
     * @param string $filename
33
     * @param string $name
34
     * @param string $namespace
35
     */
36
    public function __construct(string $filename, string $namespace, string $name)
37
    {
38
        $this->filename = $filename;
39
        $this->namespace = $namespace;
40
        $this->name = $name;
41
    }
42
43
    /**
44
     * Template namespace.
45
     *
46
     * @return string
47
     */
48
    public function getNamespace(): string
49
    {
50
        return $this->namespace;
51
    }
52
53
    /**
54
     * Template name.
55
     *
56
     * @return string
57
     */
58
    public function getName(): string
59
    {
60
        return $this->name;
61
    }
62
63
    /**
64
     * Template filename.
65
     *
66
     * @return string
67
     */
68
    public function getFilename(): string
69
    {
70
        return $this->filename;
71
    }
72
73
    /**
74
     * Template code.
75
     *
76
     * @return string
77
     */
78
    public function getCode(): string
79
    {
80
        return $this->code ?? file_get_contents($this->getFilename());
81
    }
82
83
    /**
84
     * Get source copy with redefined code.
85
     *
86
     * @param string $code
87
     * @return self
88
     */
89
    public function withCode(string $code): ViewSource
90
    {
91
        $context = clone $this;
92
        $context->code = $code;
93
94
        return $context;
95
    }
96
}
97