Blueprint   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A make() 0 5 1
A setConfig() 0 4 1
1
<?php
2
3
namespace PrismX\Generators;
4
5
use Symfony\Component\Yaml\Yaml;
6
use Illuminate\Support\Facades\File;
7
use PrismX\Generators\Support\Lexer;
8
9
class Blueprint
10
{
11
    protected $contents;
12
13
    public static function make(string $filename)
14
    {
15
        $instance = new self($filename);
16
17
        return (new Lexer())->analyze($instance->contents['models'] ?? []);
18
    }
19
20
    public function __construct(string $file)
21
    {
22
        $content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?)$/mi', function ($matches) {
23
            return $matches[1].strtolower($matches[2]).': '.$matches[2];
24
        }, File::get($file));
25
26
        $this->contents = Yaml::parse($content);
27
        $this->setConfig();
28
    }
29
30
    protected function setConfig()
31
    {
32
        $config = array_merge(config('generators'), $this->contents['options'] ?? []);
33
        config(['generators' => $config]);
34
    }
35
}
36