Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"require": {
"php": ">=7.0.0",
"fzaninotto/faker": "~1.8",
"illuminate/routing": "5.5.* || 5.6.* || 5.7.* || 5.8.*",
"illuminate/support": "5.5.* || 5.6.* || 5.7.* || 5.8.*",
"illuminate/console": "5.5.* || 5.6.* || 5.7.* || 5.8.*",
"illuminate/routing": "^5.5|^6.0",
"illuminate/support": "^5.5|^6.0",
"illuminate/console": "^5.5|^6.0",
"mpociot/documentarian": "^0.2.0",
"mpociot/reflection-docblock": "^1.0.1",
"ramsey/uuid": "^3.8",
Expand Down
2 changes: 1 addition & 1 deletion resources/views/documentarian.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@foreach($parsedRoutes as $groupName => $routes)
#{!! $groupName !!}
{{-- We pick the first non-empty description we see. --}}
{!! array_first($routes, function ($route) { return $route['groupDescription'] !== ''; })['groupDescription'] ?? '' !!}
{!! \Illuminate\Support\Arr::first($routes, function ($route) { return $route['groupDescription'] !== ''; })['groupDescription'] ?? '' !!}
@foreach($routes as $parsedRoute)
@if($writeCompareFile === true)
{!! $parsedRoute['output'] !!}
Expand Down
3 changes: 2 additions & 1 deletion src/Tools/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Faker\Factory;
use ReflectionClass;
use ReflectionMethod;
use Illuminate\Support\Str;
use Illuminate\Routing\Route;
use Mpociot\Reflection\DocBlock;
use Mpociot\Reflection\DocBlock\Tag;
Expand Down Expand Up @@ -227,7 +228,7 @@ protected function getQueryParametersFromDocBlock(array $tags)

list($description, $value) = $this->parseDescription($description, 'string');
if (is_null($value) && ! $this->shouldExcludeExample($tag)) {
$value = str_contains($description, ['number', 'count', 'page'])
$value = Str::contains($description, ['number', 'count', 'page'])
? $this->generateDummyValue('integer')
: $this->generateDummyValue('string');
}
Expand Down
7 changes: 4 additions & 3 deletions src/Tools/ResponseStrategies/TransformerTagsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ReflectionClass;
use ReflectionMethod;
use Illuminate\Support\Arr;
use League\Fractal\Manager;
use Illuminate\Routing\Route;
use Mpociot\ApiDoc\Tools\Flags;
Expand Down Expand Up @@ -80,15 +81,15 @@ private function getTransformerClass($tag)
*/
private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod)
{
$modelTag = array_first(array_filter($tags, function ($tag) {
$modelTag = Arr::first(array_filter($tags, function ($tag) {
return ($tag instanceof Tag) && strtolower($tag->getName()) == 'transformermodel';
}));

$type = null;
if ($modelTag) {
$type = $modelTag->getContent();
} else {
$parameter = array_first($transformerMethod->getParameters());
$parameter = Arr::first($transformerMethod->getParameters());
if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) {
// ladies and gentlemen, we have a type!
$type = (string) $parameter->getType();
Expand Down Expand Up @@ -146,6 +147,6 @@ private function getTransformerTag(array $tags)
})
);

return array_first($transFormerTags);
return Arr::first($transFormerTags);
}
}
13 changes: 7 additions & 6 deletions src/Tools/RouteMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mpociot\ApiDoc\Tools;

use Illuminate\Support\Str;
use Illuminate\Routing\Route;
use Dingo\Api\Routing\RouteCollection;
use Illuminate\Support\Facades\Route as RouteFacade;
Expand Down Expand Up @@ -71,18 +72,18 @@ private function shouldIncludeRoute(Route $route, array $routeRule, array $mustI
? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
: true;

return str_is($mustIncludes, $route->getName())
|| str_is($mustIncludes, $route->uri())
|| (str_is($routeRule['match']['domains'] ?? [], $route->getDomain())
&& str_is($routeRule['match']['prefixes'] ?? [], $route->uri())
return Str::is($mustIncludes, $route->getName())
|| Str::is($mustIncludes, $route->uri())
|| (Str::is($routeRule['match']['domains'] ?? [], $route->getDomain())
&& Str::is($routeRule['match']['prefixes'] ?? [], $route->uri())
&& $matchesVersion);
}

private function shouldExcludeRoute(Route $route, array $routeRule)
{
$excludes = $routeRule['exclude'] ?? [];

return str_is($excludes, $route->getName())
|| str_is($excludes, $route->uri());
return Str::is($excludes, $route->getName())
|| Str::is($excludes, $route->uri());
}
}
7 changes: 5 additions & 2 deletions src/Tools/Traits/ParamHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Mpociot\ApiDoc\Tools\Traits;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;

