Skip to content

Commit 33702cf

Browse files
committed
Allow one interface name be in new line
1 parent 43369e6 commit 33702cf

File tree

3 files changed

+19
-60
lines changed

3 files changed

+19
-60
lines changed

src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -245,27 +245,14 @@ public function processOpen(File $phpcsFile, $stackPtr)
245245
$nextClass = $phpcsFile->findNext($find, ($nextClass + 1), ($openingBrace - 1));
246246
}
247247

248-
$skip = array_merge(
249-
Tokens::$emptyTokens,
250-
[
251-
T_STRING,
252-
T_NS_SEPARATOR,
253-
]
254-
);
255-
256248
$classCount = count($classNames);
257249
$checkingImplements = false;
258250
$implementsToken = null;
259-
$oneInterface = false;
260251
foreach ($classNames as $n => $className) {
261252
if ($tokens[$className]['code'] === $keywordTokenType) {
262253
$checkingImplements = true;
263254
$implementsToken = $className;
264255

265-
if (false === $phpcsFile->findNext($skip, ($implementsToken + 1), ($openingBrace - 1), true)) {
266-
$oneInterface = true;
267-
}
268-
269256
continue;
270257
}
271258

@@ -328,39 +315,6 @@ public function processOpen(File $phpcsFile, $stackPtr)
328315
$phpcsFile->fixer->addNewline($prev);
329316
$phpcsFile->fixer->endChangeset();
330317
}
331-
} else if ($oneInterface === true) {
332-
if ($tokens[$implementsToken]['line'] !== $tokens[$className]['line']) {
333-
$error = 'Interface name should be in the same line as '.$keywordType.' keyword';
334-
$fix = $phpcsFile->addFixableError($error, $className, 'InterfaceWrongLine');
335-
if ($fix === true) {
336-
$phpcsFile->fixer->beginChangeset();
337-
$comments = [];
338-
339-
for ($i = ($implementsToken + 1); $i < $className; ++$i) {
340-
if ($tokens[$i]['code'] === T_COMMENT) {
341-
$comments[] = trim($tokens[$i]['content']);
342-
}
343-
344-
if ($tokens[$i]['code'] === T_WHITESPACE
345-
|| $tokens[$i]['code'] === T_COMMENT
346-
) {
347-
$phpcsFile->fixer->replaceToken($i, '');
348-
}
349-
}
350-
351-
$phpcsFile->fixer->addContent($implementsToken, ' ');
352-
if (empty($comments) === false) {
353-
$i = $className;
354-
while ($tokens[($i + 1)]['line'] === $tokens[$className]['line']) {
355-
++$i;
356-
}
357-
358-
$phpcsFile->fixer->addContentBefore($i, ' '.implode(' ', $comments));
359-
}
360-
361-
$phpcsFile->fixer->endChangeset();
362-
}//end if
363-
}//end if
364318
} else {
365319
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($className - 1), $implements);
366320
if ($tokens[$prev]['line'] !== $tokens[$className]['line']) {
@@ -371,7 +325,7 @@ public function processOpen(File $phpcsFile, $stackPtr)
371325

372326
$expected = ($classIndent + $this->indent);
373327
if ($found !== $expected) {
374-
$error = 'Expected %s spaces before interface name; %s found - '.$n.' :: '.$classCount;
328+
$error = 'Expected %s spaces before interface name; %s found';
375329
$data = [
376330
$expected,
377331
$found,

src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc.fixed

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,13 @@ class C2
162162

163163
} // phpcs:ignore Standard.Category.Sniff
164164

165-
interface I1 extends Foo
165+
interface I1 extends
166+
Foo
166167
{
167168
}
168169

169-
interface I2 extends Bar
170+
interface I2 extends
171+
Bar
170172
{
171173
}
172174

@@ -184,11 +186,13 @@ class C2 extends Bar
184186
{
185187
}
186188

187-
class C3 extends Foo implements Bar
189+
class C3 extends Foo implements
190+
Bar
188191
{
189192
}
190193

191-
class C4 extends Foo implements Bar
194+
class C4 extends Foo implements
195+
Bar
192196
{
193197
}
194198

@@ -198,22 +202,27 @@ class C5 extends Foo implements
198202
{
199203
}
200204

201-
class C6 extends \Foo\Bar implements \Baz\Bar
205+
class C6 extends \Foo\Bar implements
206+
\Baz\Bar
202207
{
203208
}
204209

205-
interface I4 extends \Baz\Bar
210+
interface I4 extends
211+
\Baz\Bar
206212
{
207213
}
208214

209-
interface I5 extends \Foo\Bar /* comment */
215+
interface I5 extends /* comment */
216+
\Foo\Bar
210217
{
211218
}
212219

213-
interface I6 extends \Foo\Bar // comment
220+
interface I6 extends // comment
221+
\Foo\Bar
214222
{
215223
}
216224

217-
class C7 extends \Foo\Bar implements \Baz\Bar // comment
225+
class C7 extends \Foo\Bar implements // comment
226+
\Baz\Bar
218227
{
219228
}

src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,16 @@ public function getErrorList()
5151
131 => 1,
5252
158 => 1,
5353
168 => 1,
54-
173 => 1,
5554
178 => 1,
5655
179 => 1,
5756
184 => 1,
5857
189 => 1,
5958
194 => 1,
60-
199 => 1,
6159
204 => 1,
6260
205 => 1,
6361
210 => 1,
6462
215 => 2,
6563
216 => 1,
66-
221 => 1,
67-
226 => 1,
6864
231 => 2,
6965
];
7066

0 commit comments

Comments
 (0)