Skip to content

Commit

Permalink
Add Moodle PHPDoc checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin authored and ragusa87 committed Jun 7, 2019
1 parent 99eaabd commit 0408741
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/moodle-plugin-ci
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
13 changes: 13 additions & 0 deletions composer.json
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions src/Command/PHPDocCommand.php
@@ -0,0 +1,74 @@
<?php

/*
* This file is part of the Moodle Plugin CI package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Copyright (c) 2018 Blackboard Inc. (http://www.blackboard.com)
* License http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace MoodlePluginCI\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\ProcessBuilder;
use MoodlePluginCI\Bridge\MoodlePlugin;

class PHPDocCommand extends AbstractMoodleCommand
{
use ExecuteTrait;

protected function configure()
{
parent::configure();

$this->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;
}
}

0 comments on commit 0408741

Please sign in to comment.