Skip to content

Commit 899f567

Browse files
author
Vincent Langlet
committed
✨ Abstract function should start by Abstract
1 parent 1e2488c commit 899f567

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ In Sniff/Commenting/FunctionCommentSniff:
6161
- don't check docblocks for test, setUp and tearDown methods (PHPunit, would be blank)
6262
- do check protected and private methods for docblocks
6363

64-
In Sniff/NamingConventions/ValidClassNameSniff
65-
- remove the abstract class name rule
66-
6764
In ruleset.xml
6865
- Disabled the class comment rule
6966
- Changed the concatenation spacing rule, for readability, to require 1 space around concatenation dot, instead of no spaces as the [Symfony](https://symfony.com/doc/current/contributing/code/standards.html#structure) standard requires.

Symfony3Custom/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
125125
break;
126126
}
127127

128+
/*
129+
* Prefix abstract classes with Abstract.
130+
*/
131+
if ('T_ABSTRACT' == $tokens[$stackPtr]['type']) {
132+
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
133+
$function = $phpcsFile->findNext(T_FUNCTION, $stackPtr);
134+
135+
// making sure we're not dealing with an abstract function
136+
if ($name && (is_null($function)
137+
|| $name < $function)
138+
&& substr($tokens[$name]['content'], 0, 8) != 'Abstract'
139+
) {
140+
$phpcsFile->addError(
141+
'Abstract class name is not prefixed with "Abstract"',
142+
$stackPtr,
143+
'InvalidAbstractName'
144+
);
145+
}
146+
break;
147+
}
148+
128149
$stackPtr++;
129150
}
130151

0 commit comments

Comments
 (0)