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

SiteConfBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 36
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A build() 0 9 1
A destroy() 0 3 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