Table   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 10
c 4
b 0
f 0
dl 0
loc 41
rs 10
ccs 0
cts 16
cp 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A replaceFieldsWith() 0 3 1
A getTemplate() 0 6 2
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