Passed
Push — master ( a4c5f9...448818 )
by Keoghan
18:30
created

SiteConfBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Support\Nginx;
4
5
use App\Models\Site;
6
use Illuminate\Filesystem\Filesystem;
7
8
class SiteConfBuilder
9
{
10
    protected $files;
11
12 9
    public function __construct(Filesystem $files)
13
    {
14 9
        $this->files = $files;
15
    }
16
17
    /**
18
     * Build the nginx.conf file for a given site.
19
     *
20
     * @param \App\Models\Site $site
21
     *
22
     * @throws \Throwable
23
     */
24 2
    public function build(Site $site)
25
    {
26 2
        $this->files->put(
27 2
            $site->nginx_conf_path,
28 2
            view($site->nginx_conf_template)->with([
29 2
                'site'    => $site->url,
30 2
                'name'    => $site->name,
31 2
                'version' => $site->php_version->safe,
32 2
            ])->render()
33
        );
34
    }
35
36
    /**
37
     * Destroy the nginx.conf conf for a given site.
38
     *
39
     * @param \App\Models\Site $site
40
     */
41
    public function destroy(Site $site)
42
    {
43
        $this->files->delete($site->nginx_conf_path);
44
    }
45
}
46