Test Failed
Branch feature__set_up_scrutinizer (ea6624)
by Robin
06:04 queued 02:46
created

SiteConfBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 28
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
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
7
class SiteConfBuilder
8
{
9
    /**
10
     * Build the nginx.conf file for a given site
11
     *
12
     * @param \App\Models\Site $site
13
     * @throws \Throwable
14
     */
15 1
    public function build(Site $site)
16
    {
17 1
        file_put_contents(
18 1
            $site->nginx_conf_path,
19 1
            view($site->nginx_conf_template)->with([
20 1
                'site' => $site->url,
21 1
                'name' => $site->name,
22 1
                'version' => $site->php_version->safe
23 1
            ])->render()
24
        );
25 1
    }
26
27
    /**
28
     * Destroy the nginx.conf conf for a given site
29
     *
30
     * @param \App\Models\Site $site
31
     */
32
    public function destroy(Site $site)
33
    {
34
        @unlink($site->nginx_conf_path);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

34
        /** @scrutinizer ignore-unhandled */ @unlink($site->nginx_conf_path);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
35
    }
36
}
37