diff --git a/composer.json b/composer.json index 90512c6a..bd6c470d 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/resources/views/documentarian.blade.php b/resources/views/documentarian.blade.php index 90151a73..ae973f83 100644 --- a/resources/views/documentarian.blade.php +++ b/resources/views/documentarian.blade.php @@ -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'] !!} diff --git a/src/Tools/Generator.php b/src/Tools/Generator.php index 9153e14d..9777b185 100644 --- a/src/Tools/Generator.php +++ b/src/Tools/Generator.php @@ -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; @@ -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'); } diff --git a/src/Tools/ResponseStrategies/TransformerTagsStrategy.php b/src/Tools/ResponseStrategies/TransformerTagsStrategy.php index 62ab3e9a..65e222a0 100644 --- a/src/Tools/ResponseStrategies/TransformerTagsStrategy.php +++ b/src/Tools/ResponseStrategies/TransformerTagsStrategy.php @@ -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; @@ -80,7 +81,7 @@ 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'; })); @@ -88,7 +89,7 @@ private function getClassToBeTransformed(array $tags, ReflectionMethod $transfor 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(); @@ -146,6 +147,6 @@ private function getTransformerTag(array $tags) }) ); - return array_first($transFormerTags); + return Arr::first($transFormerTags); } } diff --git a/src/Tools/RouteMatcher.php b/src/Tools/RouteMatcher.php index c98885f0..3f9ab607 100644 --- a/src/Tools/RouteMatcher.php +++ b/src/Tools/RouteMatcher.php @@ -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; @@ -71,10 +72,10 @@ 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); } @@ -82,7 +83,7 @@ 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()); } } diff --git a/src/Tools/Traits/ParamHelpers.php b/src/Tools/Traits/ParamHelpers.php index 6f72be10..352e6489 100644 --- a/src/Tools/Traits/ParamHelpers.php +++ b/src/Tools/Traits/ParamHelpers.php @@ -2,6 +2,9 @@ namespace Mpociot\ApiDoc\Tools\Traits; +use Illuminate\Support\Arr; +use Illuminate\Support\Str; + trait ParamHelpers { /** @@ -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); } } diff --git a/tests/Unit/GeneratorTestCase.php b/tests/Unit/GeneratorTestCase.php index 4a44090b..093b9081 100644 --- a/tests/Unit/GeneratorTestCase.php +++ b/tests/Unit/GeneratorTestCase.php @@ -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; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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(); @@ -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); @@ -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); } @@ -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); } @@ -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); } @@ -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); @@ -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); @@ -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); diff --git a/tests/Unit/RouteMatcherTest.php b/tests/Unit/RouteMatcherTest.php index 07ea60db..8fe9a9a3 100644 --- a/tests/Unit/RouteMatcherTest.php +++ b/tests/Unit/RouteMatcherTest.php @@ -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; @@ -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())); } } @@ -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())); } } @@ -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); }