Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.

Commit 3b58052

Browse files
committed
cs
1 parent cb8304a commit 3b58052

File tree

6 files changed

+61
-68
lines changed

6 files changed

+61
-68
lines changed

src/Generator/ApiMakeCommand.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ApiMakeCommand extends Command
5151
/**
5252
* Create a new controller creator command instance.
5353
*
54-
* @param \Illuminate\Filesystem\Filesystem $files
54+
* @param \Illuminate\Filesystem\Filesystem $files
5555
*/
5656
public function __construct(Filesystem $files)
5757
{
@@ -102,8 +102,7 @@ protected function prepareVariablesForStubs($name)
102102
*/
103103
protected function setModelData($name)
104104
{
105-
if (str_contains($name, '/'))
106-
{
105+
if (str_contains($name, '/')) {
107106
$name = $this->convertSlashes($name);
108107
}
109108

@@ -135,10 +134,9 @@ protected function setControllerData()
135134
return $this;
136135
}
137136

138-
139137
/**
140138
* Set route data for a given model.
141-
* "Profile\Payer" -> "profile_payers"
139+
* "Profile\Payer" -> "profile_payers".
142140
*
143141
* @return $this
144142
*/
@@ -193,11 +191,11 @@ protected function addRoutes()
193191

194192
// read file
195193
$lines = file($routesFile);
196-
$lastLine = $lines[count($lines)-1];
194+
$lastLine = $lines[count($lines) - 1];
197195

198196
// modify file
199-
if (strcmp($lastLine, "});") === 0) {
200-
$lines[count($lines)-1] = " ".$stub;
197+
if (strcmp($lastLine, '});') === 0) {
198+
$lines[count($lines) - 1] = ' '.$stub;
201199
$lines[] = "\r\n});";
202200
} else {
203201
$lines[] = "\r\n".$stub;
@@ -215,13 +213,15 @@ protected function addRoutes()
215213
* Create class with a given type.
216214
*
217215
* @param $type
216+
*
218217
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
219218
*/
220219
protected function createClass($type)
221220
{
222221
$path = $this->getPath($this->stubVariables[$type.'FullName']);
223222
if ($this->files->exists($path)) {
224223
$this->error(ucfirst($type).' already exists!');
224+
225225
return;
226226
}
227227

@@ -235,7 +235,8 @@ protected function createClass($type)
235235
/**
236236
* Get the destination file path.
237237
*
238-
* @param string $name
238+
* @param string $name
239+
*
239240
* @return string
240241
*/
241242
protected function getPath($name)
@@ -248,22 +249,23 @@ protected function getPath($name)
248249
/**
249250
* Build the directory for the class if needed.
250251
*
251-
* @param string $path
252+
* @param string $path
253+
*
252254
* @return string
253255
*/
254256
protected function makeDirectoryIfNeeded($path)
255257
{
256-
if ( ! $this->files->isDirectory(dirname($path)))
257-
{
258+
if (!$this->files->isDirectory(dirname($path))) {
258259
$this->files->makeDirectory(dirname($path), 0777, true, true);
259260
}
260261
}
261262

262263
/**
263264
* Get stub content and replace all stub placeholders
264-
* with data from $this->stubData
265+
* with data from $this->stubData.
266+
*
267+
* @param string $path
265268
*
266-
* @param string $path
267269
* @return string
268270
*/
269271
protected function constructStub($path)
@@ -293,10 +295,11 @@ protected function getArguments()
293295
* Convert "/" to "\".
294296
*
295297
* @param $string
298+
*
296299
* @return string
297300
*/
298301
protected function convertSlashes($string)
299302
{
300303
return str_replace('/', '\\', $string);
301304
}
302-
}
305+
}

src/ServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class ServiceProvider extends \Illuminate\Support\ServiceProvider
88
{
9-
109
/**
1110
* Register the service provider.
1211
*

src/Skeleton/BaseController.php

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class BaseController extends LaravelController
4343
/**
4444
* Do we need to unguard the model before create/update?
4545
*
46-
* @var boolean
46+
* @var bool
4747
*/
4848
protected $unguard = false;
4949

@@ -54,10 +54,9 @@ public function __construct()
5454
{
5555
$this->model = $this->model();
5656
$this->transformer = $this->transformer();
57-
$this->fractal = new Manager;
57+
$this->fractal = new Manager();
5858

59-
if (Input::has('include'))
60-
{
59+
if (Input::has('include')) {
6160
$this->fractal->parseIncludes(camel_case(Input::get('include')));
6261
}
6362
}
@@ -134,7 +133,6 @@ protected function respondWithCollection($collection, $callback)
134133
return $this->respondWithArray($rootScope->toArray());
135134
}
136135

137-
138136
/**
139137
* Respond with a given array of items.
140138
*
@@ -161,14 +159,15 @@ protected function respondWithError($message)
161159
'error' => [
162160
'http_code' => $this->statusCode,
163161
'message' => $message,
164-
]
162+
],
165163
]);
166164
}
167165

168166
/**
169167
* Prepare root scope and adds meta.
170168
*
171169
* @param Item $resource
170+
*
172171
* @return mixed
173172
*/
174173
protected function prepareRootScope($resource)
@@ -196,6 +195,7 @@ protected function rulesForCreate()
196195
* Get the validation rules for update.
197196
*
198197
* @param $id
198+
*
199199
* @return array
200200
*/
201201
protected function rulesForUpdate($id)
@@ -208,7 +208,7 @@ protected function rulesForUpdate($id)
208208
*
209209
* @param $message
210210
*
211-
* @return Response
211+
* @return Response
212212
*/
213213
public function errorForbidden($message = 'Forbidden')
214214
{
@@ -220,7 +220,7 @@ public function errorForbidden($message = 'Forbidden')
220220
*
221221
* @param $message
222222
*
223-
* @return Response
223+
* @return Response
224224
*/
225225
public function errorInternalError($message = 'Internal Error')
226226
{
@@ -232,7 +232,7 @@ public function errorInternalError($message = 'Internal Error')
232232
*
233233
* @param $message
234234
*
235-
* @return Response
235+
* @return Response
236236
*/
237237
public function errorNotFound($message = 'Resource Not Found')
238238
{
@@ -244,7 +244,7 @@ public function errorNotFound($message = 'Resource Not Found')
244244
*
245245
* @param $message
246246
*
247-
* @return Response
247+
* @return Response
248248
*/
249249
public function errorUnauthorized($message = 'Unauthorized')
250250
{
@@ -256,7 +256,7 @@ public function errorUnauthorized($message = 'Unauthorized')
256256
*
257257
* @param $message
258258
*
259-
* @return Response
259+
* @return Response
260260
*/
261261
public function errorWrongArgs($message = 'Wrong Arguments')
262262
{
@@ -268,7 +268,7 @@ public function errorWrongArgs($message = 'Wrong Arguments')
268268
*
269269
* @param $message
270270
*
271-
* @return Response
271+
* @return Response
272272
*/
273273
public function errorNotImplemented($message = 'Not implemented')
274274
{
@@ -277,32 +277,31 @@ public function errorNotImplemented($message = 'Not implemented')
277277

278278
/**
279279
* Display a listing of the resource.
280-
* GET /api/{resource}
280+
* GET /api/{resource}.
281281
*
282282
* @return Response
283283
*/
284284
public function index()
285285
{
286-
$with = $this->getEagerLoad();
286+
$with = $this->getEagerLoad();
287287
$items = $this->model->with($with)->get();
288288

289289
return $this->respondWithCollection($items, $this->transformer);
290290
}
291291

292292
/**
293293
* Store a newly created resource in storage.
294-
* POST /api/{resource}
294+
* POST /api/{resource}.
295295
*
296296
* @return Response
297297
*/
298298
public function store()
299299
{
300300
$input = Input::json();
301-
$data = $input->get('data');
301+
$data = $input->get('data');
302302

303303
$v = Validator::make($data, $this->rulesForCreate());
304-
if ($v->fails())
305-
{
304+
if ($v->fails()) {
306305
return $this->errorWrongArgs('Validation failed');
307306
}
308307

@@ -315,9 +314,9 @@ public function store()
315314

316315
/**
317316
* Display the specified resource.
318-
* GET /api/{resource}/{id}
317+
* GET /api/{resource}/{id}.
319318
*
320-
* @param int $id
319+
* @param int $id
321320
*
322321
* @return Response
323322
*/
@@ -326,8 +325,7 @@ public function show($id)
326325
$with = $this->getEagerLoad();
327326

328327
$item = $this->findItem($id, $with);
329-
if (!$item)
330-
{
328+
if (!$item) {
331329
return $this->errorNotFound();
332330
}
333331

@@ -336,31 +334,28 @@ public function show($id)
336334

337335
/**
338336
* Update the specified resource in storage.
339-
* PUT /api/{resource}/{id}
337+
* PUT /api/{resource}/{id}.
340338
*
341-
* @param int $id
339+
* @param int $id
342340
*
343341
* @return Response
344342
*/
345343
public function update($id)
346344
{
347345
$input = Input::json();
348-
$data = $input->get('data');
346+
$data = $input->get('data');
349347

350-
if (!$data)
351-
{
348+
if (!$data) {
352349
return $this->errorWrongArgs('Empty data');
353350
}
354351

355352
$item = $this->findItem($id);
356-
if (!$item)
357-
{
353+
if (!$item) {
358354
return $this->errorNotFound();
359355
}
360356

361357
$v = Validator::make($data, $this->rulesForUpdate($item->id));
362-
if ($v->fails())
363-
{
358+
if ($v->fails()) {
364359
return $this->errorWrongArgs('Validation failed');
365360
}
366361

@@ -374,18 +369,17 @@ public function update($id)
374369

375370
/**
376371
* Remove the specified resource from storage.
377-
* DELETE /api/{resource}/{id}
372+
* DELETE /api/{resource}/{id}.
378373
*
379-
* @param int $id
374+
* @param int $id
380375
*
381376
* @return Response
382377
*/
383378
public function destroy($id)
384379
{
385380
$item = $this->findItem($id);
386381

387-
if (!$item)
388-
{
382+
if (!$item) {
389383
return $this->errorNotFound();
390384
}
391385

@@ -407,7 +401,8 @@ public function create()
407401
/**
408402
* Show the form for editing the specified resource.
409403
*
410-
* @param int $id
404+
* @param int $id
405+
*
411406
* @return Response
412407
*/
413408
public function edit($id)
@@ -422,7 +417,7 @@ public function edit($id)
422417
*/
423418
protected function getEagerLoad()
424419
{
425-
$include = camel_case(Input::get('include', ''));
420+
$include = camel_case(Input::get('include', ''));
426421
$includes = explode(',', $include);
427422
$includes = array_filter($includes);
428423

@@ -439,8 +434,7 @@ protected function getEagerLoad()
439434
*/
440435
protected function findItem($id, array $with = [])
441436
{
442-
if (Input::has('use_as_id'))
443-
{
437+
if (Input::has('use_as_id')) {
444438
return $this->model->with($with)->where(Input::get('use_as_id'), '=', $id)->first();
445439
}
446440

@@ -452,9 +446,8 @@ protected function findItem($id, array $with = [])
452446
*/
453447
protected function unguardIfNeeded()
454448
{
455-
if ($this->unguard)
456-
{
449+
if ($this->unguard) {
457450
$this->model->unguard();
458451
}
459452
}
460-
}
453+
}

0 commit comments

Comments
 (0)