mirror of
https://github.com/ambieco/scribe.git
synced 2026-04-24 08:14:56 +08:00
Merge pull request #568 from mpociot/analysis-8Keom9
Apply fixes from StyleCI
This commit is contained in:
@@ -15,7 +15,6 @@ use Illuminate\Foundation\Http\FormRequest as LaravelFormRequest;
|
||||
|
||||
class GetFromDocBlocks extends Strategy
|
||||
{
|
||||
|
||||
use ParamHelpers;
|
||||
|
||||
public function __invoke(Route $route, ReflectionClass $controller, ReflectionMethod $method, array $routeRules, array $context = [])
|
||||
@@ -49,6 +48,7 @@ class GetFromDocBlocks extends Strategy
|
||||
}
|
||||
|
||||
$methodDocBlock = RouteDocBlocker::getDocBlocksFromRoute($route)['method'];
|
||||
|
||||
return $this->getBodyParametersFromDocBlock($methodDocBlock->getTags());
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ class GetFromDocBlocks extends Strategy
|
||||
|
||||
/**
|
||||
* @param DocBlock $methodDocBlock
|
||||
*
|
||||
* @param DocBlock $controllerDocBlock
|
||||
*
|
||||
* @return array The route group name, the group description, ad the route title
|
||||
@@ -86,15 +85,15 @@ class GetFromDocBlocks extends Strategy
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($controllerDocBlock->getTags() as $tag) {
|
||||
if ($tag->getName() === 'group') {
|
||||
$routeGroupParts = explode("\n", trim($tag->getContent()));
|
||||
$routeGroupName = array_shift($routeGroupParts);
|
||||
$routeGroupDescription = implode("\n", $routeGroupParts);
|
||||
foreach ($controllerDocBlock->getTags() as $tag) {
|
||||
if ($tag->getName() === 'group') {
|
||||
$routeGroupParts = explode("\n", trim($tag->getContent()));
|
||||
$routeGroupName = array_shift($routeGroupParts);
|
||||
$routeGroupDescription = implode("\n", $routeGroupParts);
|
||||
|
||||
return [$routeGroupName, $routeGroupDescription, $methodDocBlock->getShortDescription()];
|
||||
}
|
||||
return [$routeGroupName, $routeGroupDescription, $methodDocBlock->getShortDescription()];
|
||||
}
|
||||
}
|
||||
|
||||
return [$this->config->get('default_group'), '', $methodDocBlock->getShortDescription()];
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ use Illuminate\Foundation\Http\FormRequest as LaravelFormRequest;
|
||||
|
||||
class GetFromDocBlocks extends Strategy
|
||||
{
|
||||
|
||||
use ParamHelpers;
|
||||
|
||||
public function __invoke(Route $route, ReflectionClass $controller, ReflectionMethod $method, array $routeRules, array $context = [])
|
||||
@@ -49,6 +48,7 @@ class GetFromDocBlocks extends Strategy
|
||||
}
|
||||
|
||||
$methodDocBlock = RouteDocBlocker::getDocBlocksFromRoute($route)['method'];
|
||||
|
||||
return $this->getqueryParametersFromDocBlock($methodDocBlock->getTags());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,16 @@ class UseResponseFileTag extends Strategy
|
||||
* @param array $routeRules
|
||||
* @param array $context
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $routeRules, array $context = [])
|
||||
{
|
||||
$docBlocks = RouteDocBlocker::getDocBlocksFromRoute($route);
|
||||
/** @var DocBlock $methodDocBlock */
|
||||
$methodDocBlock = $docBlocks['method'];
|
||||
|
||||
return $this->getFileResponses($methodDocBlock->getTags());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,16 @@ class UseResponseTag extends Strategy
|
||||
* @param array $routeRules
|
||||
* @param array $context
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $routeRules, array $context = [])
|
||||
{
|
||||
$docBlocks = RouteDocBlocker::getDocBlocksFromRoute($route);
|
||||
/** @var DocBlock $methodDocBlock */
|
||||
$methodDocBlock = $docBlocks['method'];
|
||||
|
||||
return $this->getDocBlockResponses($methodDocBlock->getTags());
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ use Mpociot\ApiDoc\Tools\Flags;
|
||||
use Mpociot\Reflection\DocBlock;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Mpociot\Reflection\DocBlock\Tag;
|
||||
use Mpociot\ApiDoc\Strategies\Strategy;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use Mpociot\ApiDoc\Strategies\Strategy;
|
||||
use Mpociot\ApiDoc\Tools\RouteDocBlocker;
|
||||
|
||||
/**
|
||||
@@ -26,14 +26,16 @@ class UseTransformerTags extends Strategy
|
||||
* @param array $rulesToApply
|
||||
* @param array $context
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $rulesToApply, array $context = [])
|
||||
{
|
||||
$docBlocks = RouteDocBlocker::getDocBlocksFromRoute($route);
|
||||
/** @var DocBlock $methodDocBlock */
|
||||
$methodDocBlock = $docBlocks['method'];
|
||||
|
||||
return $this->getTransformerResponse($methodDocBlock->getTags());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,9 @@ abstract class Strategy
|
||||
* @param array $routeRules Array of rules for the ruleset which this route belongs to.
|
||||
* @param array $context Results from the previous stages
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function __invoke(Route $route, ReflectionClass $controller, ReflectionMethod $method, array $routeRules, array $context = []);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
namespace Mpociot\ApiDoc\Tools;
|
||||
|
||||
use Faker\Factory;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use Illuminate\Routing\Route;
|
||||
use Mpociot\Reflection\DocBlock;
|
||||
use Mpociot\ApiDoc\Tools\Traits\ParamHelpers;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
@@ -104,25 +102,27 @@ class Generator
|
||||
return array_map(function (Response $response) {
|
||||
return [
|
||||
'status' => $response->getStatusCode(),
|
||||
'content' => $response->getContent()
|
||||
'content' => $response->getContent(),
|
||||
];
|
||||
}, $responses);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function iterateThroughStrategies(string $key, array $arguments)
|
||||
{
|
||||
$strategies = $this->config->get("strategies.$key", []);
|
||||
$results = [];
|
||||
$strategies = $this->config->get("strategies.$key", []);
|
||||
$results = [];
|
||||
|
||||
foreach ($strategies as $strategyClass) {
|
||||
$strategy = new $strategyClass($this->config);
|
||||
$results = $strategy(...$arguments);
|
||||
if (! is_null($results)) {
|
||||
break;
|
||||
foreach ($strategies as $strategyClass) {
|
||||
$strategy = new $strategyClass($this->config);
|
||||
$results = $strategy(...$arguments);
|
||||
if (! is_null($results)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return is_null($results) ? [] : $results;
|
||||
}
|
||||
return is_null($results) ? [] : $results;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use Mpociot\Reflection\DocBlock;
|
||||
|
||||
class RouteDocBlocker
|
||||
{
|
||||
|
||||
public static $docBlocks = [];
|
||||
|
||||
public static function getDocBlocksFromRoute(Route $route)
|
||||
@@ -27,15 +26,17 @@ class RouteDocBlocker
|
||||
|
||||
$docBlocks = [
|
||||
'method' => new DocBlock($class->getMethod($methodName)->getDocComment() ?: ''),
|
||||
'class' => new DocBlock($class->getDocComment() ?: '')
|
||||
'class' => new DocBlock($class->getDocComment() ?: ''),
|
||||
];
|
||||
self::cacheDocBlocks($route, $className, $methodName, $docBlocks);
|
||||
|
||||
return $docBlocks;
|
||||
}
|
||||
|
||||
protected static function getCachedDocBlock(Route $route, string $className, string $methodName)
|
||||
{
|
||||
$routeId = self::getRouteId($route, $className, $methodName);
|
||||
|
||||
return self::$docBlocks[$routeId] ?? null;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class TestController extends Controller
|
||||
*/
|
||||
public function withGroupOverride()
|
||||
{
|
||||
return "Group B, baby!";
|
||||
return 'Group B, baby!';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ class TestController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint with body parameters
|
||||
* Endpoint with body parameters.
|
||||
*
|
||||
* @bodyParam user_id int required The id of the user. Example: 9
|
||||
* @bodyParam room_id string The id of the room.
|
||||
|
||||
@@ -29,7 +29,7 @@ class GenerateDocumentationTest extends TestCase
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Utils::deleteDirectoryAndContents('/public/docs');
|
||||
Utils::deleteDirectoryAndContents('/public/docs');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -451,7 +451,7 @@ abstract class GeneratorTestCase extends TestCase
|
||||
$this->assertEquals(200, $response['status']);
|
||||
$this->assertSame(
|
||||
$response['content'],
|
||||
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},' .
|
||||
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},'.
|
||||
'{"id":1,"description":"Welcome on this test versions","name":"TestName"}]}'
|
||||
);
|
||||
}
|
||||
@@ -470,7 +470,7 @@ abstract class GeneratorTestCase extends TestCase
|
||||
$this->assertEquals(200, $response['status']);
|
||||
$this->assertSame(
|
||||
$response['content'],
|
||||
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},' .
|
||||
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},'.
|
||||
'{"id":1,"description":"Welcome on this test versions","name":"TestName"}]}'
|
||||
);
|
||||
}
|
||||
@@ -608,7 +608,7 @@ abstract class GeneratorTestCase extends TestCase
|
||||
public function can_parse_response_file_tag()
|
||||
{
|
||||
// copy file to storage
|
||||
$filePath = __DIR__ . '/../Fixtures/response_test.json';
|
||||
$filePath = __DIR__.'/../Fixtures/response_test.json';
|
||||
$fixtureFileJson = file_get_contents($filePath);
|
||||
copy($filePath, storage_path('response_test.json'));
|
||||
|
||||
@@ -633,7 +633,7 @@ abstract class GeneratorTestCase extends TestCase
|
||||
public function can_add_or_replace_key_value_pair_in_response_file()
|
||||
{
|
||||
// copy file to storage
|
||||
$filePath = __DIR__ . '/../Fixtures/response_test.json';
|
||||
$filePath = __DIR__.'/../Fixtures/response_test.json';
|
||||
$fixtureFileJson = file_get_contents($filePath);
|
||||
copy($filePath, storage_path('response_test.json'));
|
||||
|
||||
@@ -658,10 +658,10 @@ abstract class GeneratorTestCase extends TestCase
|
||||
public function can_parse_multiple_response_file_tags_with_status_codes()
|
||||
{
|
||||
// copy file to storage
|
||||
$successFilePath = __DIR__ . '/../Fixtures/response_test.json';
|
||||
$successFilePath = __DIR__.'/../Fixtures/response_test.json';
|
||||
$successFixtureFileJson = file_get_contents($successFilePath);
|
||||
copy($successFilePath, storage_path('response_test.json'));
|
||||
$errorFilePath = __DIR__ . '/../Fixtures/response_error_test.json';
|
||||
$errorFilePath = __DIR__.'/../Fixtures/response_error_test.json';
|
||||
$errorFixtureFileJson = file_get_contents($errorFilePath);
|
||||
copy($errorFilePath, storage_path('response_error_test.json'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user