浏览代码

Refactor syntax

shalvah 5 年之前
父节点
当前提交
353d680c93

+ 1 - 1
src/Commands/GenerateDocumentation.php

@@ -29,7 +29,7 @@ class GenerateDocumentation extends Command
      * @var string
      */
     protected $signature = "scribe:generate
-                            {--force: Discard any changes you've made to the Markdown files}
+                            {--force : Discard any changes you've made to the Markdown files}
     ";
 
     /**

+ 5 - 1
src/Extracting/ParamHelpers.php

@@ -111,13 +111,17 @@ trait ParamHelpers
      */
     protected function normalizeParameterType(string $type): string
     {
+        if (!$type) {
+            return 'string';
+        }
+
         $typeMap = [
             'int' => 'integer',
             'bool' => 'boolean',
             'double' => 'float',
         ];
 
-        return $type ? ($typeMap[$type] ?? $type) : 'string';
+        return $typeMap[$type] ?? $type;
     }
 
     /**

+ 2 - 2
src/Extracting/Strategies/BodyParameters/GetFromBodyParamTag.php

@@ -75,7 +75,7 @@ class GetFromBodyParamTag extends Strategy
                 $content = preg_replace('/\s?No-example.?/', '', $content);
                 if (empty($content)) {
                     // this means only name and type were supplied
-                    list($name, $type) = preg_split('/\s+/', $tag->getContent());
+                    [$name, $type] = preg_split('/\s+/', $tag->getContent());
                     $required = false;
                     $description = '';
                 } else {
@@ -89,7 +89,7 @@ class GetFromBodyParamTag extends Strategy
                 }
 
                 $type = $this->normalizeParameterType($type);
-                list($description, $example) = $this->parseParamDescription($description, $type);
+                [$description, $example] = $this->parseParamDescription($description, $type);
                 $value = is_null($example) && ! $this->shouldExcludeExample($tag->getContent())
                     ? $this->generateDummyValue($type)
                     : $example;

+ 1 - 1
src/Extracting/Strategies/Metadata/GetFromDocBlocks.php

@@ -26,7 +26,7 @@ class GetFromDocBlocks extends Strategy
 
     public function getMetadataFromDocBlock(DocBlock $methodDocBlock, DocBlock $classDocBlock): array
     {
-        list($routeGroupName, $routeGroupDescription, $routeTitle) = $this->getRouteGroupDescriptionAndTitle($methodDocBlock, $classDocBlock);
+        [$routeGroupName, $routeGroupDescription, $routeTitle] = $this->getRouteGroupDescriptionAndTitle($methodDocBlock, $classDocBlock);
 
         return [
             'groupName' => $routeGroupName,

+ 3 - 3
src/Extracting/Strategies/QueryParameters/GetFromQueryParamTag.php

@@ -75,11 +75,11 @@ class GetFromQueryParamTag extends Strategy
                 $content = preg_replace('/\s?No-example.?/', '', $content);
                 if (empty($content)) {
                     // this means only name was supplied
-                    list($name) = preg_split('/\s+/', $tag->getContent());
+                    [$name] = preg_split('/\s+/', $tag->getContent());
                     $required = false;
                     $description = '';
                 } else {
-                    list($_, $name, $required, $description) = $content;
+                    [$_, $name, $required, $description] = $content;
                     $description = trim($description);
                     if ($description == 'required' && empty(trim($required))) {
                         $required = $description;
@@ -88,7 +88,7 @@ class GetFromQueryParamTag extends Strategy
                     $required = trim($required) == 'required' ? true : false;
                 }
 
-                list($description, $value) = $this->parseParamDescription($description, 'string');
+                [$description, $value] = $this->parseParamDescription($description, 'string');
                 if (is_null($value) && ! $this->shouldExcludeExample($tag->getContent())) {
                     $value = Str::contains($description, ['number', 'count', 'page'])
                         ? $this->generateDummyValue('integer')

+ 2 - 2
src/Extracting/Strategies/ResponseFields/GetFromResponseFieldTag.php

@@ -46,10 +46,10 @@ class GetFromResponseFieldTag extends Strategy
                 preg_match('/(.+?)\s+(.+?)\s+(.*)/', $tag->getContent(), $content);
                 if (empty($content)) {
                     // this means only name and type were supplied
-                    list($name, $type) = preg_split('/\s+/', $tag->getContent());
+                    [$name, $type] = preg_split('/\s+/', $tag->getContent());
                     $description = '';
                 } else {
-                    list($_, $name, $type, $description) = $content;
+                    [$_, $name, $type, $description] = $content;
                     $description = trim($description);
                 }
 

+ 1 - 1
src/Extracting/Strategies/Responses/UseApiResourceTags.php

@@ -69,7 +69,7 @@ class UseApiResourceTags extends Strategy
             return null;
         }
 
-        list($statusCode, $apiResourceClass) = $this->getStatusCodeAndApiResourceClass($apiResourceTag);
+        [$statusCode, $apiResourceClass] = $this->getStatusCodeAndApiResourceClass($apiResourceTag);
         [$model, $factoryStates, $relations, $pagination] = $this->getClassToBeTransformedAndAttributes($tags);
         $modelInstance = $this->instantiateApiResourceModel($model, $factoryStates, $relations);