/** * Processes the tokens within the scope. * * @param PHP_CodeSniffer_File $phpcsfile The file being processed. * @param int $stackptr The position where this token was * found. * @param int $currscope The position of the current scope. * * @return void */ protected function processtokenwithinscope(PHP_CodeSniffer_File $phpcsfile, $stackptr, $currscope) { $classname = $phpcsfile->getdeclarationname($currscope); $methodname = $phpcsfile->getdeclarationname($stackptr); // Is this a magic method. IE. is prefixed with "__". if (preg_match('|^__|', $methodname) !== 0) { $magicpart = substr($methodname, 2); if (in_array($magicpart, $this->_magicmethods) === false) { $error = "method name \"{$classname}::{$methodname}\" is invalid; " . 'only PHP magic methods should be prefixed with a double underscore'; $phpcsfile->adderror($error, $stackptr); } return; } // PHP4 constructors are allowed to break our rules. if ($methodname === $classname) { return; } // PHP4 destructors are allowed to break our rules. if ($methodname === '_' . $classname) { return; } $methodprops = $phpcsfile->getmethodproperties($stackptr); $ispublic = $methodprops['scope'] === 'private' ? false : true; $scope = $methodprops['scope']; $scopespecified = $methodprops['scope_specified']; // Only lower-case accepted if (preg_match('/[A-Z]+/', $methodname)) { if ($scopespecified === true) { $error = ucfirst($scope) . " method name \"{$classname}::{$methodname}\" must be in lower-case letters only"; } else { $error = "method name \"{$classname}::{$methodname}\" must be in lower-case letters only"; } $phpcsfile->adderror($error, $stackptr); return; } // No numbers accepted if (preg_match('/[0-9]+/', $methodname)) { if ($scopespecified === true) { $error = ucfirst($scope) . " method name \"{$classname}::{$methodname}\" must only contain letters"; } else { $error = "Method name \"{$classname}::{$methodname}\" must only contain letters"; } $phpcsfile->adderror($error, $stackptr); return; } }