Passed
Push — master ( 23bbf0...48eab7 )
by Keoghan
05:16
created

YamlBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 20
dl 0
loc 59
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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