Updated dockblocks and optimized qualified classes

This commit is contained in:
Andrey Helldar
2020-01-13 12:36:11 +03:00
parent e32b6ee3bf
commit 38932f0a62
6 changed files with 25 additions and 7 deletions

View File

@@ -89,6 +89,8 @@ class GenerateDocumentation extends Command
* @param \Mpociot\ApiDoc\Extracting\Generator $generator
* @param array $routes
*
* @throws \ReflectionException
*
* @return array
*/
private function processRoutes(Generator $generator, array $routes)

View File

@@ -47,6 +47,8 @@ class Generator
* @param \Illuminate\Routing\Route $route
* @param array $routeRules Rules to apply when generating documentation for this route
*
* @throws \ReflectionException
*
* @return array
*/
public function processRoute(Route $route, array $routeRules = [])

View File

@@ -3,6 +3,7 @@
namespace Mpociot\ApiDoc\Extracting;
use Faker\Factory;
use stdClass;
trait ParamHelpers
{
@@ -32,7 +33,7 @@ trait ParamHelpers
return [];
},
'object' => function () {
return new \stdClass;
return new stdClass;
},
];

View File

@@ -20,6 +20,7 @@ class RouteDocBlocker
* @param Route $route
*
* @throws \ReflectionException
* @throws \Exception
*
* @return array<string, DocBlock> Method and class docblocks
*/

View File

@@ -4,6 +4,7 @@ namespace Mpociot\ApiDoc\Extracting\Strategies\Responses;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Model as IlluminateModel;
use Illuminate\Routing\Route;
use Illuminate\Support\Arr;
use League\Fractal\Manager;
@@ -34,7 +35,7 @@ class UseTransformerTags extends Strategy
*
* @return array|null
*/
public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $rulesToApply, array $context = [])
public function __invoke(Route $route, ReflectionClass $controller, ReflectionMethod $method, array $rulesToApply, array $context = [])
{
$docBlocks = RouteDocBlocker::getDocBlocksFromRoute($route);
/** @var DocBlock $methodDocBlock */
@@ -47,6 +48,7 @@ class UseTransformerTags extends Strategy
* Get a response from the transformer tags.
*
* @param array $tags
* @param Route $route
*
* @return array|null
*/
@@ -57,7 +59,7 @@ class UseTransformerTags extends Strategy
return null;
}
list($statusCode, $transformer) = $this->getStatusCodeAndTransformerClass($transformerTag);
[$statusCode, $transformer] = $this->getStatusCodeAndTransformerClass($transformerTag);
$model = $this->getClassToBeTransformed($tags, (new ReflectionClass($transformer))->getMethod('transform'));
$modelInstance = $this->instantiateTransformerModel($model);
@@ -81,7 +83,7 @@ class UseTransformerTags extends Strategy
'content' => $response->getContent(),
],
];
} catch (\Exception $e) {
} catch (Exception $e) {
echo 'Exception thrown when fetching transformer response for ['.implode(',', $route->methods)."] {$route->uri}.\n";
if (Flags::$shouldBeVerbose) {
Utils::dumpException($e);
@@ -112,6 +114,8 @@ class UseTransformerTags extends Strategy
* @param array $tags
* @param ReflectionMethod $transformerMethod
*
* @throws Exception
*
* @return string
*/
private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod): string
@@ -153,20 +157,20 @@ class UseTransformerTags extends Strategy
$type = ltrim($type, '\\');
return factory($type)->make();
} catch (\Exception $e) {
} catch (Exception $e) {
if (Flags::$shouldBeVerbose) {
echo "Eloquent model factory failed to instantiate {$type}; trying to fetch from database.\n";
}
$instance = new $type;
if ($instance instanceof \Illuminate\Database\Eloquent\Model) {
if ($instance instanceof IlluminateModel) {
try {
// we can't use a factory but can try to get one from the database
$firstInstance = $type::first();
if ($firstInstance) {
return $firstInstance;
}
} catch (\Exception $e) {
} catch (Exception $e) {
// okay, we'll stick with `new`
if (Flags::$shouldBeVerbose) {
echo "Failed to fetch first {$type} from database; using `new` to instantiate.\n";

View File

@@ -94,6 +94,14 @@ class Utils
$fs->deleteDir($dir);
}
/**
* @param mixed $value
* @param int $indentationLevel
*
* @throws \Symfony\Component\VarExporter\Exception\ExceptionInterface
*
* @return string
*/
public static function printPhpValue($value, $indentationLevel = 0)
{
$output = VarExporter::export($value);