Skip to content

Commit

Permalink
Merge pull request #191 from stronk7/no_relevant_files
Browse files Browse the repository at this point in the history
No relevant files
  • Loading branch information
stronk7 authored Feb 25, 2022
2 parents 417e705 + 2221a6e commit c12ba0f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
8 changes: 6 additions & 2 deletions moodle/Sniffs/Files/MoodleInternalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function process(File $file, $pointer) {

// Find where real code is and check from there.
$pointer = $this->get_position_of_relevant_code($file, $pointer);
if (!$pointer) {
// The file only contains non-relevant (and non side-effects) code. We are done.
return;
}

if ($this->is_config_php_incluson($file, $pointer)) {
// We are requiring config.php. This file is good, hurrah!
Expand Down Expand Up @@ -136,8 +140,8 @@ public function process(File $file, $pointer) {
}

/**
* Finds the position of the first bit of relevant code (ignoring namespaces
* and define statements).
* Finds the position of the first bit of relevant code (ignoring namespaces,
* uses, declares and define statements).
*
* @param File $file The file being scanned.
* @param int $pointer The position in the stack.
Expand Down
14 changes: 13 additions & 1 deletion moodle/tests/files_moodleinternal_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,20 @@ public function test_moodle_files_moodleinternal_old_style_if_die() {
$this->verify_cs_results();
}

public function test_moodle_files_moodleinternal_no_relevant_ok() {
// Files that only contain non-relevant (and no side-effects) code.
$this->set_standard('moodle');
$this->set_sniff('moodle.Files.MoodleInternal');
$this->set_fixture(__DIR__ . '/fixtures/files/moodleinternal/no_relevant_ok.php');

$this->set_errors([]);
$this->set_warnings([]);

$this->verify_cs_results();
}

public function test_moodle_files_moodleinternal_unexpected() {
// Old style if statement MOODLE_INTERNAL check.
// Unexpected (not needed) check.
$this->set_standard('moodle');
$this->set_sniff('moodle.Files.MoodleInternal');
$this->set_fixture(__DIR__ . '/fixtures/files/moodleinternal/unexpected.php');
Expand Down
32 changes: 32 additions & 0 deletions moodle/tests/fixtures/files/moodleinternal/no_relevant_ok.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* A file that only contains non-relevant (and no side effects) code.
*/

declare(strict_types=1);
declare(encoding='UTF-8');
declare(ticks=1);

namespace local_codechecker;;

use something;
use various, things;
use something as elsething;

define('ONE', 1);
define('TWO', 2);
2 changes: 1 addition & 1 deletion tests/behat/ui.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Feature: Codechecker UI works as expected
| path | exclude | seen | notseen |
| local/codechecker/moodle/tests | */tests/fixtures/* | Files found: 8 | Invalid path |
| local/codechecker/moodle/tests | */tests/fixtures/* | moodlestandard_test.php | Invalid path |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Files found: 69 | Invalid path |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Files found: 70 | Invalid path |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Line 1 of the opening comment | moodle_php |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Inline comments must end | /phpcompat |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Inline comments must end | /phpcompat |
Expand Down

0 comments on commit c12ba0f

Please sign in to comment.