CollectionGenerator::getVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace AlexWells\ApiDocsGenerator\Postman;
4
5
use Illuminate\Support\Collection;
6
7
class CollectionGenerator
8
{
9
    /**
10
     * @var array[]
11
     */
12
    private $routes;
13
14
    /**
15
     * CollectionGenerator constructor.
16
     *
17
     * @param array[] $routes
18
     */
19
    public function __construct(array $routes)
20
    {
21
        $this->routes = $routes;
22
    }
23
24
    /**
25
     * Return generated collection in JSON format.
26
     *
27
     * All information is available here: https://schema.getpostman.com/json/collection/v2.0.0/docs/index.html
28
     *
29
     * @return string
30
     */
31
    public function getCollection()
32
    {
33
        $collection = array_merge([
34
            'info' => [
35
                'name' => $this->getName(),
36
                'description' => $this->getDescription(),
37
                'version' => $this->getVersion(),
38
                'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
39
            ]
40
        ], $this->getFolder());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getFolder() targeting AlexWells\ApiDocsGenerat...nGenerator::getFolder() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
42
        return json_encode($collection);
43
    }
44
45
    protected function getFolder($name = null) {
46
        $folder = [
0 ignored issues
show
Unused Code introduced by
The assignment to $folder is dead and can be removed.
Loading history...
47
            'name' => $name,
48
            'variable' => $this->getVariables($name),
49
            'event' => $this->getEvents($name),
50
            'auth' => $this->getAuth($name),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getAuth($name) targeting AlexWells\ApiDocsGenerat...ionGenerator::getAuth() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51
            'item' => $this->getItems($folder)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $folder seems to be never defined.
Loading history...
52
        ];
53
    }
54
55
    protected function getItems(array $input, array $formatted = []) {
56
        foreach ($input as $route) {
57
            $resource = $route['resource'];
58
59
            while (count($resource) > 1) {
60
                $key = array_shift($resource);
0 ignored issues
show
Unused Code introduced by
The assignment to $key is dead and can be removed.
Loading history...
61
62
                $folder = $this->getFolder($resource);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $folder is correct as $this->getFolder($resource) targeting AlexWells\ApiDocsGenerat...nGenerator::getFolder() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
The assignment to $folder is dead and can be removed.
Loading history...
63
            }
64
65
            $array[array_shift($resource)] = $value;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value seems to be never defined.
Loading history...
66
67
            $formatted = array_merge($formatted, $array);
68
        }
69
70
        return [];
71
        /*$this->routeGroups->map(function ($routes, $groupName) {
72
            return [
73
                'name' => $groupName,
74
                'description' => '',
75
                'item' => $routes->map(function ($route) {
76
                    return [
77
                        'name' => $route['title'] != '' ? $route['title'] : url($route['uri']),
78
                        'request' => [
79
                            'url' => url($route['uri']),
80
                            'method' => $route['methods'][0],
81
                            'body' => [
82
                                'mode' => 'formdata',
83
                                'formdata' => collect($route['parameters']['query'])->map(function ($parameter) {
84
                                    return [
85
                                        'key' => $parameter['name'],
86
                                        'value' => '',
87
                                        'type' => collect($parameter['rules'])->contains(function ($rule) {
88
                                            return in_array($rule, ['file', 'image']);
89
                                            // TODO: advanced mime checks
90
                                        }) ? 'file' : 'text', // this check is fine for now
91
                                        'enabled' => true,
92
                                    ];
93
                                })->values()->toArray(),
94
                            ],
95
                            'description' => $route['description'],
96
                            'response' => [],
97
                        ],
98
                    ];
99
                })->toArray(),
100
            ];
101
        })->values()->toArray();*/
102
    }
103
104
    /**
105
     * Get display name.
106
     *
107
     * @return string
108
     */
109
    protected function getName() {
110
        return config('app.name');
111
    }
112
113
    /**
114
     * Get description.
115
     *
116
     * @return string|array
117
     */
118
    protected function getDescription() {
119
        return 'Automatically generated by laravel-api-docs-generator';
120
    }
121
122
    /**
123
     * Get version.
124
     *
125
     * @return string
126
     */
127
    protected function getVersion() {
128
        return '1.0.0';
129
    }
130
131
    /**
132
     * Get set of variables.
133
     *
134
     * @return array
135
     */
136
    protected function getVariables(string $folderName = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $folderName 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

136
    protected function getVariables(/** @scrutinizer ignore-unused */ string $folderName = null) {

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...
137
        return [];
138
    }
139
140
    /**
141
     * Get set of events.
142
     *
143
     * @return array
144
     */
145
    protected function getEvents(string $folderName = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $folderName 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

145
    protected function getEvents(/** @scrutinizer ignore-unused */ string $folderName = null) {

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...
146
        return [];
147
    }
148
149
    /**
150
     * Get auth.
151
     *
152
     * @return array|null
153
     */
154
    protected function getAuth(string $folderName = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $folderName 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

154
    protected function getAuth(/** @scrutinizer ignore-unused */ string $folderName = null) {

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...
155
        return null;
156
    }
157
}
158