From 3ba920c92c842ba4eb2228ce6acd856c842ff67a Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Sat, 28 May 2016 17:43:06 -0400 Subject: [PATCH] Applied fixes from StyleCI --- src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php | 7 ++++++- src/Mpociot/ApiDoc/Generators/AbstractGenerator.php | 11 +++++++---- src/Mpociot/ApiDoc/Generators/DingoGenerator.php | 10 +++------- src/Mpociot/ApiDoc/Generators/LaravelGenerator.php | 11 +++++------ tests/ApiDocGeneratorTest.php | 1 - 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php index bb4faccd..63e0da8c 100644 --- a/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php +++ b/src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php @@ -120,6 +120,7 @@ private function getBindings() list($name, $id) = explode(',', $binding); $resultBindings[$name] = $id; } + return $resultBindings; } @@ -128,7 +129,7 @@ private function getBindings() */ private function setUserToBeImpersonated($actAs) { - if (!empty($actAs)) { + if (! empty($actAs)) { if (version_compare($this->laravel->version(), '5.2.0', '<')) { $userModel = config('auth.model'); $user = $userModel::find($actAs); @@ -157,6 +158,7 @@ private function getRoutes() * @param AbstractGenerator $generator * @param $allowedRoutes * @param $routePrefix + * * @return array */ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) @@ -170,6 +172,7 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout $this->info('Processed route: '.$route->getUri()); } } + return $parsedRoutes; } @@ -177,6 +180,7 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout * @param AbstractGenerator $generator * @param $allowedRoutes * @param $routePrefix + * * @return array */ private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) @@ -190,6 +194,7 @@ private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes $this->info('Processed route: '.$route->uri()); } } + return $parsedRoutes; } } diff --git a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php index 03100808..718751c0 100644 --- a/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php @@ -12,9 +12,9 @@ abstract class AbstractGenerator { - /** * @param Route $route + * * @return mixed */ abstract protected function getUri(Route $route); @@ -30,9 +30,11 @@ abstract public function processRoute(Route $route, $bindings = []); /** * @param array $routeData * @param array $routeAction + * * @return mixed */ - protected function getParameters($routeData, $routeAction) { + protected function getParameters($routeData, $routeAction) + { $validator = Validator::make([], $this->getRouteRules($routeAction['uses'])); foreach ($validator->getRules() as $attribute => $rules) { $attributeData = [ @@ -65,10 +67,10 @@ protected function getRouteResponse(Route $route, $bindings) return $this->callRoute(array_shift($methods), $uri); } - /** * @param Route $route * @param array $bindings + * * @return mixed */ protected function addRouteModelBindings(Route $route, $bindings) @@ -77,6 +79,7 @@ protected function addRouteModelBindings(Route $route, $bindings) foreach ($bindings as $model => $id) { $uri = str_replace('{'.$model.'}', $id, $uri); } + return $uri; } @@ -100,7 +103,6 @@ protected function getRouteDescription($route) ]; } - /** * @param string $route * @@ -117,6 +119,7 @@ protected function getRouteGroup($route) return $tag->getContent(); } } + return 'general'; } diff --git a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php index 691f1cde..938ae422 100644 --- a/src/Mpociot/ApiDoc/Generators/DingoGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/DingoGenerator.php @@ -4,11 +4,9 @@ use Illuminate\Routing\Route; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Request; class DingoGenerator extends AbstractGenerator { - /** * @param \Illuminate\Routing\Route $route * @param array $bindings @@ -22,7 +20,7 @@ public function processRoute(Route $route, $bindings = []) $routeAction = $route->getAction(); $routeGroup = $this->getRouteGroup($routeAction['uses']); $routeDescription = $this->getRouteDescription($routeAction['uses']); - + if ($response->headers->get('Content-Type') === 'application/json') { $content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT); } else { @@ -30,7 +28,7 @@ public function processRoute(Route $route, $bindings = []) } return $this->getParameters([ - 'resource' => $routeGroup, + 'resource' => $routeGroup, 'title' => $routeDescription['short'], 'description' => $routeDescription['long'], 'methods' => $route->getMethods(), @@ -40,7 +38,6 @@ public function processRoute(Route $route, $bindings = []) ], $routeAction); } - /** * {@inheritdoc} */ @@ -56,5 +53,4 @@ protected function getUri(Route $route) { return $route->uri(); } - -} \ No newline at end of file +} diff --git a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php index 997c10d9..c4b40307 100644 --- a/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php +++ b/src/Mpociot/ApiDoc/Generators/LaravelGenerator.php @@ -8,9 +8,9 @@ class LaravelGenerator extends AbstractGenerator { - /** * @param Route $route + * * @return mixed */ protected function getUri(Route $route) @@ -27,11 +27,11 @@ protected function getUri(Route $route) public function processRoute(Route $route, $bindings = []) { $response = $this->getRouteResponse($route, $bindings); - + $routeAction = $route->getAction(); $routeGroup = $this->getRouteGroup($routeAction['uses']); $routeDescription = $this->getRouteDescription($routeAction['uses']); - + if ($response->headers->get('Content-Type') === 'application/json') { $content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT); } else { @@ -39,7 +39,7 @@ public function processRoute(Route $route, $bindings = []) } return $this->getParameters([ - 'resource' => $routeGroup, + 'resource' => $routeGroup, 'title' => $routeDescription['short'], 'description' => $routeDescription['long'], 'methods' => $route->getMethods(), @@ -83,5 +83,4 @@ public function callRoute($method, $uri, $parameters = [], $cookies = [], $files return $response; } - -} \ No newline at end of file +} diff --git a/tests/ApiDocGeneratorTest.php b/tests/ApiDocGeneratorTest.php index 1590e28c..07f297b5 100644 --- a/tests/ApiDocGeneratorTest.php +++ b/tests/ApiDocGeneratorTest.php @@ -5,7 +5,6 @@ use Illuminate\Routing\Route; use Mpociot\ApiDoc\Generators\LaravelGenerator; use Orchestra\Testbench\TestCase; -use Mpociot\ApiDoc\AbstractGenerator; use Mpociot\ApiDoc\Tests\Fixtures\TestRequest; use Mpociot\ApiDoc\Tests\Fixtures\TestController; use Illuminate\Support\Facades\Route as RouteFacade;