@@ -12,7 +12,7 @@ discard block  | 
                                                    ||
| 12 | 12 | |
| 13 | 13 | class TestDocGenerator  | 
                                                        
| 14 | 14 |  { | 
                                                        
| 15 | - private $specification = [];  | 
                                                        |
| 15 | + private $specification = [ ];  | 
                                                        |
| 16 | 16 | |
| 17 | 17 | public function registerEndpoint(Request $request, $response) : void  | 
                                                        
| 18 | 18 |  	{ | 
                                                        
@@ -32,8 +32,8 @@ discard block  | 
                                                    ||
| 32 | 32 | |
| 33 | 33 | private function registerDefaults() : void  | 
                                                        
| 34 | 34 |  	{ | 
                                                        
| 35 | - $this->specification['openapi'] = '3.0.0';  | 
                                                        |
| 36 | - $this->specification['components']['securitySchemes']['bearerAuth'] = [  | 
                                                        |
| 35 | + $this->specification[ 'openapi' ] = '3.0.0';  | 
                                                        |
| 36 | + $this->specification[ 'components' ][ 'securitySchemes' ][ 'bearerAuth' ] = [  | 
                                                        |
| 37 | 37 | 'type' => 'http',  | 
                                                        
| 38 | 38 | 'scheme' => 'bearer',  | 
                                                        
| 39 | 39 | 'bearerFormat' => 'JWT'  | 
                                                        
@@ -42,7 +42,7 @@ discard block  | 
                                                    ||
| 42 | 42 | |
| 43 | 43 | private function addOrUpdateEndpoint(Request $request, $response): void  | 
                                                        
| 44 | 44 |  	{ | 
                                                        
| 45 | -		if($this->endpointExistsOnSpecification($request)){ | 
                                                        |
| 45 | +		if ($this->endpointExistsOnSpecification($request)) { | 
                                                        |
| 46 | 46 | $this->updateSpecificationEndpoint($request, $response);  | 
                                                        
| 47 | 47 |  		} else { | 
                                                        
| 48 | 48 | $this->addSpecificationEndpoint($request, $response);  | 
                                                        
@@ -50,18 +50,18 @@ discard block  | 
                                                    ||
| 50 | 50 | }  | 
                                                        
| 51 | 51 | |
| 52 | 52 |  	private function endpointExistsOnSpecification(Request $request):bool{ | 
                                                        
| 53 | - return isset($this->specification['paths']  | 
                                                        |
| 54 | - [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        |
| 55 | - [$this->getRouteMethodForSpecification($request)]);  | 
                                                        |
| 53 | + return isset($this->specification[ 'paths' ]  | 
                                                        |
| 54 | + [ $this->getInternalRouteDeclaredFormat($request) ]  | 
                                                        |
| 55 | + [ $this->getRouteMethodForSpecification($request) ]);  | 
                                                        |
| 56 | 56 | }  | 
                                                        
| 57 | 57 | |
| 58 | -	private function addSpecificationEndpoint(Request $request, $response){ | 
                                                        |
| 58 | +	private function addSpecificationEndpoint(Request $request, $response) { | 
                                                        |
| 59 | 59 | //TODO: Config  | 
                                                        
| 60 | - if(str_contains($this->getInternalRouteDeclaredFormat($request), 'internal')) return;  | 
                                                        |
| 60 | + if (str_contains($this->getInternalRouteDeclaredFormat($request), 'internal')) return;  | 
                                                        |
| 61 | 61 | |
| 62 | - $this->specification['paths']  | 
                                                        |
| 63 | - [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        |
| 64 | - [$this->getRouteMethodForSpecification($request)] = [  | 
                                                        |
| 62 | + $this->specification[ 'paths' ]  | 
                                                        |
| 63 | + [ $this->getInternalRouteDeclaredFormat($request) ]  | 
                                                        |
| 64 | + [ $this->getRouteMethodForSpecification($request) ] = [  | 
                                                        |
| 65 | 65 | 'responses' => [  | 
                                                        
| 66 | 66 | '200' => [  | 
                                                        
| 67 | 67 | 'description' => ''  | 
                                                        
@@ -76,10 +76,10 @@ discard block  | 
                                                    ||
| 76 | 76 | $this->updateSpecificationEndpoint($request, $response);  | 
                                                        
| 77 | 77 | }  | 
                                                        
| 78 | 78 | |
| 79 | -	private function updateSpecificationEndpoint(Request $request, $response){ | 
                                                        |
| 79 | +	private function updateSpecificationEndpoint(Request $request, $response) { | 
                                                        |
| 80 | 80 | $this->mergeResponseToEndpoint($request, $response);  | 
                                                        
| 81 | 81 | |
| 82 | -		if(in_array($this->getRouteMethodForSpecification($request), ['post', 'patch', 'delete'])){ | 
                                                        |
| 82 | +		if (in_array($this->getRouteMethodForSpecification($request), [ 'post', 'patch', 'delete' ])) { | 
                                                        |
| 83 | 83 | $this->mergeRequestBodiesToEndpoint($request, $response);  | 
                                                        
| 84 | 84 |  		} else { | 
                                                        
| 85 | 85 | $this->mergeParamsToEndpoint($request, $response);  | 
                                                        
@@ -88,12 +88,12 @@ discard block  | 
                                                    ||
| 88 | 88 | $this->saveSpecification();  | 
                                                        
| 89 | 89 | }  | 
                                                        
| 90 | 90 | |
| 91 | -	private function mergeResponseToEndpoint(Request $request, $response){ | 
                                                        |
| 92 | - $this->specification['paths']  | 
                                                        |
| 93 | - [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        |
| 94 | - [$this->getRouteMethodForSpecification($request)]  | 
                                                        |
| 95 | - ['responses']  | 
                                                        |
| 96 | - [$response->getStatusCode()] = [  | 
                                                        |
| 91 | +	private function mergeResponseToEndpoint(Request $request, $response) { | 
                                                        |
| 92 | + $this->specification[ 'paths' ]  | 
                                                        |
| 93 | + [ $this->getInternalRouteDeclaredFormat($request) ]  | 
                                                        |
| 94 | + [ $this->getRouteMethodForSpecification($request) ]  | 
                                                        |
| 95 | + [ 'responses' ]  | 
                                                        |
| 96 | + [ $response->getStatusCode() ] = [  | 
                                                        |
| 97 | 97 | 'description' => '',  | 
                                                        
| 98 | 98 | 'content' => [  | 
                                                        
| 99 | 99 | 'application/json' => [  | 
                                                        
@@ -106,76 +106,75 @@ discard block  | 
                                                    ||
| 106 | 106 | ];  | 
                                                        
| 107 | 107 | }  | 
                                                        
| 108 | 108 | |
| 109 | -	private function mergeParamsToEndpoint(Request $request, $response){ | 
                                                        |
| 109 | +	private function mergeParamsToEndpoint(Request $request, $response) { | 
                                                        |
| 110 | 110 |  		collect($request->query->all())->keys()->each(function($param)use($request){ | 
                                                        
| 111 | - $this->specification['paths']  | 
                                                        |
| 112 | - [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        |
| 113 | - [$this->getRouteMethodForSpecification($request)]  | 
                                                        |
| 114 | - ['parameters'][] = [  | 
                                                        |
| 111 | + $this->specification[ 'paths' ]  | 
                                                        |
| 112 | + [ $this->getInternalRouteDeclaredFormat($request) ]  | 
                                                        |
| 113 | + [ $this->getRouteMethodForSpecification($request) ]  | 
                                                        |
| 114 | + [ 'parameters' ][ ] = [  | 
                                                        |
| 115 | 115 | 'in' => 'query',  | 
                                                        
| 116 | 116 | 'name' => $param,  | 
                                                        
| 117 | - 'schema' => ['type' => 'string']  | 
                                                        |
| 117 | + 'schema' => [ 'type' => 'string' ]  | 
                                                        |
| 118 | 118 | ];  | 
                                                        
| 119 | 119 | });  | 
                                                        
| 120 | 120 | }  | 
                                                        
| 121 | 121 | |
| 122 | -	private function mergeRequestBodiesToEndpoint(Request $request, $response){ | 
                                                        |
| 123 | - if( ! isset($this->specification['paths']  | 
                                                        |
| 124 | - [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        |
| 125 | - [$this->getRouteMethodForSpecification($request)]  | 
                                                        |
| 126 | -			['requestBody'])){ | 
                                                        |
| 122 | +	private function mergeRequestBodiesToEndpoint(Request $request, $response) { | 
                                                        |
| 123 | + if ( ! isset($this->specification[ 'paths' ]  | 
                                                        |
| 124 | + [ $this->getInternalRouteDeclaredFormat($request) ]  | 
                                                        |
| 125 | + [ $this->getRouteMethodForSpecification($request) ]  | 
                                                        |
| 126 | +			[ 'requestBody' ])) { | 
                                                        |
| 127 | 127 | |
| 128 | - $this->specification['paths']  | 
                                                        |
| 129 | - [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        |
| 130 | - [$this->getRouteMethodForSpecification($request)]  | 
                                                        |
| 131 | - ['requestBody']['content']['application/json'] = [  | 
                                                        |
| 128 | + $this->specification[ 'paths' ]  | 
                                                        |
| 129 | + [ $this->getInternalRouteDeclaredFormat($request) ]  | 
                                                        |
| 130 | + [ $this->getRouteMethodForSpecification($request) ]  | 
                                                        |
| 131 | + [ 'requestBody' ][ 'content' ][ 'application/json' ] = [  | 
                                                        |
| 132 | 132 | 'schema' => [  | 
                                                        
| 133 | 133 | 'type' => 'object',  | 
                                                        
| 134 | - 'properties' => []  | 
                                                        |
| 134 | + 'properties' => [ ]  | 
                                                        |
| 135 | 135 | ],  | 
                                                        
| 136 | 136 | 'required' => false  | 
                                                        
| 137 | 137 | ];  | 
                                                        
| 138 | 138 | }  | 
                                                        
| 139 | 139 | |
| 140 | 140 |  		collect($request->json()->all())->keys()->each(function($bodyKey)use($request){ | 
                                                        
| 141 | - $this->specification['paths']  | 
                                                        |
| 142 | - [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        |
| 143 | - [$this->getRouteMethodForSpecification($request)]  | 
                                                        |
| 144 | - ['requestBody']['content']['application/json']['schema']['properties'][$bodyKey] = [  | 
                                                        |
| 141 | + $this->specification[ 'paths' ]  | 
                                                        |
| 142 | + [ $this->getInternalRouteDeclaredFormat($request) ]  | 
                                                        |
| 143 | + [ $this->getRouteMethodForSpecification($request) ]  | 
                                                        |
| 144 | + [ 'requestBody' ][ 'content' ][ 'application/json' ][ 'schema' ][ 'properties' ][ $bodyKey ] = [  | 
                                                        |
| 145 | 145 | 'type' => 'string'  | 
                                                        
| 146 | 146 | ];  | 
                                                        
| 147 | 147 | });  | 
                                                        
| 148 | 148 | }  | 
                                                        
| 149 | 149 | |
| 150 | -	private function getRouteMethodForSpecification(Request $request){ | 
                                                        |
| 150 | +	private function getRouteMethodForSpecification(Request $request) { | 
                                                        |
| 151 | 151 | return strtolower($request->getMethod());  | 
                                                        
| 152 | 152 | }  | 
                                                        
| 153 | 153 | |
| 154 | -	private function getInternalRoute(Request $request){ | 
                                                        |
| 155 | - if( ! isset($request->route()[1]['as'])) return null;  | 
                                                        |
| 156 | - return route($request->route()[1]['as']);  | 
                                                        |
| 154 | +	private function getInternalRoute(Request $request) { | 
                                                        |
| 155 | + if ( ! isset($request->route()[ 1 ][ 'as' ])) return null;  | 
                                                        |
| 156 | + return route($request->route()[ 1 ][ 'as' ]);  | 
                                                        |
| 157 | 157 | }  | 
                                                        
| 158 | 158 | |
| 159 | -	private function getInternalRouteDeclaredFormat(Request $request){ | 
                                                        |
| 159 | +	private function getInternalRouteDeclaredFormat(Request $request) { | 
                                                        |
| 160 | 160 | $uri = parse_url($this->getInternalRoute($request) ?: $request->getRequestUri());  | 
                                                        
| 161 | - return $uri['path'];  | 
                                                        |
| 161 | + return $uri[ 'path' ];  | 
                                                        |
| 162 | 162 | }  | 
                                                        
| 163 | 163 | |
| 164 | -	private function getRouteSpecificationGroup(Request $request){ | 
                                                        |
| 165 | - return $this->getRouteSpecificationGroupByRouteName($request) ?:  | 
                                                        |
| 166 | - $this->getRouteSpecificationGroupByRequestUri($request);  | 
                                                        |
| 164 | +	private function getRouteSpecificationGroup(Request $request) { | 
                                                        |
| 165 | + return $this->getRouteSpecificationGroupByRouteName($request) ?: $this->getRouteSpecificationGroupByRequestUri($request);  | 
                                                        |
| 167 | 166 | }  | 
                                                        
| 168 | 167 | |
| 169 | -	private function getRouteSpecificationGroupByRouteName(Request $request){ | 
                                                        |
| 170 | - if( ! isset($request->route()[1]['as'])) return null;  | 
                                                        |
| 168 | +	private function getRouteSpecificationGroupByRouteName(Request $request) { | 
                                                        |
| 169 | + if ( ! isset($request->route()[ 1 ][ 'as' ])) return null;  | 
                                                        |
| 171 | 170 | |
| 172 | - $internalRoute = $request->route()[1]['as'];  | 
                                                        |
| 171 | + $internalRoute = $request->route()[ 1 ][ 'as' ];  | 
                                                        |
| 173 | 172 |  		$tag = explode('.', $internalRoute); | 
                                                        
| 174 | 173 | |
| 175 | - return $tag[count($tag) - 2];  | 
                                                        |
| 174 | + return $tag[ count($tag) - 2 ];  | 
                                                        |
| 176 | 175 | }  | 
                                                        
| 177 | 176 | |
| 178 | -	private function getRouteSpecificationGroupByRequestUri(Request $request){ | 
                                                        |
| 177 | +	private function getRouteSpecificationGroupByRequestUri(Request $request) { | 
                                                        |
| 179 | 178 | return "other";  | 
                                                        
| 180 | 179 | }  | 
                                                        
| 181 | 180 | |
@@ -185,8 +184,8 @@ discard block  | 
                                                    ||
| 185 | 184 | |
| 186 | 185 |  	private function getOperationSecurity(Request $request) : array{ | 
                                                        
| 187 | 186 | return (  | 
                                                        
| 188 | - isset($request->route()[1]['middleware']) &&  | 
                                                        |
| 189 | -			in_array('auth', $request->route()[1]['middleware'], true) | 
                                                        |
| 190 | - ) ? ['bearerAuth' => []] : [];  | 
                                                        |
| 187 | + isset($request->route()[ 1 ][ 'middleware' ]) &&  | 
                                                        |
| 188 | +			in_array('auth', $request->route()[ 1 ][ 'middleware' ], true) | 
                                                        |
| 189 | + ) ? [ 'bearerAuth' => [ ] ] : [ ];  | 
                                                        |
| 191 | 190 | }  | 
                                                        
| 192 | 191 | }  | 
                                                        
| 193 | 192 | \ No newline at end of file  | 
                                                        
@@ -57,7 +57,9 @@ discard block  | 
                                                    ||
| 57 | 57 | |
| 58 | 58 |  	private function addSpecificationEndpoint(Request $request, $response){ | 
                                                        
| 59 | 59 | //TODO: Config  | 
                                                        
| 60 | - if(str_contains($this->getInternalRouteDeclaredFormat($request), 'internal')) return;  | 
                                                        |
| 60 | +		if(str_contains($this->getInternalRouteDeclaredFormat($request), 'internal')) { | 
                                                        |
| 61 | + return;  | 
                                                        |
| 62 | + }  | 
                                                        |
| 61 | 63 | |
| 62 | 64 | $this->specification['paths']  | 
                                                        
| 63 | 65 | [$this->getInternalRouteDeclaredFormat($request)]  | 
                                                        
@@ -152,7 +154,9 @@ discard block  | 
                                                    ||
| 152 | 154 | }  | 
                                                        
| 153 | 155 | |
| 154 | 156 |  	private function getInternalRoute(Request $request){ | 
                                                        
| 155 | - if( ! isset($request->route()[1]['as'])) return null;  | 
                                                        |
| 157 | +		if( ! isset($request->route()[1]['as'])) { | 
                                                        |
| 158 | + return null;  | 
                                                        |
| 159 | + }  | 
                                                        |
| 156 | 160 | return route($request->route()[1]['as']);  | 
                                                        
| 157 | 161 | }  | 
                                                        
| 158 | 162 | |
@@ -167,7 +171,9 @@ discard block  | 
                                                    ||
| 167 | 171 | }  | 
                                                        
| 168 | 172 | |
| 169 | 173 |  	private function getRouteSpecificationGroupByRouteName(Request $request){ | 
                                                        
| 170 | - if( ! isset($request->route()[1]['as'])) return null;  | 
                                                        |
| 174 | +		if( ! isset($request->route()[1]['as'])) { | 
                                                        |
| 175 | + return null;  | 
                                                        |
| 176 | + }  | 
                                                        |
| 171 | 177 | |
| 172 | 178 | $internalRoute = $request->route()[1]['as'];  | 
                                                        
| 173 | 179 |  		$tag = explode('.', $internalRoute); | 
                                                        
@@ -20,14 +20,14 @@  | 
                                                    ||
| 20 | 20 | *  | 
                                                        
| 21 | 21 | * @return void  | 
                                                        
| 22 | 22 | */  | 
                                                        
| 23 | -	public function boot(){ | 
                                                        |
| 24 | -		if($this->app->runningUnitTests()){ | 
                                                        |
| 25 | -			if($this->app instanceof \Illuminate\Foundation\Application){ | 
                                                        |
| 23 | +	public function boot() { | 
                                                        |
| 24 | +		if ($this->app->runningUnitTests()) { | 
                                                        |
| 25 | +			if ($this->app instanceof \Illuminate\Foundation\Application) { | 
                                                        |
| 26 | 26 | //Laravel middleware loading  | 
                                                        
| 27 | - $this->app[Kernel::class]->pushMiddleware(IncludeInSpecification::class);  | 
                                                        |
| 27 | + $this->app[ Kernel::class ]->pushMiddleware(IncludeInSpecification::class);  | 
                                                        |
| 28 | 28 |  			} else { | 
                                                        
| 29 | 29 | //Lumen middleware loading  | 
                                                        
| 30 | - $this->app->middleware([IncludeInSpecification::class]);  | 
                                                        |
| 30 | + $this->app->middleware([ IncludeInSpecification::class ]);  | 
                                                        |
| 31 | 31 | }  | 
                                                        
| 32 | 32 | }  | 
                                                        
| 33 | 33 | }  |