Conditions | 8 |
Paths | 20 |
Total Lines | 72 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 2 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
89 | private function writeMarkdown($parsedRoutes) |
||
90 | { |
||
91 | $outputPath = $this->option('output'); |
||
92 | $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
||
93 | |||
94 | $infoText = view('apidoc::partials.info') |
||
1 ignored issue
–
show
|
|||
95 | ->with('outputPath', $this->option('output')) |
||
96 | ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')); |
||
97 | |||
98 | $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
||
99 | return $routeGroup->map(function($route){ |
||
100 | $route['output'] = (string)view('apidoc::partials.route')->with('parsedRoute', $route); |
||
1 ignored issue
–
show
|
|||
101 | return $route; |
||
102 | }); |
||
103 | }); |
||
104 | |||
105 | $frontmatter = view('apidoc::partials.frontmatter'); |
||
106 | /** |
||
107 | * In case the target file already exists, we should check if the documentation was modified |
||
108 | * and skip the modified parts of the routes. |
||
109 | */ |
||
110 | if (file_exists($targetFile)) { |
||
111 | $generatedDocumentation = file_get_contents($targetFile); |
||
112 | |||
113 | if (preg_match("/<!-- START_INFO -->(.*)<!-- END_INFO -->/is", $generatedDocumentation, $generatedInfoText)) { |
||
114 | $infoText = trim($generatedInfoText[1],"\n"); |
||
115 | } |
||
116 | |||
117 | if (preg_match("/---(.*)---\\s<!-- START_INFO -->/is", $generatedDocumentation, $generatedFrontmatter)) { |
||
118 | $frontmatter = trim($generatedFrontmatter[1],"\n"); |
||
119 | } |
||
120 | |||
121 | $parsedRouteOutput->transform(function ($routeGroup) use($generatedDocumentation) { |
||
122 | return $routeGroup->transform(function($route) use($generatedDocumentation) { |
||
123 | if (preg_match("/<!-- START_".$route['id']." -->(.*)<!-- END_".$route['id']." -->/is", $generatedDocumentation, $routeMatch) && !$this->option('force')) { |
||
124 | $route['output'] = $routeMatch[0]; |
||
125 | } |
||
126 | return $route; |
||
127 | }); |
||
128 | }); |
||
129 | } |
||
130 | |||
131 | $documentarian = new Documentarian(); |
||
132 | |||
133 | $markdown = view('apidoc::documentarian') |
||
1 ignored issue
–
show
|
|||
134 | ->with('frontmatter', $frontmatter) |
||
135 | ->with('infoText', $infoText) |
||
136 | ->with('outputPath', $this->option('output')) |
||
137 | ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')) |
||
138 | ->with('parsedRoutes', $parsedRouteOutput); |
||
139 | |||
140 | if (! is_dir($outputPath)) { |
||
141 | $documentarian->create($outputPath); |
||
142 | } |
||
143 | |||
144 | file_put_contents($targetFile, $markdown); |
||
145 | |||
146 | $this->info('Wrote index.md to: '.$outputPath); |
||
147 | |||
148 | $this->info('Generating API HTML code'); |
||
149 | |||
150 | $documentarian->generate($outputPath); |
||
151 | |||
152 | $this->info('Wrote HTML documentation to: '.$outputPath.'/public/index.html'); |
||
153 | |||
154 | |||
155 | if ($this->option('noPostmanCollection') !== true) { |
||
156 | $this->info('Generating Postman collection'); |
||
157 | |||
158 | file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
||
159 | } |
||
160 | } |
||
161 | |||
285 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.