Passed
Push — master ( 48aa9a...5ad1d2 )
by Richard
10:34
created

InterfaceGenerator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
c 0
b 0
f 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rollback() 0 4 2
A __construct() 0 5 1
A generate() 0 20 3
1
<?php
2
3
namespace PWWEB\Artomator\Generators;
4
5
use InfyOm\Generator\Generators\BaseGenerator;
6
use InfyOm\Generator\Utils\FileUtil;
7
use PWWEB\Artomator\Common\CommandData;
8
9
class InterfaceGenerator extends BaseGenerator
10
{
11
    /** @var CommandData */
12
    private $commandData;
13
14
    /** @var string */
15
    private $path;
16
17
    /** @var string */
18
    private $fileName;
19
20
    public function __construct(CommandData $commandData)
21
    {
22
        $this->commandData = $commandData;
23
        $this->path = $commandData->config->pathInterface;
24
        $this->fileName = $this->commandData->modelName.'RepositoryInterface.php';
25
    }
26
27
    public function generate()
28
    {
29
        $templateData = get_artomator_template('interface');
30
31
        $templateData = fill_template($this->commandData->dynamicVars, $templateData);
32
33
        $searchables = [];
34
35
        foreach ($this->commandData->fields as $field) {
36
            if ($field->isSearchable) {
37
                $searchables[] = "'".$field->name."'";
38
            }
39
        }
40
41
        $templateData = str_replace('$FIELDS$', implode(','.infy_nl_tab(1, 2), $searchables), $templateData);
42
43
        FileUtil::createFile($this->path, $this->fileName, $templateData);
44
45
        $this->commandData->commandComment("\nRepository Interface created: ");
46
        $this->commandData->commandInfo($this->fileName);
47
    }
48
49
    public function rollback()
50
    {
51
        if ($this->rollbackFile($this->path, $this->fileName)) {
52
            $this->commandData->commandComment('Repository Interface file deleted: '.$this->fileName);
53
        }
54
    }
55
}
56