Table::getTemplate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php namespace Way\Generators\Syntax;
2
3
use Illuminate\Support\Facades\File;
4
use KitLoong\MigrationsGenerator\Generators\Decorator;
5
use Way\Generators\Compilers\TemplateCompiler;
6
7
abstract class Table
8
{
9
    /**
10
     * @var TemplateCompiler
11
     */
12
    protected $compiler;
13
14
    protected $decorator;
15
16
    public function __construct(TemplateCompiler $compiler, Decorator $decorator)
17
    {
18
        $this->compiler = $compiler;
19
        $this->decorator = $decorator;
20
    }
21
22
    /**
23
     * Fetch the template of the schema
24
     *
25
     * @param  string  $method
26
     * @return string
27
     */
28
    protected function getTemplate(string $method): string
29
    {
30
        if ($method === 'drop') {
31
            return File::get(__DIR__.'/../templates/drop.txt');
32
        } else {
33
            return File::get(__DIR__.'/../templates/schema.txt');
34
        }
35
    }
36
37
    /**
38
     * Replace $FIELDS$ in the given template
39
     * with the provided schema
40
     *
41
     * @param  array  $schema
42
     * @param  string  $template
43
     * @return string
44
     */
45
    protected function replaceFieldsWith(array $schema, string $template): string
46
    {
47
        return str_replace('$FIELDS$', implode(PHP_EOL.str_repeat(' ', 12), $schema), $template);
48
    }
49
}
50