Skip to content

Commit

Permalink
Merge pull request #75 from stronk7/add_missing_codes
Browse files Browse the repository at this point in the history
Add a hand of missing codes that are mandatory in phpcs3
  • Loading branch information
stronk7 authored Jun 21, 2020
2 parents 56b3278 + aad98bc commit b5f743a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions moodle/Sniffs/Files/MoodleInternalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ public function process(PHP_CodeSniffer_File $file, $pointer) {

// Got here because, so something is not right.
if ($this->code_changes_global_state($file, $pointer, ($file->numTokens - 1))) {
$file->addError('Expected MOODLE_INTERNAL check or config.php inclusion. Change in global state detected.', $pointer);
$file->addError('Expected MOODLE_INTERNAL check or config.php inclusion. Change in global state detected.',
$pointer, 'MoodleInternalGlobalState');
} else {
// Only if there are more than one artifact (class, interface, trait), we show the warning.
// (files with only one, are allowed to be MOODLE_INTERNAL free - MDLSITE-5967).
if ($this->count_artifacts($file) > 1) {
$file->addWarning('Expected MOODLE_INTERNAL check or config.php inclusion. Multiple artifacts detected.', $pointer);
$file->addWarning('Expected MOODLE_INTERNAL check or config.php inclusion. Multiple artifacts detected.',
$pointer, 'MoodleInternalMultipleArtifacts');
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions moodle/Sniffs/NamingConventions/ValidVariableNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ protected function processMemberVar(PHP_CodeSniffer_File $phpcsfile, $stackptr)

if (preg_match('/[A-Z]+/', $membername)) {
$error = "Member variable \"$membername\" must be all lower-case";
$phpcsfile->addError($error, $stackptr);
$phpcsfile->addError($error, $stackptr, 'MemberNameLowerCase');
}

// Find underscores in variable names (accepting $_foo for private vars).
$pos = strpos($membername, '_');
if ($pos > 1) {
$error = "Member variable \"$membername\" must not contain underscores.";
$phpcsfile->addError($error, $stackptr);
$phpcsfile->addError($error, $stackptr, 'MemberNameUnderscore');
}

// Must not be preceded by 'var' keyword.
Expand All @@ -68,7 +68,7 @@ protected function processMemberVar(PHP_CodeSniffer_File $phpcsfile, $stackptr)
if ($tokens[$keyword]['line'] == $tokens[$stackptr]['line']) {
$error = "The 'var' keyword is not permitted." .
'Visibility must be explicitly declared with public, private or protected';
$phpcsfile->addError($error, $stackptr);
$phpcsfile->addError($error, $stackptr, 'MemberNameVisibility');
}
}

Expand Down Expand Up @@ -118,12 +118,12 @@ protected function processVariableInString(PHP_CodeSniffer_File $phpcsfile, $sta
private function validate_moodle_variable_name($varname, PHP_CodeSniffer_File $phpcsfile, $stackptr) {
if (preg_match('/[A-Z]+/', $varname) && !in_array($varname, self::$allowedglobals)) {
$error = "Variable \"$varname\" must be all lower-case";
$phpcsfile->addError($error, $stackptr);
$phpcsfile->addError($error, $stackptr, 'VariableNameLowerCase');
}

if (strpos($varname, '_') !== false && !in_array($varname, self::$allowedglobals)) {
$error = "Variable \"$varname\" must not contain underscores.";
$phpcsfile->addError($error, $stackptr);
$phpcsfile->addError($error, $stackptr, 'VariableNameUnderscore');
}
}
}

0 comments on commit b5f743a

Please sign in to comment.