| Conditions | 9 |
| Paths | 4 |
| Total Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 92 | public function writeMarkdownAndSourceFiles(Collection $parsedRoutes) |
||
| 93 | { |
||
| 94 | $targetFile = $this->getSourceOutputPath() . '/source/index.md'; |
||
| 95 | $compareFile = $this->getSourceOutputPath() . '/source/.compare.md'; |
||
| 96 | |||
| 97 | $infoText = view('apidoc::partials.info') |
||
| 98 | ->with('outputPath', 'docs') |
||
| 99 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection); |
||
| 100 | |||
| 101 | $settings = ['languages' => $this->config->get('example_languages')]; |
||
| 102 | // Generate Markdown for each route |
||
| 103 | $parsedRouteOutput = $this->generateMarkdownOutputForEachRoute($parsedRoutes, $settings); |
||
| 104 | |||
| 105 | $frontmatter = view('apidoc::partials.frontmatter') |
||
| 106 | ->with('settings', $settings); |
||
| 107 | |||
| 108 | /* |
||
| 109 | * If the target file already exists, |
||
| 110 | * we check if the documentation was modified |
||
| 111 | * and skip the modified parts of the routes. |
||
| 112 | */ |
||
| 113 | if (file_exists($targetFile) && file_exists($compareFile)) { |
||
| 114 | $generatedDocumentation = file_get_contents($targetFile); |
||
| 115 | $compareDocumentation = file_get_contents($compareFile); |
||
| 116 | |||
| 117 | $parsedRouteOutput->transform(function (Collection $routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
||
| 118 | return $routeGroup->transform(function (array $route) use ($generatedDocumentation, $compareDocumentation) { |
||
| 119 | if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
||
| 120 | $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
||
| 121 | if ($routeDocumentationChanged === false || $this->forceIt) { |
||
| 122 | if ($routeDocumentationChanged) { |
||
| 123 | $this->output->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
||
| 124 | } |
||
| 125 | } else { |
||
| 126 | $this->output->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
||
| 127 | $route['modified_output'] = $existingRouteDoc[0]; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | return $route; |
||
| 132 | }); |
||
| 133 | }); |
||
| 134 | } |
||
| 135 | |||
| 136 | $prependFileContents = $this->getMarkdownToPrepend(); |
||
| 137 | $appendFileContents = $this->getMarkdownToAppend(); |
||
| 138 | |||
| 139 | $markdown = view('apidoc::documentarian') |
||
| 140 | ->with('writeCompareFile', false) |
||
| 141 | ->with('frontmatter', $frontmatter) |
||
| 142 | ->with('infoText', $infoText) |
||
| 143 | ->with('prependMd', $prependFileContents) |
||
| 144 | ->with('appendMd', $appendFileContents) |
||
| 145 | ->with('outputPath', $this->config->get('output')) |
||
| 146 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection) |
||
| 147 | ->with('parsedRoutes', $parsedRouteOutput); |
||
| 148 | |||
| 149 | $this->output->info('Writing index.md and source files to: ' . $this->getSourceOutputPath()); |
||
| 150 | |||
| 151 | if (! is_dir($this->getSourceOutputPath())) { |
||
| 152 | $documentarian = new Documentarian(); |
||
| 153 | $documentarian->create($this->getSourceOutputPath()); |
||
| 154 | } |
||
| 155 | |||
| 156 | // Write output file |
||
| 157 | file_put_contents($targetFile, $markdown); |
||
| 158 | |||
| 159 | // Write comparable markdown file |
||
| 160 | $compareMarkdown = view('apidoc::documentarian') |
||
| 161 | ->with('writeCompareFile', true) |
||
| 162 | ->with('frontmatter', $frontmatter) |
||
| 163 | ->with('infoText', $infoText) |
||
| 164 | ->with('prependMd', $prependFileContents) |
||
| 165 | ->with('appendMd', $appendFileContents) |
||
| 166 | ->with('outputPath', $this->config->get('output')) |
||
| 167 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection) |
||
| 168 | ->with('parsedRoutes', $parsedRouteOutput); |
||
| 169 | |||
| 170 | file_put_contents($compareFile, $compareMarkdown); |
||
| 171 | |||
| 172 | $this->output->info('Wrote index.md and source files to: ' . $this->getSourceOutputPath()); |
||
| 173 | } |
||
| 174 | |||
| 325 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.