RequestGenerator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getPathConfigNode() 0 3 1
A getReplacements() 0 10 2
A getBasePath() 0 3 1
A getPath() 0 8 1
A getRules() 0 14 4
A getRootNamespace() 0 4 1
1
<?php
2
3
namespace Yeelight\Generators;
4
5
/**
6
 * Class RequestGenerator
7
 *
8
 * @category Yeelight
9
 *
10
 * @package Yeelight\Generators
11
 *
12
 * @author Sheldon Lee <[email protected]>
13
 *
14
 * @license https://opensource.org/licenses/MIT MIT
15
 *
16
 * @link https://www.yeelight.com
17
 */
18
class RequestGenerator extends Generator
19
{
20
    /**
21
     * Get stub name.
22
     *
23
     * @var string
24
     */
25
    protected $stub = 'request/request';
26
27
    /**
28
     * Get root namespace.
29
     *
30
     * @return string
31
     */
32
    public function getRootNamespace()
33
    {
34
        return parent::getRootNamespace() .
35
            parent::getConfigGeneratorClassPath($this->getPathConfigNode());
0 ignored issues
show
Bug introduced by
Are you sure parent::getConfigGenerat...s->getPathConfigNode()) of type Illuminate\Config\Repository|mixed can be used in concatenation? ( Ignorable by Annotation )

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

35
            /** @scrutinizer ignore-type */ parent::getConfigGeneratorClassPath($this->getPathConfigNode());
Loading history...
36
    }
37
38
    /**
39
     * Get generator path config node.
40
     *
41
     * @return string
42
     */
43
    public function getPathConfigNode()
44
    {
45
        return 'requests';
46
    }
47
48
    /**
49
     * Get destination path for generated file.
50
     *
51
     * @return string
52
     */
53
    public function getPath()
54
    {
55
        return $this->getBasePath() .
56
            '/' .
57
            parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true) .
0 ignored issues
show
Bug introduced by
Are you sure parent::getConfigGenerat...PathConfigNode(), true) of type Illuminate\Config\Repository|mixed can be used in concatenation? ( Ignorable by Annotation )

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

57
            /** @scrutinizer ignore-type */ parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true) .
Loading history...
58
            '/' .
59
            $this->getName() .
60
            'Request.php';
61
    }
62
63
    /**
64
     * Get base path of destination file.
65
     *
66
     * @return string
67
     */
68
    public function getBasePath()
69
    {
70
        return config('repository.generator.basePath', app_path());
71
    }
72
73
    /**
74
     * Get default Columns description.
75
     *
76
     * @return string
77
     */
78
    public function getRules()
79
    {
80
        if (!$this->fields) {
0 ignored issues
show
Bug Best Practice introduced by
The property fields does not exist on Yeelight\Generators\RequestGenerator. Since you implemented __get, consider adding a @property annotation.
Loading history...
81
            return '[]';
82
        }
83
        $results = '['.PHP_EOL;
84
85
        foreach ($this->fields as $column => $field) {
86
            if (isset($field['rule'])) {
87
                $results .= "\t\t\t'{$field['name']}' => '{$field['rule']}',".PHP_EOL;
88
            }
89
        }
90
91
        return $results."\t\t".']';
92
    }
93
94
    /**
95
     * Get array replacements.
96
     *
97
     * @return array
98
     */
99
    public function getReplacements()
100
    {
101
        $type = $this->type;
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist on Yeelight\Generators\RequestGenerator. Since you implemented __get, consider adding a @property annotation.
Loading history...
102
        $formRequest = $type == 'api' ? 'Dingo\Api\Http\FormRequest' : 'Illuminate\Foundation\Http\FormRequest';
103
104
        return array_merge(
105
            parent::getReplacements(),
106
            [
107
                'form_request' => $formRequest,
108
                'request_rules' => $this->getRules(),
109
            ]
110
        );
111
    }
112
}
113