trait ParamHelpers
{
/**
Expand Down Expand Up @@ -36,9 +39,9 @@ protected function cleanParams(array $params)
*/
protected function cleanValueFrom($name, $value, array &$values = [])
{
if (str_contains($name, '[')) {
if (Str::contains($name, '[')) {
$name = str_replace(['][', '[', ']', '..'], ['.', '.', '', '.*.'], $name);
}
array_set($values, str_replace('.*', '.0', $name), $value);
Arr::set($values, str_replace('.*', '.0', $name), $value);
}
}
33 changes: 17 additions & 16 deletions tests/Unit/GeneratorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mpociot\ApiDoc\Tests\Unit;

use Illuminate\Support\Arr;
use Orchestra\Testbench\TestCase;
use Mpociot\ApiDoc\Tools\Generator;
use Mpociot\ApiDoc\Tools\DocumentationConfig;
Expand Down Expand Up @@ -315,7 +316,7 @@ public function can_parse_response_tag()
{
$route = $this->createRoute('POST', '/responseTag', 'withResponseTag');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand All @@ -336,7 +337,7 @@ public function can_parse_response_tag_with_status_code()
{
$route = $this->createRoute('POST', '/responseTag', 'withResponseTagAndStatusCode');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand Down Expand Up @@ -385,7 +386,7 @@ public function can_parse_transformer_tag($serializer, $expected)
config(['apidoc.fractal.serializer' => $serializer]);
$route = $this->createRoute('GET', '/transformerTag', 'transformerTag');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand All @@ -403,7 +404,7 @@ public function can_parse_transformer_tag_with_model()
{
$route = $this->createRoute('GET', '/transformerTagWithModel', 'transformerTagWithModel');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand All @@ -421,7 +422,7 @@ public function can_parse_transformer_collection_tag()
{
$route = $this->createRoute('GET', '/transformerCollectionTag', 'transformerCollectionTag');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand All @@ -440,7 +441,7 @@ public function can_parse_transformer_collection_tag_with_model()
{
$route = $this->createRoute('GET', '/transformerCollectionTagWithModel', 'transformerCollectionTagWithModel');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand Down Expand Up @@ -469,7 +470,7 @@ public function can_call_route_and_generate_response()
],
];
$parsed = $this->generator->processRoute($route, $rules);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand All @@ -496,7 +497,7 @@ public function can_override_config_during_response_call()
],
];
$parsed = $this->generator->processRoute($route, $rules);
$response = json_decode(array_first($parsed['response'])['content'], true);
$response = json_decode(Arr::first($parsed['response'])['content'], true);
$originalValue = $response['app.env'];

$now = time();
Expand All @@ -509,7 +510,7 @@ public function can_override_config_during_response_call()
],
];
$parsed = $this->generator->processRoute($route, $rules);
$response = json_decode(array_first($parsed['response'])['content'], true);
$response = json_decode(Arr::first($parsed['response'])['content'], true);
$newValue = $response['app.env'];
$this->assertEquals($now, $newValue);
$this->assertNotEquals($originalValue, $newValue);
Expand All @@ -530,7 +531,7 @@ public function can_override_url_path_parameters_with_bindings()
],
];
$parsed = $this->generator->processRoute($route, $rules);
$response = json_decode(array_first($parsed['response'])['content'], true);
$response = json_decode(Arr::first($parsed['response'])['content'], true);
$param = $response['param'];
$this->assertEquals($rand, $param);
}
Expand All @@ -550,7 +551,7 @@ public function replaces_optional_url_path_parameters_with_bindings()
],
];
$parsed = $this->generator->processRoute($route, $rules);
$response = json_decode(array_first($parsed['response'])['content'], true);
$response = json_decode(Arr::first($parsed['response'])['content'], true);
$param = $response['param'];
$this->assertEquals($rand, $param);
}
Expand All @@ -573,12 +574,12 @@ public function uses_correct_bindings_by_prefix()
],
];
$parsed = $this->generator->processRoute($route1, $rules);
$response = json_decode(array_first($parsed['response'])['content'], true);
$response = json_decode(Arr::first($parsed['response'])['content'], true);
$param = $response['param'];
$this->assertEquals($rand1, $param);

