@@ -17,12 +17,12 @@ |
||
| 17 | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | */ |
| 20 | -include __DIR__.'/../vendor/autoload.php'; |
|
| 20 | +include __DIR__ . '/../vendor/autoload.php'; |
|
| 21 | 21 | |
| 22 | 22 | use JuliusHaertl\PHPDocToRst\ApiDocBuilder; |
| 23 | 23 | |
| 24 | -$src = [__DIR__.'/../src']; |
|
| 25 | -$dst = __DIR__.'/../tests/test-project-doc'; |
|
| 24 | +$src = [__DIR__ . '/../src']; |
|
| 25 | +$dst = __DIR__ . '/../tests/test-project-doc'; |
|
| 26 | 26 | |
| 27 | 27 | $apiDocBuilder = new ApiDocBuilder($src, $dst); |
| 28 | 28 | $apiDocBuilder->setVerboseOutput(true); |
@@ -67,15 +67,15 @@ |
||
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | $filePath = $builder->getFile()->getPath(); |
| 70 | - $filePath = preg_replace('/^'.preg_quote($this->basePath, '/').'/', '', $filePath); |
|
| 70 | + $filePath = preg_replace('/^' . preg_quote($this->basePath, '/') . '/', '', $filePath); |
|
| 71 | 71 | $lineNumber = $element->getLocation()->getLineNumber(); |
| 72 | 72 | $url = $this->getGithubLink($filePath, $lineNumber, $this->branch); |
| 73 | - $builder->addFieldList('Source', '`'.$filePath.'#'.$lineNumber.' <'.$url.'>`_'); |
|
| 73 | + $builder->addFieldList('Source', '`' . $filePath . '#' . $lineNumber . ' <' . $url . '>`_'); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | private function getGithubLink($file, $line = 1, $branch = 'master') |
| 78 | 78 | { |
| 79 | - return $this->githubRepo.'/blob/'.$branch.'/'.$file.'#L'.$line; |
|
| 79 | + return $this->githubRepo . '/blob/' . $branch . '/' . $file . '#L' . $line; |
|
| 80 | 80 | } |
| 81 | 81 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | if ($element instanceof Method || $element instanceof Property) { |
| 44 | 44 | /** @var Method|Property $class */ |
| 45 | 45 | $class = $element; |
| 46 | - if ((string) $class->getVisibility() !== 'public') { |
|
| 46 | + if ((string)$class->getVisibility() !== 'public') { |
|
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | if ($element instanceof Class_) { |
| 44 | 44 | $modifiers = $element->isAbstract() ? 'abstract' : ''; |
| 45 | 45 | $modifiers = $element->isFinal() ? ' final' : $modifiers; |
| 46 | - $builder->addLine(':php:`'.$modifiers.' class '.RstBuilder::escape($builder->getElement()->getName()).' {}`'); |
|
| 46 | + $builder->addLine(':php:`' . $modifiers . ' class ' . RstBuilder::escape($builder->getElement()->getName()) . ' {}`'); |
|
| 47 | 47 | $builder->addLine(); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | if ($element instanceof Method || $element instanceof Property) { |
| 44 | 44 | /** @var Method|Property $class */ |
| 45 | 45 | $class = $element; |
| 46 | - if ((string) $class->getVisibility() === 'private') { |
|
| 46 | + if ((string)$class->getVisibility() === 'private') { |
|
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | foreach ($this->project->getFiles() as $file) { |
| 39 | 39 | foreach ($file->getClasses() as $class) { |
| 40 | 40 | foreach ($class->getInterfaces() as $interface) { |
| 41 | - if (!array_key_exists((string) $interface, $this->implementors)) { |
|
| 42 | - $this->implementors[(string) $interface] = []; |
|
| 41 | + if (!array_key_exists((string)$interface, $this->implementors)) { |
|
| 42 | + $this->implementors[(string)$interface] = []; |
|
| 43 | 43 | } |
| 44 | - $this->implementors[(string) $interface][] = $class->getFqsen(); |
|
| 44 | + $this->implementors[(string)$interface][] = $class->getFqsen(); |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -61,15 +61,15 @@ discard block |
||
| 61 | 61 | /** @var Interface_ $interface */ |
| 62 | 62 | $interface = $builder->getElement(); |
| 63 | 63 | $content = ''; |
| 64 | - if (!array_key_exists((string) $interface->getFqsen(), $this->implementors)) { |
|
| 64 | + if (!array_key_exists((string)$interface->getFqsen(), $this->implementors)) { |
|
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | - $implementors = $this->implementors[(string) $interface->getFqsen()]; |
|
| 67 | + $implementors = $this->implementors[(string)$interface->getFqsen()]; |
|
| 68 | 68 | if (count($implementors) === 0) { |
| 69 | 69 | return; |
| 70 | 70 | } |
| 71 | 71 | foreach ($implementors as $implementor) { |
| 72 | - $content .= ':php:class:`'.RstBuilder::escape(substr($implementor, 1)).'` '; |
|
| 72 | + $content .= ':php:class:`' . RstBuilder::escape(substr($implementor, 1)) . '` '; |
|
| 73 | 73 | } |
| 74 | 74 | $builder->addFieldList('Implemented by', $content); |
| 75 | 75 | $builder->addLine(); |
@@ -54,16 +54,16 @@ |
||
| 54 | 54 | /** @var Argument $argument */ |
| 55 | 55 | foreach ($method->getArguments() as $argument) { |
| 56 | 56 | // TODO: defaults, types |
| 57 | - $args .= '$'.$argument->getName().', '; |
|
| 57 | + $args .= '$' . $argument->getName() . ', '; |
|
| 58 | 58 | } |
| 59 | 59 | $args = substr($args, 0, -2); |
| 60 | 60 | $modifiers = $method->getVisibility(); |
| 61 | 61 | $modifiers .= $method->isAbstract() ? ' abstract' : ''; |
| 62 | 62 | $modifiers .= $method->isFinal() ? ' final' : ''; |
| 63 | 63 | $modifiers .= $method->isStatic() ? ' static' : ''; |
| 64 | - $signature = $modifiers.' '.$method->getName().'('.$args.')'; |
|
| 64 | + $signature = $modifiers . ' ' . $method->getName() . '(' . $args . ')'; |
|
| 65 | 65 | |
| 66 | - $builder->addLine('* '.PhpDomainBuilder::getLink('meth', $method->getFqsen(), $signature)); |
|
| 66 | + $builder->addLine('* ' . PhpDomainBuilder::getLink('meth', $method->getFqsen(), $signature)); |
|
| 67 | 67 | } |
| 68 | 68 | $builder->addLine()->addLine(); |
| 69 | 69 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function __construct($srcDir, $dstDir) |
| 91 | 91 | { |
| 92 | 92 | $this->dstDir = $dstDir; |
| 93 | - $this->srcDir = (array) $srcDir; |
|
| 93 | + $this->srcDir = (array)$srcDir; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | try { |
| 126 | 126 | $interfaceList[] = new LocalFile($file->getPathname()); |
| 127 | 127 | } catch (Exception $e) { |
| 128 | - $this->log('Failed to load '.$file->getPathname().PHP_EOL); |
|
| 128 | + $this->log('Failed to load ' . $file->getPathname() . PHP_EOL); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | foreach ($this->extensionNames as $extensionName) { |
| 152 | 152 | $extension = new $extensionName($this->project, $this->extensionArguments[$extensionName]); |
| 153 | 153 | if (!is_subclass_of($extension, Extension::class)) { |
| 154 | - $this->log('Failed to load extension '.$extensionName.'.'); |
|
| 154 | + $this->log('Failed to load extension ' . $extensionName . '.'); |
|
| 155 | 155 | } |
| 156 | 156 | $this->extensions[] = $extension; |
| 157 | - $this->log('Extension '.$extensionName.' loaded.'); |
|
| 157 | + $this->log('Extension ' . $extensionName . ' loaded.'); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | public function log($message) |
| 167 | 167 | { |
| 168 | 168 | if ($this->verboseOutput) { |
| 169 | - echo $message.PHP_EOL; |
|
| 169 | + echo $message . PHP_EOL; |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | private function createDirectoryStructure() |
| 179 | 179 | { |
| 180 | 180 | foreach ($this->project->getNamespaces() as $namespace) { |
| 181 | - $namespaceDir = $this->dstDir.str_replace('\\', '/', $namespace->getFqsen()); |
|
| 181 | + $namespaceDir = $this->dstDir . str_replace('\\', '/', $namespace->getFqsen()); |
|
| 182 | 182 | if (is_dir($namespaceDir)) { |
| 183 | 183 | continue; |
| 184 | 184 | } |
| 185 | 185 | if (!mkdir($namespaceDir, 0755, true)) { |
| 186 | - throw new WriteException('Could not create directory '.$namespaceDir); |
|
| 186 | + throw new WriteException('Could not create directory ' . $namespaceDir); |
|
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -202,43 +202,43 @@ discard block |
||
| 202 | 202 | foreach ($file->getInterfaces() as $interface) { |
| 203 | 203 | $fqsen = $interface->getFqsen(); |
| 204 | 204 | $builder = new InterfaceFileBuilder($file, $interface, $this->extensions); |
| 205 | - $filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst'; |
|
| 205 | + $filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst'; |
|
| 206 | 206 | file_put_contents($filename, $builder->getContent()); |
| 207 | - $this->docFiles[(string) $interface->getFqsen()] = str_replace('\\', '/', $fqsen); |
|
| 207 | + $this->docFiles[(string)$interface->getFqsen()] = str_replace('\\', '/', $fqsen); |
|
| 208 | 208 | |
| 209 | 209 | // also build root namespace in indexes |
| 210 | - if (strpos((string) substr($fqsen, 1), '\\') === false) { |
|
| 210 | + if (strpos((string)substr($fqsen, 1), '\\') === false) { |
|
| 211 | 211 | $this->project->getRootNamespace()->addInterface($fqsen); |
| 212 | 212 | } |
| 213 | - $this->debug('Written interface documentation to '.$filename); |
|
| 213 | + $this->debug('Written interface documentation to ' . $filename); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | foreach ($file->getClasses() as $class) { |
| 217 | 217 | $fqsen = $class->getFqsen(); |
| 218 | 218 | $builder = new ClassFileBuilder($file, $class, $this->extensions); |
| 219 | - $filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst'; |
|
| 219 | + $filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst'; |
|
| 220 | 220 | file_put_contents($filename, $builder->getContent()); |
| 221 | - $this->docFiles[(string) $class->getFqsen()] = str_replace('\\', '/', $fqsen); |
|
| 221 | + $this->docFiles[(string)$class->getFqsen()] = str_replace('\\', '/', $fqsen); |
|
| 222 | 222 | |
| 223 | 223 | // also build root namespace in indexes |
| 224 | - if (strpos((string) substr($class->getFqsen(), 1), '\\') === false) { |
|
| 224 | + if (strpos((string)substr($class->getFqsen(), 1), '\\') === false) { |
|
| 225 | 225 | $this->project->getRootNamespace()->addClass($fqsen); |
| 226 | 226 | } |
| 227 | - $this->debug('Written class documentation to '.$filename); |
|
| 227 | + $this->debug('Written class documentation to ' . $filename); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | foreach ($file->getTraits() as $trait) { |
| 231 | 231 | $fqsen = $trait->getFqsen(); |
| 232 | 232 | $builder = new TraitFileBuilder($file, $trait, $this->extensions); |
| 233 | - $filename = $this->dstDir.str_replace('\\', '/', $fqsen).'.rst'; |
|
| 233 | + $filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst'; |
|
| 234 | 234 | file_put_contents($filename, $builder->getContent()); |
| 235 | - $this->docFiles[(string) $trait->getFqsen()] = str_replace('\\', '/', $fqsen); |
|
| 235 | + $this->docFiles[(string)$trait->getFqsen()] = str_replace('\\', '/', $fqsen); |
|
| 236 | 236 | |
| 237 | 237 | // also build root namespace in indexes |
| 238 | - if (strpos((string) substr($fqsen, 1), '\\') === false) { |
|
| 238 | + if (strpos((string)substr($fqsen, 1), '\\') === false) { |
|
| 239 | 239 | $this->project->getRootNamespace()->addTrait($fqsen); |
| 240 | 240 | } |
| 241 | - $this->debug('Written trait documentation to '.$filename); |
|
| 241 | + $this->debug('Written trait documentation to ' . $filename); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // build array of functions per namespace |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | public function debug($message) |
| 271 | 271 | { |
| 272 | 272 | if ($this->debugOutput) { |
| 273 | - echo $message.PHP_EOL; |
|
| 273 | + echo $message . PHP_EOL; |
|
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
@@ -279,13 +279,13 @@ discard block |
||
| 279 | 279 | $this->log('Build indexes.'); |
| 280 | 280 | $namespaces = $this->project->getNamespaces(); |
| 281 | 281 | $namespaces['\\'] = $this->project->getRootNamespace(); |
| 282 | - usort($namespaces, function (Namespace_ $a, Namespace_ $b) { |
|
| 282 | + usort($namespaces, function(Namespace_ $a, Namespace_ $b) { |
|
| 283 | 283 | return strcmp($a->getFqsen(), $b->getFqsen()); |
| 284 | 284 | }); |
| 285 | 285 | /** @var Namespace_ $namespace */ |
| 286 | 286 | foreach ($namespaces as $namespace) { |
| 287 | - $fqsen = (string) $namespace->getFqsen(); |
|
| 288 | - $this->debug('Build namespace index for '.$fqsen); |
|
| 287 | + $fqsen = (string)$namespace->getFqsen(); |
|
| 288 | + $this->debug('Build namespace index for ' . $fqsen); |
|
| 289 | 289 | $functions = []; |
| 290 | 290 | $constants = []; |
| 291 | 291 | if (array_key_exists($fqsen, $this->functions)) { |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | $builder = new NamespaceIndexBuilder($this->extensions, $namespaces, $namespace, $functions, $constants); |
| 298 | 298 | $builder->render(); |
| 299 | - $path = $this->dstDir.str_replace('\\', '/', $fqsen).'/index.rst'; |
|
| 299 | + $path = $this->dstDir . str_replace('\\', '/', $fqsen) . '/index.rst'; |
|
| 300 | 300 | file_put_contents($path, $builder->getContent()); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | $this->log('Build main index files.'); |
| 304 | 304 | $builder = new MainIndexBuilder($namespaces); |
| 305 | 305 | $builder->render(); |
| 306 | - $path = $this->dstDir.'/index-namespaces-all.rst'; |
|
| 306 | + $path = $this->dstDir . '/index-namespaces-all.rst'; |
|
| 307 | 307 | file_put_contents($path, $builder->getContent()); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -50,12 +50,12 @@ |
||
| 50 | 50 | public function execute($command, callable $next) |
| 51 | 51 | { |
| 52 | 52 | $filename = $command->getFile()->path(); |
| 53 | - $this->apiDocBuilder->debug('Starting to parse file: '.$filename); |
|
| 53 | + $this->apiDocBuilder->debug('Starting to parse file: ' . $filename); |
|
| 54 | 54 | |
| 55 | 55 | try { |
| 56 | 56 | return $next($command); |
| 57 | 57 | } catch (Exception $e) { |
| 58 | - $this->apiDocBuilder->log('Unable to parse file "'.$filename.'", '.$e->getMessage()); |
|
| 58 | + $this->apiDocBuilder->log('Unable to parse file "' . $filename . '", ' . $e->getMessage()); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | } |