Completed
Push — master ( 3de03a...7f0828 )
by Maarten
12s queued 11s
created

StubWriter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Mtolhuys\LaravelSchematics\Services;
4
5
use Illuminate\Support\Facades\File;
6
7
class StubWriter
8
{
9
    protected $stub;
10
11
    protected $file;
12
13
    public function __construct(string $file, string $stub)
14
    {
15
        $this->stub = $stub;
16
        $this->file = $file;
17
    }
18
19
    public function write(array $variables)
20
    {
21
        if (! File::isDirectory(dirname($this->file))) {
22
            File::makeDirectory(dirname($this->file), 0777, true, true);
23
        }
24
25
        File::put($this->file, str_replace(
26
            array_keys($variables),
27
            array_values($variables),
28
            File::get($this->stub)
29
        ));
30
    }
31
}
32