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

Template   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDestination() 0 4 1
A setDestination() 0 4 1
A getContent() 0 8 2
A setContents() 0 4 1
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