Passed
Push — master ( 0b2a3d...a47e04 )
by Bruno
17:31 queued 04:58
created

FrontendGenerator::makeVueRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Frontend;
4
5
use Formularium\Model;
6
use Formularium\FrameworkComposer;
7
use Formularium\Frontend\Blade\Framework as FrameworkBlade;
8
use Formularium\Frontend\Vue\Framework as FrameworkVue;
9
use Modelarium\GeneratedCollection;
10
use Modelarium\GeneratedItem;
11
use Modelarium\GeneratorInterface;
12
use Modelarium\GeneratorNameTrait;
13
14
use function Safe\file_get_contents;
15
16
class FrontendGenerator implements GeneratorInterface
17
{
18
    use GeneratorNameTrait;
19
20
    /**
21
     * @var FrameworkComposer
22
     */
23
    protected $composer = null;
24
25
    /**
26
     * @var Model
27
     */
28
    protected $model = null;
29
30
    /**
31
     * @var GeneratedCollection
32
     */
33
    protected $collection;
34
35
    /**
36
     *
37
     * @var string
38
     */
39
    protected $stubDir = __DIR__ . '/stubs';
40
41
    public function __construct(FrameworkComposer $composer, Model $model)
42
    {
43
        $this->composer = $composer;
44
        $this->model = $model;
45
        $this->setName($model->getName());
46
    }
47
48
    public function generate(): GeneratedCollection
49
    {
50
        $this->collection = new GeneratedCollection();
51
52
        /**
53
         * @var FrameworkVue $vue
54
         */
55
        $vue = $this->composer->getByName('Vue');
56
        // $blade = FrameworkComposer::getByName('Blade');
57
58
        if ($vue !== null) {
59
            $this->makeVue($vue, 'Base', 'viewable');
60
            $this->makeVue($vue, 'Card', 'viewable');
61
            $this->makeVue($vue, 'List', 'viewable');
62
            $this->makeVue($vue, 'Show', 'viewable');
63
            $this->makeVue($vue, 'Form', 'editable');
64
            $this->makeVueRouter();
0 ignored issues
show
Bug introduced by
The method makeVueRouter() does not exist on Modelarium\Frontend\FrontendGenerator. Did you maybe mean makeVue()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            $this->/** @scrutinizer ignore-call */ 
65
                   makeVueRouter();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
        }
66
67
        return $this->collection;
68
    }
69
70
    protected function makeVue(FrameworkVue $vue, string $component, string $mode): void
71
    {
72
        $path = $this->model->getName() . '/' .
73
            $this->model->getName() . $component . '.vue';
74
        $stub = file_get_contents($this->stubDir . "/Vue{$component}.stub.vue");
75
        if ($mode == 'editable') {
76
            $vue->setEditableTemplate($stub);
77
            $this->collection->push(
78
                new GeneratedItem(
79
                    GeneratedItem::TYPE_FRONTEND,
80
                    $this->model->editable($this->composer),
81
                    $path
82
                )
83
            );
84
        } else {
85
            $vue->setViewableTemplate($stub);
86
            $this->collection->push(
87
                new GeneratedItem(
88
                    GeneratedItem::TYPE_FRONTEND,
89
                    $this->model->viewable($this->composer, []),
90
                    $path
91
                )
92
            );
93
        }
94
    }
95
96
    protected function makeVueRoutes(string $component, string $mode): void
0 ignored issues
show
Unused Code introduced by
The parameter $mode is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

96
    protected function makeVueRoutes(string $component, /** @scrutinizer ignore-unused */ string $mode): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $component is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

96
    protected function makeVueRoutes(/** @scrutinizer ignore-unused */ string $component, string $mode): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
    {
98
        $path = $this->model->getName() . '/routes.js';
99
        $stub = file_get_contents($this->stubDir . "/routes.stub.js");
100
101
        $this->collection->push(
102
            new GeneratedItem(
103
                GeneratedItem::TYPE_FRONTEND,
104
                $this->template($stub),
105
                $path
106
            )
107
        );
108
    }
109
}
110