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

YamlBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 15
ccs 14
cts 14
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Support\Console\DockerCompose;
4
5
use App\Models\PhpVersion;
6
use App\Support\Contracts\ImageRepository;
7
8
class YamlBuilder
9
{
10
    /**
11
     * Build the docker-compose.yaml file
12
     *
13
     * @param $imageSet
14
     * @throws \Throwable
15
     */
16 4
    public function build(ImageRepository $imageSet)
17
    {
18 4
        file_put_contents(
19 4
            config('porter.docker-compose-file'),
20 4
            view("docker_compose.{$imageSet->getName()}.base")->with([
21 4
                'home' => setting('home'),
22 4
                'host_machine_name' => setting('host_machine_name'),
23 4
                'activePhpVersions' => PhpVersion::active()->get(),
24 4
                'useMysql' => setting('use_mysql') == 'on',
25 4
                'useRedis' => setting('use_redis') == 'on',
26 4
                'useBrowser' => setting('use_browser') == 'on',
27 4
                'imageSet' => $imageSet->getName(),
28 4
                'imageSetPath' => $imageSet->getPath(),
29 4
                'libraryPath' => config('porter.library_path'),
30 4
            ])->render()
31
        );
32 4
    }
33
34
    /**
35
     * Destroy the docker-compose.yaml file
36
     */
37
    public function destroy()
38
    {
39
        @unlink(config('porter.docker-compose-file'));
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

39
        /** @scrutinizer ignore-unhandled */ @unlink(config('porter.docker-compose-file'));

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...
40
    }
41
}
42