Conditions | 8 |
Paths | 20 |
Total Lines | 74 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 3 | 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 |
||
91 | private function writeMarkdown($parsedRoutes) |
||
92 | { |
||
93 | $outputPath = $this->option('output'); |
||
94 | $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
||
95 | |||
96 | $infoText = view('apidoc::partials.info') |
||
1 ignored issue
–
show
|
|||
97 | ->with('outputPath', $this->option('output')) |
||
98 | ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')); |
||
99 | |||
100 | $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
||
101 | return $routeGroup->map(function ($route) { |
||
102 | $route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route); |
||
1 ignored issue
–
show
|
|||
103 | |||
104 | return $route; |
||
105 | }); |
||
106 | }); |
||
107 | |||
108 | $frontmatter = view('apidoc::partials.frontmatter'); |
||
109 | /* |
||
110 | * In case the target file already exists, we should check if the documentation was modified |
||
111 | * and skip the modified parts of the routes. |
||
112 | */ |
||
113 | if (file_exists($targetFile)) { |
||
114 | $generatedDocumentation = file_get_contents($targetFile); |
||
115 | |||
116 | if (preg_match('/<!-- START_INFO -->(.*)<!-- END_INFO -->/is', $generatedDocumentation, $generatedInfoText)) { |
||
117 | $infoText = trim($generatedInfoText[1], "\n"); |
||
118 | } |
||
119 | |||
120 | if (preg_match('/---(.*)---\\s<!-- START_INFO -->/is', $generatedDocumentation, $generatedFrontmatter)) { |
||
121 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
||
122 | } |
||
123 | |||
124 | $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation) { |
||
125 | return $routeGroup->transform(function ($route) use ($generatedDocumentation) { |
||
126 | if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $routeMatch) && ! $this->option('force')) { |
||
127 | $route['output'] = $routeMatch[0]; |
||
128 | } |
||
129 | |||
130 | return $route; |
||
131 | }); |
||
132 | }); |
||
133 | } |
||
134 | |||
135 | $documentarian = new Documentarian(); |
||
136 | |||
137 | $markdown = view('apidoc::documentarian') |
||
1 ignored issue
–
show
|
|||
138 | ->with('frontmatter', $frontmatter) |
||
139 | ->with('infoText', $infoText) |
||
140 | ->with('outputPath', $this->option('output')) |
||
141 | ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')) |
||
142 | ->with('parsedRoutes', $parsedRouteOutput); |
||
143 | |||
144 | if (! is_dir($outputPath)) { |
||
145 | $documentarian->create($outputPath); |
||
146 | } |
||
147 | |||
148 | file_put_contents($targetFile, $markdown); |
||
149 | |||
150 | $this->info('Wrote index.md to: '.$outputPath); |
||
151 | |||
152 | $this->info('Generating API HTML code'); |
||
153 | |||
154 | $documentarian->generate($outputPath); |
||
155 | |||
156 | $this->info('Wrote HTML documentation to: '.$outputPath.'/public/index.html'); |
||
157 | |||
158 | |||
159 | if ($this->option('noPostmanCollection') !== true) { |
||
160 | $this->info('Generating Postman collection'); |
||
161 | |||
162 | file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
||
163 | } |
||
164 | } |
||
165 | |||
309 |
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.