--- /dev/null
+<?php
+/**
+ * This sniff is based on PSR2_Sniffs_Methods_MethodDeclarationSniff. Originally written
+ * by Greg Sherwood <gsherwood@squiz.net> and released under the terms of the BSD Licence.
+ * See: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php
+ *
+ * @author Tim Duesterhus
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @category Community Framework
+ */
+class WCF_Sniffs_Methods_MethodDeclarationSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff {
+ /**
+ * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff.
+ */
+ public function __construct() {
+ parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION));
+ }
+
+ /**
+ * Processes the function tokens within the class.
+ *
+ * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
+ * @param int $stackPtr The position where the token was found.
+ * @param int $currScope The current scope opener token.
+ *
+ * @return void
+ */
+ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ $methodName = $phpcsFile->getDeclarationName($stackPtr);
+ if ($methodName === null) {
+ // Ignore closures.
+ return;
+ }
+
+ $visibility = 0;
+ $static = 0;
+ $abstract = 0;
+ $final = 0;
+
+ $find = PHP_CodeSniffer_Tokens::$methodPrefixes;
+ $find[] = T_WHITESPACE;
+ $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
+
+ $prefix = $stackPtr;
+ while (($prefix = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) {
+ switch ($tokens[$prefix]['code']) {
+ case T_STATIC:
+ $static = $prefix;
+ break;
+ case T_ABSTRACT:
+ $abstract = $prefix;
+ break;
+ case T_FINAL:
+ $final = $prefix;
+ break;
+ default:
+ $visibility = $prefix;
+ break;
+ }
+ }
+
+ if ($abstract > $visibility) {
+ $error = 'The abstract declaration must precede the visibility declaration';
+ $phpcsFile->addError($error, $abstract, 'AbstractAfterVisibility');
+ }
+
+ if ($static !== 0 && $static < $visibility) {
+ $error = 'The static declaration must come after the visibility declaration';
+ $phpcsFile->addError($error, $static, 'StaticBeforeVisibility');
+ }
+
+ if ($final !== 0 && ($final < $visibility || $final < $static)) {
+ $error = 'The final declaration must come after the visibility declaration and after the static declaration';
+ $phpcsFile->addError($error, $final, 'FinalBeforeVisibilityOrBeforeStatic');
+ }
+ }
+}
\ No newline at end of file
* @package com.woltlab.wcf
* @category Community Framework
*/
-class WCF_Sniffs_Namespaces_ClassMustBeImportedSniff implements PHP_CodeSniffer_Sniff {
+class WCF_Sniffs_Namespaces_ClassMustBeImportedSniff implements PHP_CodeSniffer_Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
<exclude-pattern>*/CodeSniff/*</exclude-pattern>
<rule ref="Generic.Classes.DuplicateClassName" />
+ <rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
<rule ref="Generic.Files.ByteOrderMark" />
<rule ref="Generic.Files.EndFileNewline" />
<rule ref="Generic.Files.OneClassPerFile" />
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
<rule ref="Squiz.Arrays.ArrayBracketSpacing" />
<rule ref="Squiz.Classes.LowercaseClassKeywords" />
- <rule ref="Squiz.Classes.SelfMemberReference" /> <!-- TODO: Is this wanted? -->
+ <rule ref="Squiz.Classes.SelfMemberReference" />
<rule ref="Squiz.Classes.ValidClassName" />
<rule ref="Squiz.Commenting.DocCommentAlignment" />
<rule ref="Squiz.ControlStructures.ElseIfDeclaration" />
<rule ref="Squiz.ControlStructures.LowercaseDeclaration" />
<rule ref="Squiz.Operators.ValidLogicalOperators" />
<rule ref="Squiz.PHP.ForbiddenFunctions" />
+ <rule ref="Squiz.Scope.MethodScope" />
<rule ref="WCF.Classes.ClassFileName" />
<rule ref="WCF.ControlStructures.ControlSignature" />
- <!--rule ref="WCF.PHP.DiscouragePCRE" /--> <!-- TODO: Sniff is disabled by commenting out the extends in the sniff file! -->
+ <rule ref="WCF.Methods.MethodDeclaration" />
<rule ref="WCF.Namespaces.ClassMustBeImported" />
<rule ref="WCF.Namespaces.SortedUseDeclaration" />
<rule ref="WCF.Namespaces.UseDeclaration" />
+ <!--rule ref="WCF.PHP.DiscouragePCRE" /--> <!-- TODO: Sniff is disabled by commenting out the extends in the sniff file! -->
<rule ref="WCF.WhiteSpace.SuperfluousWhitespace" />
<rule ref="Zend.Files.ClosingTag" />
public function execute(Cronjob $cronjob) {
parent::execute($cronjob);
+ return;
// TODO
}
}
/**
* Connects to database server.
*/
- public abstract function connect();
+ abstract public function connect();
/**
* Returns ID from last insert.
* @category Community Framework
*/
class NamedUserException extends UserException {
- /**
- * Creates a new NamedUserException object.
- *
- * @param string $message
- */
- public function __construct($message) {
- parent::__construct($message);
- }
-
/**
* Shows a styled page with the given error message.
*/
/**
* Disconnects the Client-Server connection
*/
- function disconnect() {
+ public function disconnect() {
if ($this->connection === null) {
return;
}
* @param string $categoryName
* @param integer $existingOptionID
*/
- protected abstract function saveOption($option, $categoryName, $existingOptionID = 0);
+ abstract protected function saveOption($option, $categoryName, $existingOptionID = 0);
/**
* @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete()