@@ -23,8 +23,11 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public static function getLimit(Request $request) |
| 25 | 25 | { |
| 26 | - if ($request->has('limit')) return $request->limit; |
|
| 27 | - else return config('larastart.limit'); |
|
| 26 | + if ($request->has('limit')) { |
|
| 27 | + return $request->limit; |
|
| 28 | + } else { |
|
| 29 | + return config('larastart.limit'); |
|
| 30 | + } |
|
| 28 | 31 | } |
| 29 | 32 | |
| 30 | 33 | /** |
@@ -35,8 +38,9 @@ discard block |
||
| 35 | 38 | */ |
| 36 | 39 | public static function getDates($date) |
| 37 | 40 | { |
| 38 | - if (!$date instanceof Carbon) |
|
| 39 | - $date = Carbon::parse($date); |
|
| 41 | + if (!$date instanceof Carbon) { |
|
| 42 | + $date = Carbon::parse($date); |
|
| 43 | + } |
|
| 40 | 44 | return [ |
| 41 | 45 | 'approx' => $date->diffForHumans(), |
| 42 | 46 | 'formatted' => $date->format('D d M Y'), |
@@ -71,9 +75,14 @@ discard block |
||
| 71 | 75 | $pieces = \explode('/', $newName); |
| 72 | 76 | array_pop($pieces); |
| 73 | 77 | if (sizeof($pieces)) { |
| 74 | - if ($includeSlash) return '\\' . implode('\\', $pieces); |
|
| 75 | - else return implode('\\', $pieces); |
|
| 76 | - } else return ''; |
|
| 78 | + if ($includeSlash) { |
|
| 79 | + return '\\' . implode('\\', $pieces); |
|
| 80 | + } else { |
|
| 81 | + return implode('\\', $pieces); |
|
| 82 | + } |
|
| 83 | + } else { |
|
| 84 | + return ''; |
|
| 85 | + } |
|
| 77 | 86 | } |
| 78 | 87 | |
| 79 | 88 | public static function getModelNamespace(string $modelName): string |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | function successResponse() |
| 13 | 13 | { |
| 14 | - return function ($message, array $data = [], int $statusCode = 200) { |
|
| 14 | + return function($message, array $data = [], int $statusCode = 200) { |
|
| 15 | 15 | return response()->json(array_merge([ |
| 16 | 16 | 'success' => true, |
| 17 | 17 | 'message' => $message |
@@ -17,34 +17,34 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | function apiExceptions(Request $request, $exception, bool $rawError = false) |
| 19 | 19 | { |
| 20 | - if ($rawError) |
|
| 21 | - return parent::render($request, $exception); |
|
| 22 | - else { |
|
| 20 | + if ($rawError) { |
|
| 21 | + return parent::render($request, $exception); |
|
| 22 | + } else { |
|
| 23 | 23 | if ($exception instanceof ModelNotFoundException) { |
| 24 | 24 | $errorBody = [ |
| 25 | 25 | 'status' => Response::HTTP_NOT_FOUND, |
| 26 | 26 | 'code' => 'MOD_04', |
| 27 | 27 | 'message' => $exception->getMessage(), |
| 28 | 28 | ]; |
| 29 | - } else if ($exception instanceof NotFoundHttpException) |
|
| 30 | - $errorBody = [ |
|
| 29 | + } else if ($exception instanceof NotFoundHttpException) { |
|
| 30 | + $errorBody = [ |
|
| 31 | 31 | 'status' => Response::HTTP_NOT_FOUND, |
| 32 | 32 | 'code' => 'RT_04', |
| 33 | 33 | 'message' => 'Invalid route', |
| 34 | 34 | ]; |
| 35 | - else if ($exception instanceof InvalidArgumentException) |
|
| 36 | - $errorBody = [ |
|
| 35 | + } else if ($exception instanceof InvalidArgumentException) { |
|
| 36 | + $errorBody = [ |
|
| 37 | 37 | 'status' => Response::HTTP_NOT_ACCEPTABLE, |
| 38 | 38 | 'code' => 'AUT_01', |
| 39 | 39 | 'message' => 'Authorization code is empty.', |
| 40 | 40 | ]; |
| 41 | - else if ($exception instanceof MethodNotAllowedHttpException) |
|
| 42 | - $errorBody = [ |
|
| 41 | + } else if ($exception instanceof MethodNotAllowedHttpException) { |
|
| 42 | + $errorBody = [ |
|
| 43 | 43 | 'status' => Response::HTTP_METHOD_NOT_ALLOWED, |
| 44 | 44 | 'code' => 'MET_05', |
| 45 | 45 | 'message' => $exception->getMessage(), |
| 46 | 46 | ]; |
| 47 | - else if ($exception instanceof ValidationException) { |
|
| 47 | + } else if ($exception instanceof ValidationException) { |
|
| 48 | 48 | $messages = []; |
| 49 | 49 | foreach ($exception->errors() as $key => $error) { |
| 50 | 50 | foreach ($error as $key => $err) { |
@@ -56,24 +56,25 @@ discard block |
||
| 56 | 56 | 'code' => 'VAL_22', |
| 57 | 57 | 'message' => implode(PHP_EOL, $messages), |
| 58 | 58 | ]; |
| 59 | - } else if ($exception instanceof BadRequestHttpException) |
|
| 60 | - $errorBody = [ |
|
| 59 | + } else if ($exception instanceof BadRequestHttpException) { |
|
| 60 | + $errorBody = [ |
|
| 61 | 61 | 'status' => Response::HTTP_BAD_REQUEST, |
| 62 | 62 | 'code' => 'VAL_22', |
| 63 | 63 | 'message' => $exception->getMessage(), |
| 64 | 64 | ]; |
| 65 | - else if ($exception instanceof AuthorizationException) |
|
| 66 | - $errorBody = [ |
|
| 65 | + } else if ($exception instanceof AuthorizationException) { |
|
| 66 | + $errorBody = [ |
|
| 67 | 67 | 'status' => Response::HTTP_FORBIDDEN, |
| 68 | 68 | 'code' => 'AUT_02', |
| 69 | 69 | 'message' => $exception->getMessage(), |
| 70 | 70 | ]; |
| 71 | - else |
|
| 72 | - $errorBody = [ |
|
| 71 | + } else { |
|
| 72 | + $errorBody = [ |
|
| 73 | 73 | 'status' => Response::HTTP_INTERNAL_SERVER_ERROR, |
| 74 | 74 | 'code' => 'SER_00', |
| 75 | 75 | 'message' => $exception->getMessage(), |
| 76 | 76 | ]; |
| 77 | + } |
|
| 77 | 78 | return \response()->json($errorBody, $errorBody['status']); |
| 78 | 79 | } |
| 79 | 80 | } |
@@ -6,13 +6,17 @@ discard block |
||
| 6 | 6 | { |
| 7 | 7 | public function attemptLogin(array $credentials = [], string $guard = 'api') |
| 8 | 8 | { |
| 9 | - if (!sizeof($credentials)) |
|
| 10 | - $credentials = request(['email', 'password']); |
|
| 9 | + if (!sizeof($credentials)) { |
|
| 10 | + $credentials = request(['email', 'password']); |
|
| 11 | + } |
|
| 11 | 12 | |
| 12 | - if (!$guard) $guard = config('larastart.guard'); |
|
| 13 | + if (!$guard) { |
|
| 14 | + $guard = config('larastart.guard'); |
|
| 15 | + } |
|
| 13 | 16 | |
| 14 | - if (!$token = auth($guard)->attempt($credentials)) |
|
| 15 | - return $this->validationFailed(); |
|
| 17 | + if (!$token = auth($guard)->attempt($credentials)) { |
|
| 18 | + return $this->validationFailed(); |
|
| 19 | + } |
|
| 16 | 20 | |
| 17 | 21 | $class = config('larastart.resource'); |
| 18 | 22 | return [ |
@@ -29,7 +33,9 @@ discard block |
||
| 29 | 33 | { |
| 30 | 34 | $class = config('larastart.resource'); |
| 31 | 35 | |
| 32 | - if (!$guard) $guard = config('larastart.guard'); |
|
| 36 | + if (!$guard) { |
|
| 37 | + $guard = config('larastart.guard'); |
|
| 38 | + } |
|
| 33 | 39 | |
| 34 | 40 | return new $class(auth($guard)->user()); |
| 35 | 41 | } |
@@ -59,7 +59,9 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | try { |
| 61 | 61 | $this->getModel()->update($this->optimizeAttributes($attributes)); |
| 62 | - if ($returnObject) return $this->getModel(); |
|
| 62 | + if ($returnObject) { |
|
| 63 | + return $this->getModel(); |
|
| 64 | + } |
|
| 63 | 65 | return $this->successResponse($message); |
| 64 | 66 | } catch (\Exception $e) { |
| 65 | 67 | abort(500, $e->getMessage()); |
@@ -79,8 +81,9 @@ discard block |
||
| 79 | 81 | try { |
| 80 | 82 | $model = $this->getModel()->create($this->optimizeAttributes($attributes)); |
| 81 | 83 | |
| 82 | - if ($returnObject) |
|
| 83 | - return $model; |
|
| 84 | + if ($returnObject) { |
|
| 85 | + return $model; |
|
| 86 | + } |
|
| 84 | 87 | return $this->successResponse($message, [], 201); |
| 85 | 88 | } catch (\Exception $e) { |
| 86 | 89 | abort(500, $e->getMessage()); |
@@ -103,8 +106,9 @@ discard block |
||
| 103 | 106 | |
| 104 | 107 | try { |
| 105 | 108 | $this->getParent()->save($model); |
| 106 | - if ($returnObject) |
|
| 107 | - return $model; |
|
| 109 | + if ($returnObject) { |
|
| 110 | + return $model; |
|
| 111 | + } |
|
| 108 | 112 | return $this->successResponse($message, [], 201); |
| 109 | 113 | } catch (\Exception $e) { |
| 110 | 114 | abort(500, $e->getMessage()); |
@@ -119,12 +123,14 @@ discard block |
||
| 119 | 123 | */ |
| 120 | 124 | protected function optimizeAttributes(array $attributes) |
| 121 | 125 | { |
| 122 | - if (is_string($this->getUnsetFields())) |
|
| 123 | - unset($attributes[$this->getUnsetFields()]); |
|
| 126 | + if (is_string($this->getUnsetFields())) { |
|
| 127 | + unset($attributes[$this->getUnsetFields()]); |
|
| 128 | + } |
|
| 124 | 129 | |
| 125 | - if (is_array($this->getUnsetFields())) |
|
| 126 | - foreach ($this->getUnsetFields() as $field) { |
|
| 130 | + if (is_array($this->getUnsetFields())) { |
|
| 131 | + foreach ($this->getUnsetFields() as $field) { |
|
| 127 | 132 | unset($attributes[$field]); |
| 133 | + } |
|
| 128 | 134 | } |
| 129 | 135 | return $attributes; |
| 130 | 136 | } |
@@ -134,18 +140,22 @@ discard block |
||
| 134 | 140 | */ |
| 135 | 141 | private function getParent() |
| 136 | 142 | { |
| 137 | - if (\is_object($this->getParentRelationship())) return $this->getParentRelationship(); |
|
| 138 | - else if (\is_array($this->getParentRelationship())) { |
|
| 143 | + if (\is_object($this->getParentRelationship())) { |
|
| 144 | + return $this->getParentRelationship(); |
|
| 145 | + } else if (\is_array($this->getParentRelationship())) { |
|
| 139 | 146 | $class = $this->getParentRelationship()['0']; |
| 140 | 147 | $relationship = $this->getParentRelationship()['1']; |
| 141 | 148 | |
| 142 | - if (sizeof($this->getParentRelationship()) > 2) $parent = $class::findOrFail(request($this->getParentRelationship()['2'])); |
|
| 143 | - else { |
|
| 149 | + if (sizeof($this->getParentRelationship()) > 2) { |
|
| 150 | + $parent = $class::findOrFail(request($this->getParentRelationship()['2'])); |
|
| 151 | + } else { |
|
| 144 | 152 | $_class = new $class(); |
| 145 | 153 | $parent = $class::findOrFail(request($_class->getForeignKey())); |
| 146 | 154 | } |
| 147 | 155 | |
| 148 | 156 | return $parent->$relationship(); |
| 149 | - } else throw new InvalidArgumentException('You have set an invalid parent for this model'); |
|
| 157 | + } else { |
|
| 158 | + throw new InvalidArgumentException('You have set an invalid parent for this model'); |
|
| 159 | + } |
|
| 150 | 160 | } |
| 151 | 161 | } |
@@ -23,9 +23,11 @@ |
||
| 23 | 23 | |
| 24 | 24 | function getStub() |
| 25 | 25 | { |
| 26 | - if ($this->hasArgument('name')) |
|
| 27 | - return __DIR__ . '/stubs/FullService.stub'; |
|
| 28 | - else return __DIR__ . '/stubs/PlainService.stub'; |
|
| 26 | + if ($this->hasArgument('name')) { |
|
| 27 | + return __DIR__ . '/stubs/FullService.stub'; |
|
| 28 | + } else { |
|
| 29 | + return __DIR__ . '/stubs/PlainService.stub'; |
|
| 30 | + } |
|
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | public function getModel() |
@@ -40,7 +40,9 @@ |
||
| 40 | 40 | if (!$this->filesystem->isFile($this->getPath() . '/' . $this->getFilename())) { |
| 41 | 41 | $this->warn(Helper::getFileName($this->argument('name')) . ' created'); |
| 42 | 42 | return $this->filesystem->put($this->getPath() . '/' . $this->getFilename(), $this->getReplaceContent()); |
| 43 | - } else $this->warn(Helper::getFileName($this->argument('name')) . ' already exist'); |
|
| 43 | + } else { |
|
| 44 | + $this->warn(Helper::getFileName($this->argument('name')) . ' already exist'); |
|
| 45 | + } |
|
| 44 | 46 | } |
| 45 | 47 | |
| 46 | 48 | /** |