@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param \Flugg\Responder\Http\Responses\SuccessResponseBuilder $successResponseBuilder |
| 36 | 36 | * @param \Flugg\Responder\Http\Responses\ErrorResponseBuilder $errorResponseBuilder |
| 37 | 37 | */ |
| 38 | - public function __construct(SuccessResponseBuilder $successResponseBuilder, ErrorResponseBuilder $errorResponseBuilder) |
|
| 38 | + public function __construct( SuccessResponseBuilder $successResponseBuilder, ErrorResponseBuilder $errorResponseBuilder ) |
|
| 39 | 39 | { |
| 40 | 40 | $this->successResponseBuilder = $successResponseBuilder; |
| 41 | 41 | $this->errorResponseBuilder = $errorResponseBuilder; |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * @param string|null $resourceKey |
| 50 | 50 | * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder |
| 51 | 51 | */ |
| 52 | - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder |
|
| 52 | + public function success( $data = null, $transformer = null, string $resourceKey = null ): SuccessResponseBuilder |
|
| 53 | 53 | { |
| 54 | - return $this->successResponseBuilder->transform($data, $transformer, $resourceKey); |
|
| 54 | + return $this->successResponseBuilder->transform( $data, $transformer, $resourceKey ); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @param string|null $message |
| 62 | 62 | * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder |
| 63 | 63 | */ |
| 64 | - public function error(string $errorCode = null, string $message = null): ErrorResponseBuilder |
|
| 64 | + public function error( string $errorCode = null, string $message = null ): ErrorResponseBuilder |
|
| 65 | 65 | { |
| 66 | - return $this->errorResponseBuilder->error($errorCode, $message); |
|
| 66 | + return $this->errorResponseBuilder->error( $errorCode, $message ); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @param string|null $resourceKey |
| 23 | 23 | * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder |
| 24 | 24 | */ |
| 25 | - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder; |
|
| 25 | + public function success( $data = null, $transformer = null, string $resourceKey = null ): SuccessResponseBuilder; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Build an error response. |
@@ -31,5 +31,5 @@ discard block |
||
| 31 | 31 | * @param string|null $message |
| 32 | 32 | * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder |
| 33 | 33 | */ |
| 34 | - public function error(string $errorCode = null, string $message = null): ErrorResponseBuilder; |
|
| 34 | + public function error( string $errorCode = null, string $message = null ): ErrorResponseBuilder; |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | protected function getStub() |
| 45 | 45 | { |
| 46 | - if ($this->option('model')) { |
|
| 46 | + if ( $this->option( 'model' ) ) { |
|
| 47 | 47 | return __DIR__ . '/../../resources/stubs/transformer.model.stub'; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param string $rootNamespace |
| 57 | 57 | * @return string |
| 58 | 58 | */ |
| 59 | - protected function getDefaultNamespace($rootNamespace) |
|
| 59 | + protected function getDefaultNamespace( $rootNamespace ) |
|
| 60 | 60 | { |
| 61 | 61 | return $rootNamespace . '\Transformers'; |
| 62 | 62 | } |
@@ -67,19 +67,19 @@ discard block |
||
| 67 | 67 | * @param string $name |
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | - protected function buildClass($name) |
|
| 70 | + protected function buildClass( $name ) |
|
| 71 | 71 | { |
| 72 | - $replace = []; |
|
| 72 | + $replace = [ ]; |
|
| 73 | 73 | |
| 74 | - if (! $this->option('model') && ! $this->option('plain')) { |
|
| 75 | - $this->input->setOption('model', $this->resolveModelFromClassName()); |
|
| 74 | + if ( ! $this->option( 'model' ) && ! $this->option( 'plain' ) ) { |
|
| 75 | + $this->input->setOption( 'model', $this->resolveModelFromClassName() ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ($this->option('model')) { |
|
| 79 | - $replace = $this->buildModelReplacements($replace); |
|
| 78 | + if ( $this->option( 'model' ) ) { |
|
| 79 | + $replace = $this->buildModelReplacements( $replace ); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - return str_replace(array_keys($replace), array_values($replace), parent::buildClass($name)); |
|
| 82 | + return str_replace( array_keys( $replace ), array_values( $replace ), parent::buildClass( $name ) ); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | protected function resolveModelFromClassName() |
| 91 | 91 | { |
| 92 | - return 'App\\' . str_replace('Transformer', '', array_last(explode('/', $this->getNameInput()))); |
|
| 92 | + return 'App\\' . str_replace( 'Transformer', '', array_last( explode( '/', $this->getNameInput() ) ) ); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -98,19 +98,19 @@ discard block |
||
| 98 | 98 | * @param array $replace |
| 99 | 99 | * @return array |
| 100 | 100 | */ |
| 101 | - protected function buildModelReplacements(array $replace) |
|
| 101 | + protected function buildModelReplacements( array $replace ) |
|
| 102 | 102 | { |
| 103 | - if (! class_exists($modelClass = $this->parseModel($this->option('model')))) { |
|
| 104 | - if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) { |
|
| 105 | - $this->call('make:model', ['name' => $modelClass]); |
|
| 103 | + if ( ! class_exists( $modelClass = $this->parseModel( $this->option( 'model' ) ) ) ) { |
|
| 104 | + if ( $this->confirm( "A {$modelClass} model does not exist. Do you want to generate it?", true ) ) { |
|
| 105 | + $this->call( 'make:model', [ 'name' => $modelClass ] ); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - return array_merge($replace, [ |
|
| 109 | + return array_merge( $replace, [ |
|
| 110 | 110 | 'DummyFullModelClass' => $modelClass, |
| 111 | - 'DummyModelClass' => class_basename($modelClass), |
|
| 112 | - 'DummyModelVariable' => lcfirst(class_basename($modelClass)), |
|
| 113 | - ]); |
|
| 111 | + 'DummyModelClass' => class_basename( $modelClass ), |
|
| 112 | + 'DummyModelVariable' => lcfirst( class_basename( $modelClass ) ), |
|
| 113 | + ] ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -119,15 +119,15 @@ discard block |
||
| 119 | 119 | * @param string $model |
| 120 | 120 | * @return string |
| 121 | 121 | */ |
| 122 | - protected function parseModel($model) |
|
| 122 | + protected function parseModel( $model ) |
|
| 123 | 123 | { |
| 124 | - if (preg_match('([^A-Za-z0-9_/\\\\])', $model)) { |
|
| 125 | - throw new InvalidArgumentException('Model name contains invalid characters.'); |
|
| 124 | + if ( preg_match( '([^A-Za-z0-9_/\\\\])', $model ) ) { |
|
| 125 | + throw new InvalidArgumentException( 'Model name contains invalid characters.' ); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $model = trim(str_replace('/', '\\', $model), '\\'); |
|
| 128 | + $model = trim( str_replace( '/', '\\', $model ), '\\' ); |
|
| 129 | 129 | |
| 130 | - if (! Str::startsWith($model, $rootNamespace = $this->laravel->getNamespace())) { |
|
| 130 | + if ( ! Str::startsWith( $model, $rootNamespace = $this->laravel->getNamespace() ) ) { |
|
| 131 | 131 | $model = $rootNamespace . $model; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | protected function getOptions() |
| 143 | 143 | { |
| 144 | 144 | return [ |
| 145 | - ['model', 'm', InputOption::VALUE_OPTIONAL, 'Generate a model transformer.'], |
|
| 146 | - ['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain transformer.'], |
|
| 145 | + [ 'model', 'm', InputOption::VALUE_OPTIONAL, 'Generate a model transformer.' ], |
|
| 146 | + [ 'plain', 'p', InputOption::VALUE_NONE, 'Generate a plain transformer.' ], |
|
| 147 | 147 | ]; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | \ No newline at end of file |
@@ -101,7 +101,7 @@ |
||
| 101 | 101 | protected function buildModelReplacements(array $replace) |
| 102 | 102 | { |
| 103 | 103 | if (! class_exists($modelClass = $this->parseModel($this->option('model')))) { |
| 104 | - if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) { |
|
| 104 | + if ($this->confirm("a {$modelClass} model does not exist. Do you want to generate it?", true)) { |
|
| 105 | 105 | $this->call('make:model', ['name' => $modelClass]); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | * @param string|null $resourceKey |
| 24 | 24 | * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder |
| 25 | 25 | */ |
| 26 | - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder |
|
| 26 | + public function success( $data = null, $transformer = null, string $resourceKey = null ): SuccessResponseBuilder |
|
| 27 | 27 | { |
| 28 | - return app(Responder::class)->success(...func_get_args()); |
|
| 28 | + return app( Responder::class )->success( ...func_get_args() ); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * @param string|null $message |
| 36 | 36 | * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder |
| 37 | 37 | */ |
| 38 | - public function error(string $errorCode = null, string $message = null): ErrorResponseBuilder |
|
| 38 | + public function error( string $errorCode = null, string $message = null ): ErrorResponseBuilder |
|
| 39 | 39 | { |
| 40 | - return app(Responder::class)->error(...func_get_args()); |
|
| 40 | + return app( Responder::class )->error( ...func_get_args() ); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @var array |
| 34 | 34 | */ |
| 35 | - protected $dontConvert = []; |
|
| 35 | + protected $dontConvert = [ ]; |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Convert an exception to another exception |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | * @param array $convert |
| 42 | 42 | * @return void |
| 43 | 43 | */ |
| 44 | - protected function convert(Exception $exception, array $convert) |
|
| 44 | + protected function convert( Exception $exception, array $convert ) |
|
| 45 | 45 | { |
| 46 | - foreach ($convert as $source => $target) { |
|
| 47 | - if ($exception instanceof $source) { |
|
| 48 | - if (is_callable($target)) { |
|
| 49 | - $target($exception); |
|
| 46 | + foreach ( $convert as $source => $target ) { |
|
| 47 | + if ( $exception instanceof $source ) { |
|
| 48 | + if ( is_callable( $target ) ) { |
|
| 49 | + $target( $exception ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | throw new $target; |
@@ -60,18 +60,18 @@ discard block |
||
| 60 | 60 | * @param \Exception $exception |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - protected function convertDefaultException(Exception $exception) |
|
| 63 | + protected function convertDefaultException( Exception $exception ) |
|
| 64 | 64 | { |
| 65 | - $this->convert($exception, array_diff_key([ |
|
| 65 | + $this->convert( $exception, array_diff_key( [ |
|
| 66 | 66 | AuthenticationException::class => UnauthenticatedException::class, |
| 67 | 67 | AuthorizationException::class => UnauthorizedException::class, |
| 68 | 68 | NotFoundHttpException::class => PageNotFoundException::class, |
| 69 | 69 | ModelNotFoundException::class => PageNotFoundException::class, |
| 70 | 70 | BaseRelationNotFoundException::class => RelationNotFoundException::class, |
| 71 | - ValidationException::class => function ($exception) { |
|
| 72 | - throw new ValidationFailedException($exception->validator); |
|
| 71 | + ValidationException::class => function ( $exception ) { |
|
| 72 | + throw new ValidationFailedException( $exception->validator ); |
|
| 73 | 73 | }, |
| 74 | - ], array_flip($this->dontConvert))); |
|
| 74 | + ], array_flip( $this->dontConvert ) ) ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @param \Flugg\Responder\Exceptions\Http\ApiException $exception |
| 81 | 81 | * @return \Illuminate\Http\JsonResponse |
| 82 | 82 | */ |
| 83 | - protected function renderResponse(ApiException $exception): JsonResponse |
|
| 83 | + protected function renderResponse( ApiException $exception ): JsonResponse |
|
| 84 | 84 | { |
| 85 | - return $this->container->make(ErrorResponseBuilder::class) |
|
| 86 | - ->error($exception->errorCode(), $exception->message()) |
|
| 87 | - ->data($exception->data()) |
|
| 88 | - ->respond($exception->statusCode()); |
|
| 85 | + return $this->container->make( ErrorResponseBuilder::class ) |
|
| 86 | + ->error( $exception->errorCode(), $exception->message() ) |
|
| 87 | + ->data( $exception->data() ) |
|
| 88 | + ->respond( $exception->statusCode() ); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | \ No newline at end of file |
@@ -24,14 +24,14 @@ |
||
| 24 | 24 | * @param \Exception $exception |
| 25 | 25 | * @return \Symfony\Component\HttpFoundation\Response |
| 26 | 26 | */ |
| 27 | - public function render($request, Exception $exception) |
|
| 27 | + public function render( $request, Exception $exception ) |
|
| 28 | 28 | { |
| 29 | - $this->convertDefaultException($exception); |
|
| 29 | + $this->convertDefaultException( $exception ); |
|
| 30 | 30 | |
| 31 | - if ($exception instanceof ApiException) { |
|
| 32 | - return $this->renderResponse($exception); |
|
| 31 | + if ( $exception instanceof ApiException ) { |
|
| 32 | + return $this->renderResponse( $exception ); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - return parent::render($request, $exception); |
|
| 35 | + return parent::render( $request, $exception ); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |