Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hand of missing codes that are mandatory in phpcs3 #75

Merged
merged 1 commit into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
}