Skip to content

Commit

Permalink
Merge pull request moodlehq#156 from andrewnicols/missingDocblockMore…
Browse files Browse the repository at this point in the history
…Specific

Make MissingDoclock code more specific (Fixes moodlehq#154)
  • Loading branch information
stronk7 authored Jun 14, 2024
2 parents 3961e3c + f3675a6 commit 22b99c9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt

## [Unreleased]
### Added
- The existing `moodle.PHPUnit.TestCaseCovers` sniff now detects multiple uses of the `@coversDefaultClass` annotation. Only one is allowed by class.
- The existing `moodle.PHPUnit.TestCaseCovers` sniff now detects multiple uses of the `@coversDefaultClass` annotation. Only one is allowed by class.

### Changed
- Made codes for `moodle.Commenting.MissingDocblock` more specific to the scenario (Fixes #154).

## [v3.4.7] - 2024-05-31
### Added
Expand Down
10 changes: 5 additions & 5 deletions moodle/Sniffs/Commenting/MissingDocblockSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function processScopes(File $phpcsFile, int $stackPtr): void {

if ($fileblock === null) {
$objectName = TokenUtil::getObjectName($phpcsFile, $stackPtr);
$phpcsFile->addError('Missing docblock for file %s', $stackPtr, 'Missing', [$objectName]);
$phpcsFile->addError('Missing docblock for file %s', $stackPtr, 'File', [$objectName]);
}
}

Expand All @@ -110,7 +110,7 @@ protected function processScopes(File $phpcsFile, int $stackPtr): void {
$objectName = TokenUtil::getObjectName($phpcsFile, $typePtr);
$objectType = TokenUtil::getObjectType($phpcsFile, $typePtr);

$phpcsFile->addError('Missing docblock for %s %s', $typePtr, 'Missing', [$objectType, $objectName]);
$phpcsFile->addError('Missing docblock for %s %s', $typePtr, ucfirst($objectType), [$objectType, $objectName]);
}

if ($artifactCount === 1) {
Expand Down Expand Up @@ -208,7 +208,7 @@ protected function processFunctions(File $phpcsFile, int $stackPtr): void {
);
}
} else {
$phpcsFile->addError('Missing docblock for %s %s', $typePtr, 'Missing', [$objectType, $objectName]);
$phpcsFile->addError('Missing docblock for %s %s', $typePtr, ucfirst($objectType), [$objectType, $objectName]);
}
}
}
Expand Down Expand Up @@ -255,14 +255,14 @@ protected function processConstants(File $phpcsFile, int $stackPtr): void {
$phpcsFile->addError(
'Missing docblock for constant %s::%s',
$typePtr,
'Missing',
'Constant',
[$containerName, $objectName]
);
} else {
$phpcsFile->addError(
'Missing docblock for constant %s',
$typePtr,
'Missing',
'Constant',
[$objectName]
);
}
Expand Down
22 changes: 21 additions & 1 deletion moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testMissingDocblockSniff(

public static function docblockCorrectnessProvider(): array {
$cases = [
'Multiple artifacts in a file' => [
'Multiple artifacts in a file, check messages' => [
'fixture' => 'multiple_artifacts',
'fixtureFilename' => null,
'errors' => [
Expand All @@ -72,6 +72,26 @@ public static function docblockCorrectnessProvider(): array {
'warnings' => [
],
],
'Multiple artifacts in a file, check codes' => [
'fixture' => 'multiple_artifacts',
'fixtureFilename' => null,
'errors' => [
1 => 'moodle.Commenting.MissingDocblock.File',
34 => 'moodle.Commenting.MissingDocblock.Function',
38 => 'moodle.Commenting.MissingDocblock.Class',
95 => 'moodle.Commenting.MissingDocblock.Interface',
118 => 'moodle.Commenting.MissingDocblock.Trait',
151 => 'moodle.Commenting.MissingDocblock.Function',
159 => 'moodle.Commenting.MissingDocblock.Function',
166 => 'moodle.Commenting.MissingDocblock.Function',
170 => 'moodle.Commenting.MissingDocblock.Class',
171 => 'moodle.Commenting.MissingDocblock.Function',
175 => 'moodle.Commenting.MissingDocblock.Class',
176 => 'moodle.Commenting.MissingDocblock.Function',
],
'warnings' => [
],
],
'File level tag, no class' => [
'fixture' => 'class_without_docblock',
'fixtureFilename' => null,
Expand Down

0 comments on commit 22b99c9

Please sign in to comment.