Completed
Pull Request — master (#86)
by Jan Philipp
01:53
created

Template   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 1
dl 0
loc 59
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
4
namespace Shopware\Psh\ScriptRuntime\Execution;
5
6
/**
7
 * Access template content and write the content to the target destination
8
 */
9
class Template
10
{
11
    /**
12
     * @var string
13
     */
14
    private $source;
15
16
    /**
17
     * @var string
18
     */
19
    private $destination;
20
21
    /**
22
     * @param string $source
23
     * @param string $destination
24
     */
25
    public function __construct(string $source, string $destination)
26
    {
27
        $this->source = $source;
28
        $this->destination = $destination;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getDestination(): string
35
    {
36
        return $this->destination;
37
    }
38
39
    /**
40
     * @param string $destination
41
     */
42
    public function setDestination(string $destination)
43
    {
44
        $this->destination = $destination;
45
    }
46
47
    /**
48
     * @return string
49
     * @throws TemplateNotValidException
50
     */
51
    public function getContent(): string
52
    {
53
        if (!file_exists($this->source)) {
54
            throw new TemplateNotValidException('File source not found in "' . $this->source . '"');
55
        }
56
57
        return file_get_contents($this->source);
58
    }
59
60
    /**
61
     * @param string $contents
62
     */
63
    public function setContents(string $contents)
64
    {
65
        file_put_contents($this->destination, $contents);
66
    }
67
}
68