Completed
Push — master ( d234f3...0a4926 )
by Jan Philipp
47s queued 12s
created

Template::getContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Psh\Config;
4
5
use Shopware\Psh\ScriptRuntime\Execution\TemplateNotValidException;
6
use function file_exists;
7
use function file_get_contents;
8
use function file_put_contents;
9
10
/**
11
 * Access template content and write the content to the target destination
12
 */
13
class Template
14
{
15
    /**
16
     * @var string
17
     */
18
    private $source;
19
20
    /**
21
     * @var string
22
     */
23
    private $destination;
24
25
    public function __construct(string $source, string $destination)
26
    {
27
        $this->source = $source;
28
        $this->destination = $destination;
29
    }
30
31
    public function getDestination(): string
32
    {
33
        return $this->destination;
34
    }
35
36
    public function setDestination(string $destination): void
37
    {
38
        $this->destination = $destination;
39
    }
40
41
    /**
42
     * @throws TemplateNotValidException
43
     */
44
    public function getContent(): string
45
    {
46
        if (!file_exists($this->source)) {
47
            throw new TemplateNotValidException('File source not found in "' . $this->source . '"');
48
        }
49
50
        return file_get_contents($this->source);
51
    }
52
53
    public function setContents(string $contents): void
54
    {
55
        file_put_contents($this->destination, $contents);
56
    }
57
}
58