Conditions | 1 |
Paths | 1 |
Total Lines | 146 |
Code Lines | 95 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
42 | public function getStenography(Swagger $api, Route $route) |
||
43 | { |
||
44 | $paths = $api->getPaths(); |
||
45 | $paths->set(sprintf('/api/%s', $route->getDefault('_resource_name')), new Path([ |
||
46 | 'get' => [ |
||
47 | 'summary' => sprintf('Get %s index', $route->getDefault('_resource_name')), |
||
48 | 'parameters' => [ |
||
49 | [ |
||
50 | 'name' => 'page', |
||
51 | 'description' => 'Page to return', |
||
52 | 'in' => 'integer' |
||
53 | ], |
||
54 | [ |
||
55 | 'name' => 'sort', |
||
56 | 'description' => 'Field to sort', |
||
57 | 'in' => 'string' |
||
58 | ], |
||
59 | [ |
||
60 | 'name' => 'direction', |
||
61 | 'description' => 'Sort direction', |
||
62 | 'in' => 'string (asc|desc)' |
||
63 | ] |
||
64 | ], |
||
65 | 'responses' => [ |
||
66 | '200' => [ |
||
67 | 'description' => 'Successful operation', |
||
68 | ], |
||
69 | '403' => [ |
||
70 | 'description' => 'Access denied' |
||
71 | ], |
||
72 | '401' => [ |
||
73 | 'description' => 'Authorization required' |
||
74 | ] |
||
75 | ], |
||
76 | 'tags' => [$route->getDefault('_resource_name')] |
||
77 | ], |
||
78 | 'post' => [ |
||
79 | 'summary' => sprintf('Create %s', $route->getDefault('_resource_name')), |
||
80 | 'parameters' => $this->getCreateFormFields($route->getDefault('_entity')), |
||
81 | 'tags' => [$route->getDefault('_resource_name')], |
||
82 | 'responses' => [ |
||
83 | '200' => [ |
||
84 | 'description' => 'Successful operation', |
||
85 | ], |
||
86 | '403' => [ |
||
87 | 'description' => 'Access denied' |
||
88 | ], |
||
89 | '401' => [ |
||
90 | 'description' => 'Authorization required' |
||
91 | ] |
||
92 | ], |
||
93 | ] |
||
94 | ])); |
||
95 | $paths->set(sprintf('/api/%s/{id}', $route->getDefault('_resource_name')), new Path([ |
||
96 | 'get' => [ |
||
97 | 'summary' => sprintf('Get single %s', $route->getDefault('_resource_name')), |
||
98 | 'parameters' => [ |
||
99 | [ |
||
100 | 'name' => 'id', |
||
101 | 'description' => 'Resource identifier', |
||
102 | 'in' => 'integer' |
||
103 | ] |
||
104 | ], |
||
105 | 'responses' => [ |
||
106 | '200' => [ |
||
107 | 'description' => 'Successful operation' |
||
108 | ], |
||
109 | '403' => [ |
||
110 | 'description' => 'Access denied' |
||
111 | ], |
||
112 | '401' => [ |
||
113 | 'description' => 'Authorization required' |
||
114 | ] |
||
115 | ], |
||
116 | 'tags' => [$route->getDefault('_resource_name')] |
||
117 | ], |
||
118 | 'put' => [ |
||
119 | 'summary' => sprintf('Update %s', $route->getDefault('_resource_name')), |
||
120 | 'parameters' => array_merge( |
||
121 | [[ |
||
122 | 'name' => 'id', |
||
123 | 'description' => 'Resource identifier', |
||
124 | 'in' => 'integer' |
||
125 | ]], |
||
126 | $this->getUpdateFormFields($route->getDefault('_entity'))), |
||
127 | 'tags' => [$route->getDefault('_resource_name')] |
||
128 | ], |
||
129 | 'delete' => [ |
||
130 | 'summary' => sprintf('Delete %s', $route->getDefault('_resource_name')), |
||
131 | 'parameters' => [ |
||
132 | [ |
||
133 | 'name' => 'id', |
||
134 | 'description' => 'Resource identifier', |
||
135 | 'in' => 'integer' |
||
136 | ] |
||
137 | ], |
||
138 | 'responses' => [ |
||
139 | '204' => [ |
||
140 | 'description' => 'Successful operation' |
||
141 | ], |
||
142 | '403' => [ |
||
143 | 'description' => 'Access denied' |
||
144 | ], |
||
145 | '401' => [ |
||
146 | 'description' => 'Authorization required' |
||
147 | ] |
||
148 | ], |
||
149 | 'tags' => [$route->getDefault('_resource_name')] |
||
150 | ] |
||
151 | ])); |
||
152 | $paths->set(sprintf('/api/%s/filter', $route->getDefault('_resource_name')), new Path([ |
||
153 | 'get' => [ |
||
154 | 'summary' => 'Filter operation', |
||
155 | 'description' => "Filters payload should be base64 encoded json string\n Available filters are:\n" |
||
156 | ."|Parameter|Access|Type|\n" |
||
157 | ."|---------|------|----|\n". |
||
158 | implode("\n", $this->getAvailableFilterParams($route->getDefault('_entity'))), |
||
159 | 'parameters' => [ |
||
160 | [ |
||
161 | 'name' => 'page', |
||
162 | 'description' => 'Page to return', |
||
163 | 'in' => 'integer' |
||
164 | ], |
||
165 | [ |
||
166 | 'name' => 'sort', |
||
167 | 'description' => 'Field to sort', |
||
168 | 'in' => 'string' |
||
169 | ], |
||
170 | [ |
||
171 | 'name' => 'direction', |
||
172 | 'description' => 'Sort direction', |
||
173 | 'in' => 'string (asc|desc)' |
||
174 | ] |
||
175 | ], |
||
176 | 'responses' => [ |
||
177 | '200' => [ |
||
178 | 'description' => 'Successful operation', |
||
179 | ], |
||
180 | '403' => [ |
||
181 | 'description' => 'Access denied' |
||
182 | ], |
||
183 | '401' => [ |
||
184 | 'description' => 'Authorization required' |
||
185 | ] |
||
186 | ], |
||
187 | 'tags' => [$route->getDefault('_resource_name')] |
||
188 | ], |
||
273 |