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

YamlBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 3
eloc 18
dl 0
loc 41
ccs 19
cts 21
cp 0.9048
rs 10
c 0
b 0
f 0

3 Methods

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