Completed
Push — master ( 58b546...f86624 )
by Sebastian
02:38
created

Generator::getTemplate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 2
nc 2
nop 1
crap 6
1
<?php declare(strict_types=1);
2
3
namespace phpbu\App\Configuration;
4
5
final class Generator
6
{
7
    /**
8
     * @var string
9
     */
10
    private const TEMPLATE_XML = <<<EOT
11
<?xml version="1.0" encoding="UTF-8"?>
12
<phpbu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13
         xsi:noNamespaceSchemaLocation="https://schema.phpbu.de/{phpbu_version}/phpbu.xsd"
14
         bootstrap="{bootstrap_script}"
15
         verbose="true">
16
    
17
    <!-- uncomment if you want to use an adapter
18
    <adapters>
19
    </adapters>
20
    -->
21
    
22
    <!-- uncomment if you want to use logging
23
    <logging>
24
    </logging>
25
    -->
26
    
27
    <backups>
28
        <backup name="__FIXME__">
29
            <source type="__FIXME__">
30
                <option name="__FIXME__" value="__FIXME__" />
31
            </source>
32
            <target dirname="__FIXME__" filename="backup-%Y%m%d-%H%i" compress="bzip2" />
33
        </backup>
34
    </backups>
35
</phpbu>
36
37
EOT;
38
39
    /**
40
     * @var string
41
     */
42
    private const TEMPLATE_JSON = <<<EOT
43
{
44
  "bootstrap": "{bootstrap_script}",
45
  "verbose": true,
46
  "adapters": [
47
  ],
48
  "logging": [
49
  ],
50
  "backups": [
51
    {
52
      "source": {
53
        "type": "__FIXME__",
54
        "options": {
55
          "__FIXME__": "__FIXME__"
56
        }
57
      }
58
      "target": {
59
        "dirname": "__FIXME__",
60
        "filename": "backup-%Y%m%d-%H%i"
61
        "compress": "bzip2"
62
      }
63
    }
64
  ]
65
}
66
67
EOT;
68
69
    /**
70
     * Return the config file content
71
     *
72
     * @param  string $version
73
     * @param  string $format
74
     * @param  string $bootstrapScript
75
     * @return string
76
     */
77
    public function generateDefaultConfiguration(string $version, string $format, string $bootstrapScript) : string
78
    {
79
        return \str_replace(
80
            [
81
                '{phpbu_version}',
82
                '{bootstrap_script}'
83
            ],
84
            [
85
                $version,
86
                $bootstrapScript
87
            ],
88
            $this->getTemplate($format)
89
        );
90
    }
91
92
    /**
93
     * Return the template code for the requested format
94
     *
95
     * @param  string $format
96
     * @return string
97
     */
98
    private function getTemplate(string $format)
99
    {
100
        return $format === 'json' ? self::TEMPLATE_JSON : self::TEMPLATE_XML;
101
    }
102
}
103