Skip to content

Commit

Permalink
Applied fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot authored and StyleCIBot committed May 28, 2016
1 parent 204eeeb commit 3ba920c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
7 changes: 6 additions & 1 deletion src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private function getBindings()
list($name, $id) = explode(',', $binding);
$resultBindings[$name] = $id;
}

return $resultBindings;
}

Expand All @@ -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);
Expand Down Expand Up @@ -157,6 +158,7 @@ private function getRoutes()
* @param AbstractGenerator $generator
* @param $allowedRoutes
* @param $routePrefix
*
* @return array
*/
private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix)
Expand All @@ -170,13 +172,15 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout
$this->info('Processed route: '.$route->getUri());
}
}

return $parsedRoutes;
}

/**
* @param AbstractGenerator $generator
* @param $allowedRoutes
* @param $routePrefix
*
* @return array
*/
private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix)
Expand All @@ -190,6 +194,7 @@ private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes
$this->info('Processed route: '.$route->uri());
}
}

return $parsedRoutes;
}
}
11 changes: 7 additions & 4 deletions src/Mpociot/ApiDoc/Generators/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

abstract class AbstractGenerator
{

/**
* @param Route $route
*
* @return mixed
*/
abstract protected function getUri(Route $route);
Expand All @@ -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 = [
Expand Down Expand Up @@ -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)
Expand All @@ -77,6 +79,7 @@ protected function addRouteModelBindings(Route $route, $bindings)
foreach ($bindings as $model => $id) {
$uri = str_replace('{'.$model.'}', $id, $uri);
}

return $uri;
}

Expand All @@ -100,7 +103,6 @@ protected function getRouteDescription($route)
];
}


/**
* @param string $route
*
Expand All @@ -117,6 +119,7 @@ protected function getRouteGroup($route)
return $tag->getContent();
}
}

return 'general';
}

Expand Down
10 changes: 3 additions & 7 deletions src/Mpociot/ApiDoc/Generators/DingoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,15 +20,15 @@ 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 {
$content = $response->getContent();
}

return $this->getParameters([
'resource' => $routeGroup,
'resource' => $routeGroup,
'title' => $routeDescription['short'],
'description' => $routeDescription['long'],
'methods' => $route->getMethods(),
Expand All @@ -40,7 +38,6 @@ public function processRoute(Route $route, $bindings = [])
], $routeAction);
}


/**
* {@inheritdoc}
*/
Expand All @@ -56,5 +53,4 @@ protected function getUri(Route $route)
{
return $route->uri();
}

}
}
11 changes: 5 additions & 6 deletions src/Mpociot/ApiDoc/Generators/LaravelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class LaravelGenerator extends AbstractGenerator
{

/**
* @param Route $route
*
* @return mixed
*/
protected function getUri(Route $route)
Expand All @@ -27,19 +27,19 @@ 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 {
$content = $response->getContent();
}

return $this->getParameters([
'resource' => $routeGroup,
'resource' => $routeGroup,
'title' => $routeDescription['short'],
'description' => $routeDescription['long'],
'methods' => $route->getMethods(),
Expand Down Expand Up @@ -83,5 +83,4 @@ public function callRoute($method, $uri, $parameters = [], $cookies = [], $files

return $response;
}

}
}
1 change: 0 additions & 1 deletion tests/ApiDocGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3ba920c

Please sign in to comment.