$parsed = $this->generator->processRoute($route2, $rules);
$response = json_decode(array_first($parsed['response'])['content'], true);
$response = json_decode(Arr::first($parsed['response'])['content'], true);
$param = $response['param'];
$this->assertEquals($rand2, $param);
}
Expand All @@ -593,7 +594,7 @@ public function can_parse_response_file_tag()

$route = $this->createRoute('GET', '/responseFileTag', 'responseFileTag');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand All @@ -618,7 +619,7 @@ public function can_add_or_replace_key_value_pair_in_response_file()

$route = $this->createRoute('GET', '/responseFileTagAndCustomJson', 'responseFileTagAndCustomJson');
$parsed = $this->generator->processRoute($route);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand Down Expand Up @@ -717,7 +718,7 @@ public function uses_configured_settings_when_calling_route()
],
];
$parsed = $this->generator->processRoute($route, $rules);
$response = array_first($parsed['response']);
$response = Arr::first($parsed['response']);

$this->assertTrue(is_array($parsed));
$this->assertArrayHasKey('showresponse', $parsed);
Expand Down
15 changes: 8 additions & 7 deletions tests/Unit/RouteMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mpociot\ApiDoc\Tests\Unit;

use Illuminate\Support\Str;
use Dingo\Api\Routing\Router;
use Orchestra\Testbench\TestCase;
use Mpociot\ApiDoc\Tools\RouteMatcher;
Expand Down Expand Up @@ -108,7 +109,7 @@ public function testRespectsPrefixesRuleForLaravelRouter()
$routes = $this->matcher->getRoutesToBeDocumented($routeRules);
$this->assertCount(4, $routes);
foreach ($routes as $route) {
$this->assertTrue(str_is('prefix2/*', $route['route']->uri()));
$this->assertTrue(Str::is('prefix2/*', $route['route']->uri()));
}
}

Expand All @@ -130,14 +131,14 @@ public function testRespectsPrefixesRuleForDingoRouter()
$routes = $this->matcher->getDingoRoutesToBeDocumented($routeRules);
$this->assertCount(4, $routes);
foreach ($routes as $route) {
$this->assertTrue(str_is('prefix1/*', $route['route']->uri()));
$this->assertTrue(Str::is('prefix1/*', $route['route']->uri()));
}

$routeRules[0]['match']['prefixes'] = ['prefix2/*'];
$routes = $this->matcher->getDingoRoutesToBeDocumented($routeRules);
$this->assertCount(4, $routes);
foreach ($routes as $route) {
$this->assertTrue(str_is('prefix2/*', $route['route']->uri()));
$this->assertTrue(Str::is('prefix2/*', $route['route']->uri()));
}
}

Expand Down Expand Up @@ -337,14 +338,14 @@ public function testMergesRoutesFromDifferentRuleGroupsForLaravelRouter()

$routes = collect($routes);
$firstRuleGroup = $routes->filter(function ($route) {
return str_is('prefix1/*', $route['route']->uri())
&& str_is('domain1.*', $route['route']->getDomain());
return Str::is('prefix1/*', $route['route']->uri())
&& Str::is('domain1.*', $route['route']->getDomain());
});
$this->assertCount(2, $firstRuleGroup);

$secondRuleGroup = $routes->filter(function ($route) {
return str_is('prefix2/*', $route['route']->uri())
&& str_is('domain2.*', $route['route']->getDomain());
return Str::is('prefix2/*', $route['route']->uri())
&& Str::is('domain2.*', $route['route']->getDomain());
});
$this->assertCount(2, $secondRuleGroup);
}
Expand Down