diff --git a/bin/moodle-plugin-ci b/bin/moodle-plugin-ci index aad021b..2300b30 100755 --- a/bin/moodle-plugin-ci +++ b/bin/moodle-plugin-ci @@ -24,6 +24,7 @@ use MoodlePluginCI\Command\InstallCommand; use MoodlePluginCI\Command\MessDetectorCommand; use MoodlePluginCI\Command\MustacheCommand; use MoodlePluginCI\Command\ParallelCommand; +use MoodlePluginCI\Command\PHPDocCommand; use MoodlePluginCI\Command\PHPLintCommand; use MoodlePluginCI\Command\PHPUnitCommand; use MoodlePluginCI\Command\SavePointsCommand; @@ -69,6 +70,7 @@ $application->add(new InstallCommand(ENV_FILE)); $application->add(new MessDetectorCommand()); $application->add(new MustacheCommand()); $application->add(new ParallelCommand()); +$application->add(new PHPDocCommand()); $application->add(new PHPLintCommand()); $application->add(new PHPUnitCommand()); $application->add(new SavePointsCommand()); diff --git a/composer.json b/composer.json index 7fef5fc..74fa0c3 100644 --- a/composer.json +++ b/composer.json @@ -48,12 +48,25 @@ "reference": "ea72c5f7c937014c1401a833e697afb3d95af7be" } } + }, + { + "type": "package", + "package": { + "name": "moodlehq/moodle-local_moodlecheck", + "version": "1.0.0", + "source": { + "url": "https://github.com/moodlehq/moodle-local_moodlecheck.git", + "type": "git", + "reference": "272187600c71a7833086c48f6ea40e7287074a7b" + } + } } ], "require": { "php": ">=5.6.0", "moodlehq/moodle-local_codechecker": "^2.5.4", "moodlehq/moodle-local_ci": "^1.0.2", + "moodlehq/moodle-local_moodlecheck": "^1.0.0", "sebastian/phpcpd": "^3.0", "phpmd/phpmd": "^2.2", "symfony/dotenv": "^3.3", diff --git a/composer.lock b/composer.lock index 91e5fd9..fb16745 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f1791741ea9c32f91d8b5cbdbaed0c03", + "content-hash": "3c48ab1514c8de874ab9327c951daaf3", "packages": [ { "name": "composer/ca-bundle", @@ -269,6 +269,16 @@ ] } }, + { + "name": "moodlehq/moodle-local_moodlecheck", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/moodlehq/moodle-local_moodlecheck.git", + "reference": "272187600c71a7833086c48f6ea40e7287074a7b" + }, + "type": "library" + }, { "name": "nikic/php-parser", "version": "v3.1.5", diff --git a/src/Command/PHPDocCommand.php b/src/Command/PHPDocCommand.php new file mode 100644 index 0000000..8341851 --- /dev/null +++ b/src/Command/PHPDocCommand.php @@ -0,0 +1,74 @@ +setName('phpdoc') + ->setDescription('Run Moodle PHPDoc Checker on a plugin'); + } + + protected function initialize(InputInterface $input, OutputInterface $output) + { + parent::initialize($input, $output); + $this->initializeExecute($output, $this->getHelper('process')); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->outputHeading($output, 'Moodle PHPDoc Checker on %s'); + + // We need local_moodlecheck plugin to run this check. + $pluginlocation = __DIR__.'/../../vendor/moodlehq/moodle-local_moodlecheck'; + $plugin = new MoodlePlugin($pluginlocation); + $directory = $this->moodle->getComponentInstallDirectory($plugin->getComponent()); + if (!is_dir($directory)) { + // Copy plugin into Moodle if it does not exist. + $filesystem = new Filesystem(); + $filesystem->mirror($plugin->directory, $directory); + } + + $process = $this->execute->passThroughProcess( + ProcessBuilder::create() + ->setPrefix('php') + ->add('local/moodlecheck/cli/moodlecheck.php') + ->add('-p=' . $this->plugin->directory) + ->add('-f=text') + ->setTimeout(null) + ->setWorkingDirectory($this->moodle->directory) + ->getProcess() + ); + + if (isset($filesystem)) { + // Remove plugin if we added it, so we leave things clean. + $filesystem->remove($directory); + } + + // moodlecheck.php does not return valid exit status, + // We have to parse output to see if there are errors. + $results = $process->getOutput(); + return (preg_match('/\s+Line/', $results)) ? 1 : 0; + } +}