Skip to content

Commit

Permalink
Merge pull request #177 from kabalin/ui-output-standard
Browse files Browse the repository at this point in the history
Optionaly output PHPCS standard that caused the problem in UI
  • Loading branch information
stronk7 committed Feb 1, 2022
2 parents efb86bd + e8441ce commit 36c025d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
4 changes: 3 additions & 1 deletion index.php
Expand Up @@ -40,6 +40,7 @@
$pathlist = optional_param('path', '', PARAM_RAW);
$exclude = optional_param('exclude', '', PARAM_NOTAGS);
$includewarnings = optional_param('includewarnings', true, PARAM_BOOL);
$showstandard = optional_param('showstandard', false, PARAM_BOOL);

$pageparams = array();
if ($pathlist) {
Expand All @@ -49,6 +50,7 @@
$pageparams['exclude'] = $exclude;
}
$pageparams['includewarnings'] = $includewarnings;
$pageparams['showstandard'] = $showstandard;

admin_externalpage_setup('local_codechecker', '', $pageparams);

Expand Down Expand Up @@ -112,7 +114,7 @@
list($numerrors, $numwarnings) = local_codechecker_count_problems($xml);

// Output the results report.
echo $output->report($xml, $numerrors, $numwarnings);
echo $output->report($xml, $numerrors, $numwarnings, $showstandard);

// And clean the report temp file.
@unlink($reportfile);
Expand Down
1 change: 1 addition & 0 deletions lang/en/local_codechecker.php
Expand Up @@ -58,6 +58,7 @@
$string['privacy:metadata'] = 'The Code checker plugin does not store any personal data.';
$string['pluginname'] = 'Code checker';
$string['recheckfile'] = 'Re-check just this file';
$string['showstandard'] = 'Display phpcs standard associated with a problem';
$string['success'] = 'Well done!';
$string['summary'] = 'Total: {$a}';
$string['wholefile'] = 'File';
4 changes: 4 additions & 0 deletions locallib.php
Expand Up @@ -67,6 +67,10 @@ protected function definition() {
$mform->addElement('advcheckbox', 'includewarnings', get_string('includewarnings', 'local_codechecker'));
$mform->setType('includewarnings', PARAM_BOOL);

$mform->addElement('advcheckbox', 'showstandard', get_string('showstandard', 'local_codechecker'));
$mform->setType('showstandard', PARAM_BOOL);
$mform->setDefault('showstandard', false);

$mform->addElement('submit', 'submitbutton', get_string('check', 'local_codechecker'));
}
}
Expand Down
10 changes: 9 additions & 1 deletion renderer.php
Expand Up @@ -22,6 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_codechecker_renderer extends plugin_renderer_base {
/** @var bool show phpsc standard flag. */
private $showstandard;

/** @var array string replaces used to clean up the input line for display. */
protected $replaces = array(
"\t" => '<span>&#x25b6;</span>',
Expand Down Expand Up @@ -92,9 +95,11 @@ public function invald_path_message($path) {
* @param SimpleXMLElement $xml structure containing all the information to be rendered.
* @param int $numerrors total number of error-level violations in the run.
* @param int $numwarnings total number of warning-level violations in the run.
* @param bool $showstandard Show phpcs standard associated with problem.
* @return string the report html
*/
public function report(SimpleXMLElement $xml, $numerrors, $numwarnings) {
public function report(SimpleXMLElement $xml, $numerrors, $numwarnings, $showstandard = false) {
$this->showstandard = $showstandard;

$grandsummary = '';
$grandtype = '';
Expand Down Expand Up @@ -211,6 +216,9 @@ public function problem_message($problem, $prettypath) {
}

$sourceclass = str_replace('.', '_', $problem['source']);
if ($this->showstandard) {
$problem = (string) $problem . ' (' . $problem['source'] . ')';
}
$info = html_writer::tag('div', s($problem), array('class' => 'info ' . $sourceclass));

return $code . html_writer::tag('li', $info, array('class' => 'fail ' . $level));
Expand Down
36 changes: 23 additions & 13 deletions tests/behat/ui.feature
Expand Up @@ -8,25 +8,23 @@ Feature: Codechecker UI works as expected
Given I log in as "admin"
And I navigate to "Development > Code checker" in site administration
And I set the field "Path(s) to check" to "<path>"
And I set the field "Exclude" to "*/tests/fixtures/*"
When I press "Check code"
Then I should see "<seen>"
And I should not see "<notseen>"
And I log out

Examples:
| path | seen | notseen |
| index.php | Files found: 1 | Invalid path |
| index2.php | Invalid path index2.php | Files found: 1 |
| local/codechecker/version.php | Well done! | Invalid path |
| local/codechecker/moodle/tests/fixtures | Files found: 0 | Invalid path |
| local/codechecker/tests/ | local_codechecker_testcase.php | Invalid path |
| local/codechecker/tests/ | Files found: 2 | Invalid path |
| local/codechecker/tests/ | Well done! | Invalid path |
| admin/index.php | Files found: 1 | Invalid path |
| admin/index.php | Total: | Well done! |
| admin/index.php | Expected 1 space before | Well done! |
| admin/index.php | Inline comments must start | Well done! |
| path | seen | notseen |
| index.php | Files found: 1 | Invalid path |
| index2.php | Invalid path index2.php | Files found: 1 |
| local/codechecker/version.php | Well done! | Invalid path |
| local/codechecker/tests/ | local_codechecker_testcase.php | Invalid path |
| local/codechecker/tests/ | Files found: 2 | Invalid path |
| local/codechecker/tests/ | Well done! | Invalid path |
| local/codechecker/moodle/tests/fixtures/files/moodleinternal/problem.php | Files found: 1 | Invalid path |
| local/codechecker/moodle/tests/fixtures/files/moodleinternal/problem.php | Total: 2 error(s) and 1 warning(s) | Well done! |
| local/codechecker/moodle/tests/fixtures/files/moodleinternal/problem.php | Inline comments must end | Well done! |
| local/codechecker/moodle/tests/fixtures/files/moodleinternal/problem.php | Expected MOODLE_INTERNAL check | Well done! |

Scenario Outline: Verify that specified exclusions are performed
Given I log in as "admin"
Expand Down Expand Up @@ -76,3 +74,15 @@ Feature: Codechecker UI works as expected
When I press "Check code"
Then I should see "index.php"
And I should see "version.php"

Scenario: Optionally output PHPCS standard
Given I log in as "admin"
And I navigate to "Development > Code checker" in site administration
And I set the field "Path(s) to check" to "local/codechecker/moodle/tests/fixtures/files/moodleinternal/problem.php"
And I set the field "Display phpcs standard associated with a problem" to "1"
When I press "Check code"
Then I should see "moodle.Files.BoilerplateComment.WrongWhitespace"
And I set the field "Display phpcs standard associated with a problem" to "0"
And I press "Check code"
And I should not see "moodle.Files.BoilerplateComment.WrongWhitespace"
And I log out

0 comments on commit 36c025d

Please sign in to comment.