Skip to content

Commit

Permalink
Merge pull request #94 from stronk7/avoid_abstract_infinite_loop
Browse files Browse the repository at this point in the history
Avoid abstract infinite loop
  • Loading branch information
stronk7 authored Jan 26, 2024
2 parents de2bd4d + 6ffdc32 commit 5c4f6c5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion moodle/Sniffs/PHPUnit/TestCaseCoversSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function process(File $file, $pointer) {
}

// Advance until the end of the method, if possible, to find the next one quicker.
$mStart = $tokens[$mStart]['scope_closer'] ?? $pointer + 1;
$mStart = $tokens[$mStart]['scope_closer'] ?? $mStart + 1;
}
}
}
Expand Down
14 changes: 2 additions & 12 deletions moodle/Sniffs/PHPUnit/TestCaseNamesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use MoodleHQ\MoodleCS\moodle\Util\MoodleUtil;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHPCSUtils\Utils\FunctionDeclarations;

class TestCaseNamesSniff implements Sniff {

Expand Down Expand Up @@ -122,17 +121,8 @@ public function process(File $file, $pointer) {
$method = '';
$methodFound = false;
while ($mStart = $file->findNext(T_FUNCTION, $pointer, $tokens[$cStart]['scope_closer'])) {
$info = FunctionDeclarations::getProperties($file, $mStart);
if (!$info['has_body']) {
// Some methods have no body (for example, abstract).
// Therefore there is no scope_closer
// There may be a parenthesis closer, or a semi-colon,
// but there is no easy way to determine this.
// Fall back to finding the next function based on the pointer position.
$pointer = $mStart + 1;
continue;
}
$pointer = $tokens[$mStart]['scope_closer']; // Next iteration look after the end of current method.
// Next iteration, advance until the end of the method, if possible, to find the next one quicker.
$pointer = $tokens[$mStart]['scope_closer'] ?? $mStart + 1;
if (strpos($file->getDeclarationName($mStart), 'test_') === 0) {
$methodFound = true;
$method = $file->getDeclarationName($mStart);
Expand Down
2 changes: 1 addition & 1 deletion moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function process(File $file, $pointer): void
}

// Advance until the end of the method, if possible, to find the next one quicker.
$mStart = $tokens[$mStart]['scope_closer'] ?? $pointer + 1;
$mStart = $tokens[$mStart]['scope_closer'] ?? $mStart + 1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ abstract public function generate_test_data(): array;

abstract public function generate_example_data();

public function test_something(): void {
$data = $this->generate_test_data();
// Test something with the data.
}
abstract public function test_something(): void;
}

0 comments on commit 5c4f6c5

Please sign in to comment.