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

InterfaceGenerator::rollback()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 0
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