From ea5aa008852be65bfe4d6f7cf88a10cb62422ec8 Mon Sep 17 00:00:00 2001 From: Francesco Danti Date: Sat, 26 Dec 2020 17:56:17 +0000 Subject: [PATCH 1/5] Apply fixes from StyleCI --- src/Builder/NamespaceIndexBuilder.php | 41 ++++++++++++++++---------- src/GenerateDocumentationCommand.php | 42 +++++++++++++++++++++------ 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/Builder/NamespaceIndexBuilder.php b/src/Builder/NamespaceIndexBuilder.php index 4ac33d8..e029fee 100755 --- a/src/Builder/NamespaceIndexBuilder.php +++ b/src/Builder/NamespaceIndexBuilder.php @@ -74,15 +74,21 @@ private function findChildNamespaces() /** @var Namespace_ $namespace */ foreach ($this->namespaces as $namespace) { // check if not root and doesn't start with current namespace - if ($currentNamespaceFqsen !== '\\' && strpos((string) $namespace->getFqsen(), - $currentNamespaceFqsen.'\\') !== 0) { + if ($currentNamespaceFqsen !== '\\' && strpos( + (string) $namespace->getFqsen(), + $currentNamespaceFqsen.'\\' + ) !== 0) { continue; } - if ((string) $namespace->getFqsen() !== $currentNamespaceFqsen && strpos((string) $namespace->getFqsen(), - $currentNamespaceFqsen) === 0) { + if ((string) $namespace->getFqsen() !== $currentNamespaceFqsen && strpos( + (string) $namespace->getFqsen(), + $currentNamespaceFqsen + ) === 0) { // only keep first level children - $childrenPath = substr((string) $namespace->getFqsen(), - strlen((string) $this->currentNamespace->getFqsen()) + 1); + $childrenPath = substr( + (string) $namespace->getFqsen(), + strlen((string) $this->currentNamespace->getFqsen()) + 1 + ); if (strpos($childrenPath, '\\') === false) { $this->childNamespaces[] = $namespace; } @@ -188,11 +194,11 @@ private function getElementList($type) private function getHeaderForType($type) { $headers = [self::RENDER_INDEX_NAMESPACE => 'Namespaces', - self::RENDER_INDEX_INTERFACES => 'Interfaces', - self::RENDER_INDEX_CLASSES => 'Classes', - self::RENDER_INDEX_TRAITS => 'Traits', - self::RENDER_INDEX_FUNCTIONS => 'Functions', - self::RENDER_INDEX_CONSTANTS => 'Constants', + self::RENDER_INDEX_INTERFACES => 'Interfaces', + self::RENDER_INDEX_CLASSES => 'Classes', + self::RENDER_INDEX_TRAITS => 'Traits', + self::RENDER_INDEX_FUNCTIONS => 'Functions', + self::RENDER_INDEX_CONSTANTS => 'Constants', ]; return $headers[$type]; @@ -202,8 +208,11 @@ private function addElementTocEntry(Fqsen $entry) { $currentNamespaceFqsen = (string) $this->currentNamespace->getFqsen(); $subPath = $entry; - if ($currentNamespaceFqsen !== '\\' && substr($entry, 0, - strlen($currentNamespaceFqsen)) === $currentNamespaceFqsen) { + if ($currentNamespaceFqsen !== '\\' && substr( + $entry, + 0, + strlen($currentNamespaceFqsen) + ) === $currentNamespaceFqsen) { $subPath = substr($entry, strlen($currentNamespaceFqsen)); } $path = substr(str_replace('\\', '/', $subPath), 1); @@ -244,8 +253,10 @@ private function addFunctions() /** @var Param $param */ $param = $params[$argument->getName()]; if ($param !== null) { - $this->addMultiline(':param '.self::escape($param->getType()).' $'.$argument->getName().': '.$param->getDescription(), - true); + $this->addMultiline( + ':param '.self::escape($param->getType()).' $'.$argument->getName().': '.$param->getDescription(), + true + ); } } } diff --git a/src/GenerateDocumentationCommand.php b/src/GenerateDocumentationCommand.php index 988a57a..1d27be2 100755 --- a/src/GenerateDocumentationCommand.php +++ b/src/GenerateDocumentationCommand.php @@ -39,15 +39,39 @@ class GenerateDocumentationCommand extends Command { protected function configure() { - $this->setName('generate')->setDescription('Generate documentation')->setHelp('This command allows you to generate sphinx/rst based documentation from PHPDoc annotations.')->addArgument('target', - InputArgument::REQUIRED, 'Destination for the generated rst files')->addArgument('src', - InputArgument::IS_ARRAY, 'Source directories to parse')->addOption('public-only', 'p', - InputOption::VALUE_NONE)->addOption('show-private', null, - InputOption::VALUE_NONE)->addOption('element-toc', 't', - InputOption::VALUE_NONE)->addOption('repo-github', null, InputOption::VALUE_REQUIRED, - 'Github URL of the projects git repository (requires --repo-base as well)', - false)->addOption('repo-base', null, InputOption::VALUE_REQUIRED, - 'Base path of the project git repository', false); + $this->setName('generate')->setDescription('Generate documentation')->setHelp('This command allows you to generate sphinx/rst based documentation from PHPDoc annotations.')->addArgument( + 'target', + InputArgument::REQUIRED, + 'Destination for the generated rst files' + )->addArgument( + 'src', + InputArgument::IS_ARRAY, + 'Source directories to parse' + )->addOption( + 'public-only', + 'p', + InputOption::VALUE_NONE + )->addOption( + 'show-private', + null, + InputOption::VALUE_NONE + )->addOption( + 'element-toc', + 't', + InputOption::VALUE_NONE + )->addOption( + 'repo-github', + null, + InputOption::VALUE_REQUIRED, + 'Github URL of the projects git repository (requires --repo-base as well)', + false + )->addOption( + 'repo-base', + null, + InputOption::VALUE_REQUIRED, + 'Base path of the project git repository', + false + ); } protected function execute(InputInterface $input, OutputInterface $output) From 0910a027a7ffabd0657c36a6077defe2dafafff3 Mon Sep 17 00:00:00 2001 From: Francesco Danti Date: Sat, 26 Dec 2020 18:56:55 +0100 Subject: [PATCH 2/5] fix Test generated directory --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 68138eb..6422147 100755 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ composer.phar /composer.lock .DS_Store .php_cs.cache -/build \ No newline at end of file +/build +/tests/documentor-doc/ +/tests/psr-doc/ +/tests/self-doc/ From 5a0811f41c9a7d7f6c349d600c0d8a373a38b73d Mon Sep 17 00:00:00 2001 From: Francesco Danti Date: Sat, 26 Dec 2020 19:00:05 +0100 Subject: [PATCH 3/5] Add assertion Unit tests --- tests/DocGenerationTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/DocGenerationTest.php b/tests/DocGenerationTest.php index 5fa92d4..47d4fe2 100755 --- a/tests/DocGenerationTest.php +++ b/tests/DocGenerationTest.php @@ -28,6 +28,8 @@ public function testBuildDocumentation() 'http://github.com/abbadon1334/phpdoc-to-rst/', ]); $apiDocBuilder->build(); + + $this->addToAssertionCount(1); } public function testDocumentingSelf() @@ -40,6 +42,8 @@ public function testDocumentingSelf() $apiDocBuilder->setDebugOutput(true); $apiDocBuilder->addExtension(InterfaceImplementors::class); $apiDocBuilder->build(); + + $this->addToAssertionCount(1); } public function testDocumentingPSR() @@ -52,6 +56,8 @@ public function testDocumentingPSR() $apiDocBuilder->setDebugOutput(true); $apiDocBuilder->addExtension(InterfaceImplementors::class); $apiDocBuilder->build(); + + $this->addToAssertionCount(1); } public function testDocumentingDocumentor() @@ -64,6 +70,8 @@ public function testDocumentingDocumentor() $apiDocBuilder->setDebugOutput(true); $apiDocBuilder->addExtension(InterfaceImplementors::class); $apiDocBuilder->build(); + + $this->addToAssertionCount(1); } public function testDocumentingWithExtension() @@ -84,5 +92,7 @@ public function testDocumentingWithExtension() 'master', ]); $apiDocBuilder->build(); + + $this->addToAssertionCount(1); } } From 7af2f140192c4dfe020ad7bd5b4e79dd17b12e47 Mon Sep 17 00:00:00 2001 From: Francesco Danti Date: Sat, 26 Dec 2020 19:01:15 +0100 Subject: [PATCH 4/5] Add script test and change to test-win (directory_separator) --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b6704e2..5e6e901 100755 --- a/composer.json +++ b/composer.json @@ -65,6 +65,7 @@ "# END BUILD - ALL OK" ], - "test": "vendor\\bin\\phpunit" + "test-win": "vendor\\bin\\phpunit", + "test": "vendor/bin/phpunit" } } From 1e0d9e1ee8f585a6890e67291bb9c19e0dcdcd2e Mon Sep 17 00:00:00 2001 From: Francesco Danti Date: Sat, 26 Dec 2020 19:11:38 +0100 Subject: [PATCH 5/5] Change travis after_script to after_success --- .gitignore | 1 + .travis.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6422147..e2efc87 100755 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ composer.phar /tests/documentor-doc/ /tests/psr-doc/ /tests/self-doc/ +/.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index 1a7236f..4b97515 100755 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_script: script: - php vendor/bin/phpunit --coverage-clover build/logs/clover.xml -after_script: +after_success: - php vendor/bin/codacycoverage clover build/logs/clover.xml - sh -c 'if( [ "$TRAVIS_PHP_VERSION" != "hhvm" ] ); then php vendor/bin/coveralls -v; fi;' - ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT \ No newline at end of file