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

StubWriter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A write() 0 12 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