Failed Conditions
Push — master ( ac05b5...2858d3 )
by Keoghan
02:49
created

YamlBuilder::__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\Console\DockerCompose;
4
5
use App\Models\PhpVersion;
6
use App\PorterLibrary;
7
use App\Support\Contracts\ImageRepository;
8
use Illuminate\Filesystem\Filesystem;
9
10
class YamlBuilder
11
{
12
    protected $files;
13
14 54
    public function __construct(Filesystem $files)
15
    {
16 54
        $this->files = $files;
17 54
    }
18
19
    /**
20
     * Build the docker-compose.yaml file
21
     *
22
     * @param $imageSet
23
     * @throws \Throwable
24
     */
25 4
    public function build(ImageRepository $imageSet)
26
    {
27 4
        $lib = app(PorterLibrary::class);
28
29 4
        $this->files->put(
30 4
            $lib->dockerComposeFile(),
31 4
            view("docker_compose.{$imageSet->getName()}.base")->with([
32 4
                'home' => setting('home'),
33 4
                'host_machine_name' => setting('host_machine_name'),
34 4
                'activePhpVersions' => PhpVersion::active()->get(),
35 4
                'useMysql' => setting('use_mysql') == 'on',
36 4
                'useRedis' => setting('use_redis') == 'on',
37 4
                'useBrowser' => setting('use_browser') == 'on',
38 4
                'imageSet' => $imageSet->getName(),
39 4
                'imageSetPath' => $imageSet->getPath(),
40 4
                'libraryPath' => $lib->path(),
41 4
            ])->render()
42
        );
43 4
    }
44
45
    /**
46
     * Destroy the docker-compose.yaml file
47
     */
48
    public function destroy()
49
    {
50
        $this->files->delete(app(PorterLibrary::class)->dockerComposeFile());
51
    }
52
}
53