Passed
Pull Request — master (#73)
by Keoghan
05:05
created

YamlBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 4
eloc 19
c 0
b 0
f 0
dl 0
loc 45
ccs 19
cts 21
cp 0.9048
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A destroy() 0 3 1
A build() 0 15 2
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
    /** @var Filesystem */
13
    protected $files;
14
15
    /** @var PorterLibrary */
16
    private $porterLibrary;
17
18 149
    public function __construct(Filesystem $files, PorterLibrary $porterLibrary)
19
    {
20 149
        $this->files = $files;
21 149
        $this->porterLibrary = $porterLibrary;
22 149
    }
23
24
    /**
25
     * Build the docker-compose.yaml file.
26
     *
27
     * @param $imageSet
28
     *
29
     * @throws \Throwable
30
     */
31 7
    public function build(ImageRepository $imageSet)
32
    {
33 7
        $this->files->put(
34 7
            $this->porterLibrary->dockerComposeFile(),
35 7
            view("{$imageSet->getName()}::base")->with([
36 7
                'home'              => setting('home'),
37 7
                'host_machine_name' => setting('host_machine_name'),
38 7
                'activePhpVersions' => PhpVersion::active()->get(),
39 7
                'useMysql'          => setting('use_mysql') == 'on',
40 7
                'useRedis'          => setting('use_redis') == 'on',
41 7
                'useBrowser'        => setting('use_browser') == 'on',
42 7
                'useDns'            => setting('use_dns') == 'on' || setting_missing('use_dns'),
43 7
                'imageSet'          => $imageSet,
44 7
                'libraryPath'       => $this->porterLibrary->path(),
45 7
            ])->render()
46
        );
47 7
    }
48
49
    /**
50
     * Destroy the docker-compose.yaml file.
51
     */
52
    public function destroy()
53
    {
54
        $this->files->delete($this->porterLibrary->dockerComposeFile());
55
    }
56
}
57