From 9d99fa6b5e1badf65dcf54753ffb71756674faf2 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Sun, 6 Oct 2019 17:34:27 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Tools/Generator.php | 3 +- src/Tools/Utils.php | 14 +++--- tests/Unit/GeneratorTestCase.php | 84 ++++++++++++++++---------------- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/Tools/Generator.php b/src/Tools/Generator.php index 2612182..e111b48 100644 --- a/src/Tools/Generator.php +++ b/src/Tools/Generator.php @@ -74,7 +74,6 @@ class Generator $parsedRoute['bodyParameters'] = $bodyParameters; $parsedRoute['cleanBodyParameters'] = $this->cleanParams($bodyParameters); - $responses = $this->fetchResponses($controller, $method, $route, $rulesToApply, $parsedRoute); $parsedRoute['response'] = $responses; $parsedRoute['showresponse'] = ! empty($responses); @@ -98,6 +97,7 @@ class Generator return $this->iterateThroughStrategies('metadata', $context, [$route, $controller, $method, $rulesToApply]); } + protected function fetchUrlParameters(ReflectionClass $controller, ReflectionMethod $method, Route $route, array $rulesToApply, array $context = []) { return $this->iterateThroughStrategies('urlParameters', $context, [$route, $controller, $method, $rulesToApply]); @@ -113,7 +113,6 @@ class Generator return $this->iterateThroughStrategies('bodyParameters', $context, [$route, $controller, $method, $rulesToApply]); } - protected function fetchResponses(ReflectionClass $controller, ReflectionMethod $method, Route $route, array $rulesToApply, array $context = []) { $responses = $this->iterateThroughStrategies('responses', $context, [$route, $controller, $method, $rulesToApply]); diff --git a/src/Tools/Utils.php b/src/Tools/Utils.php index e864868..c2dae71 100644 --- a/src/Tools/Utils.php +++ b/src/Tools/Utils.php @@ -2,7 +2,6 @@ namespace Mpociot\ApiDoc\Tools; -use Illuminate\Support\Str; use Illuminate\Routing\Route; use League\Flysystem\Filesystem; use League\Flysystem\Adapter\Local; @@ -54,12 +53,12 @@ class Utils public static function replaceUrlParameterPlaceholdersWithValues(string $uri, array $urlParameters) { $matches = preg_match_all('/{.+?}/i', $uri, $parameterPaths); - if (!$matches) { + if (! $matches) { return $uri; } foreach ($parameterPaths[0] as $parameterPath) { - $key = trim($parameterPath, "{?}"); + $key = trim($parameterPath, '{?}'); if (isset($urlParameters[$key])) { $example = $urlParameters[$key]; $uri = str_replace($parameterPath, $example, $uri); @@ -89,7 +88,7 @@ class Utils public static function deleteDirectoryAndContents($dir) { - $adapter = new Local(realpath(__DIR__ . '/../../')); + $adapter = new Local(realpath(__DIR__.'/../../')); $fs = new Filesystem($adapter); $fs->deleteDir($dir); } @@ -99,11 +98,12 @@ class Utils $output = var_export($value, true); // Padding with x spaces so they align $split = explode("\n", $output); - $result = ""; - $padWith = str_repeat(" ", $indentationLevel); + $result = ''; + $padWith = str_repeat(' ', $indentationLevel); foreach ($split as $index => $line) { - $result .= ($index == 0 ? "" : "\n$padWith") . $line; + $result .= ($index == 0 ? '' : "\n$padWith").$line; } + return $result; } } diff --git a/tests/Unit/GeneratorTestCase.php b/tests/Unit/GeneratorTestCase.php index 28eef9f..4d402c8 100644 --- a/tests/Unit/GeneratorTestCase.php +++ b/tests/Unit/GeneratorTestCase.php @@ -1,4 +1,6 @@ - true, 'description' => 'Some object params.', ], - "yet_another_param.name" => [ - "type" => "string", - "description" => "Subkey in the object param.", - "required" => true, + 'yet_another_param.name' => [ + 'type' => 'string', + 'description' => 'Subkey in the object param.', + 'required' => true, ], 'even_more_param' => [ 'type' => 'array', 'required' => false, 'description' => 'Some array params.', ], - "even_more_param.*" => [ - "type" => "float", - "description" => "Subkey in the array param.", - "required" => false, + 'even_more_param.*' => [ + 'type' => 'float', + 'description' => 'Subkey in the array param.', + 'required' => false, ], - "book.name" => [ - "type" => "string", - "description" => "", - "required" => false, + 'book.name' => [ + 'type' => 'string', + 'description' => '', + 'required' => false, ], - "book.author_id" => [ - "type" => "integer", - "description" => "", - "required" => false, + 'book.author_id' => [ + 'type' => 'integer', + 'description' => '', + 'required' => false, ], - "book[pages_count]" => [ - "type" => "integer", - "description" => "", - "required" => false, + 'book[pages_count]' => [ + 'type' => 'integer', + 'description' => '', + 'required' => false, ], - "ids.*" => [ - "type" => "integer", - "description" => "", - "required" => false, + 'ids.*' => [ + 'type' => 'integer', + 'description' => '', + 'required' => false, ], - "users.*.first_name" => [ - "type" => "string", - "description" => "The first name of the user.", - "required" => false, - "value" => "John", + 'users.*.first_name' => [ + 'type' => 'string', + 'description' => 'The first name of the user.', + 'required' => false, + 'value' => 'John', ], - "users.*.last_name" => [ - "type" => "string", - "description" => "The last name of the user.", - "required" => false, - "value" => "Doe", + 'users.*.last_name' => [ + 'type' => 'string', + 'description' => 'The last name of the user.', + 'required' => false, + 'value' => 'Doe', ], ], $bodyParameters); } @@ -514,7 +516,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"}]}' ); } @@ -533,7 +535,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"}]}' ); } @@ -635,7 +637,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')); @@ -660,7 +662,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')); @@ -685,10 +687,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'));