Skip to content

Commit fcb3ecd

Browse files
committed
Merge branch 'master' into 4.x
2 parents 4220d69 + 8fab89f commit fcb3ecd

16 files changed

+204
-13
lines changed

src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function process(File $phpcsFile, $stackPtr)
6666
return;
6767
}
6868

69-
// If this is a function/class/interface doc block comment, skip it.
69+
// If this is a function/class/interface/enum/property/const doc block comment, skip it.
7070
// We are only interested in inline doc block comments.
7171
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
7272
$nextToken = $stackPtr;
@@ -80,16 +80,14 @@ public function process(File $phpcsFile, $stackPtr)
8080
break;
8181
} while (true);
8282

83-
$ignore = [
83+
$ignore = Tokens::SCOPE_MODIFIERS;
84+
$ignore += [
8485
T_CLASS => true,
8586
T_INTERFACE => true,
8687
T_TRAIT => true,
8788
T_ENUM => true,
8889
T_FUNCTION => true,
89-
T_PUBLIC => true,
90-
T_PRIVATE => true,
9190
T_FINAL => true,
92-
T_PROTECTED => true,
9391
T_STATIC => true,
9492
T_ABSTRACT => true,
9593
T_CONST => true,

src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ public function process(File $phpcsFile, $stackPtr)
4242
{
4343
$tokens = $phpcsFile->getTokens();
4444

45-
// We are only interested in function/class/interface doc block comments.
45+
// We are only interested in function/class/interface/enum/property/const doc block comments.
4646
$nextToken = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, ($stackPtr + 1), null, true);
47-
$ignore = [
47+
48+
$ignore = Tokens::SCOPE_MODIFIERS;
49+
$ignore += [
4850
T_CLASS => true,
4951
T_INTERFACE => true,
5052
T_ENUM => true,
5153
T_ENUM_CASE => true,
5254
T_FUNCTION => true,
53-
T_PUBLIC => true,
54-
T_PRIVATE => true,
55-
T_PROTECTED => true,
5655
T_STATIC => true,
5756
T_ABSTRACT => true,
5857
T_FINAL => true,

src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,40 @@ public function processBracket($phpcsFile, $openBracket)
334334
}//end if
335335
}//end if
336336

337+
if (isset($param['set_visibility_token']) === true && $param['set_visibility_token'] !== false) {
338+
$visibilityToken = $param['set_visibility_token'];
339+
$afterVisibilityToken = $phpcsFile->findNext(T_WHITESPACE, ($visibilityToken + 1), $param['token'], true);
340+
341+
$spacesAfter = 0;
342+
if ($afterVisibilityToken !== false
343+
&& $tokens[$visibilityToken]['line'] !== $tokens[$afterVisibilityToken]['line']
344+
) {
345+
$spacesAfter = 'newline';
346+
} else if ($tokens[($visibilityToken + 1)]['code'] === T_WHITESPACE) {
347+
$spacesAfter = $tokens[($visibilityToken + 1)]['length'];
348+
}
349+
350+
if ($spacesAfter !== 1) {
351+
$error = 'Expected 1 space after set-visibility modifier "%s"; %s found';
352+
$data = [
353+
$tokens[$visibilityToken]['content'],
354+
$spacesAfter,
355+
];
356+
357+
$fix = $phpcsFile->addFixableError($error, $visibilityToken, 'SpacingAfterSetVisbility', $data);
358+
if ($fix === true) {
359+
$phpcsFile->fixer->beginChangeset();
360+
$phpcsFile->fixer->addContent($visibilityToken, ' ');
361+
362+
for ($i = ($visibilityToken + 1); $tokens[$i]['code'] === T_WHITESPACE; $i++) {
363+
$phpcsFile->fixer->replaceToken($i, '');
364+
}
365+
366+
$phpcsFile->fixer->endChangeset();
367+
}
368+
}//end if
369+
}//end if
370+
337371
if (isset($param['readonly_token']) === true) {
338372
$readonlyToken = $param['readonly_token'];
339373
$afterReadonlyToken = $phpcsFile->findNext(T_WHITESPACE, ($readonlyToken + 1), $param['token'], true);

src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
5151
}
5252

5353
$tokens = $phpcsFile->getTokens();
54-
$error = 'Scope modifier not specified for member variable "%s"';
55-
$data = [$tokens[$stackPtr]['content']];
56-
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
54+
if ($properties['set_scope'] === false) {
55+
$error = 'Scope modifier not specified for member variable "%s"';
56+
$data = [$tokens[$stackPtr]['content']];
57+
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
58+
} else {
59+
$error = 'Read scope modifier not specified for member variable "%s"';
60+
$data = [$tokens[$stackPtr]['content']];
61+
$phpcsFile->addError($error, $stackPtr, 'AsymReadMissing', $data);
62+
}
5763

5864
}//end processMemberVar()
5965

src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,20 @@ class FinalProperties {
314314
*/
315315
final int $prop = 1;
316316
}
317+
318+
class AsymVisibility {
319+
/**
320+
* Comment should be ignored.
321+
*/
322+
public(set) int $prop = 1;
323+
324+
/**
325+
* Comment should be ignored.
326+
*/
327+
protected(set) int $prop = 1;
328+
329+
/**
330+
* Comment should be ignored.
331+
*/
332+
private(set) int $prop = 1;
333+
}

src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc.fixed

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,20 @@ class FinalProperties {
316316
*/
317317
final int $prop = 1;
318318
}
319+
320+
class AsymVisibility {
321+
/**
322+
* Comment should be ignored.
323+
*/
324+
public(set) int $prop = 1;
325+
326+
/**
327+
* Comment should be ignored.
328+
*/
329+
protected(set) int $prop = 1;
330+
331+
/**
332+
* Comment should be ignored.
333+
*/
334+
private(set) int $prop = 1;
335+
}

src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,20 @@ final class FinalClassWithFinalProp
114114
*/
115115
final $property = 10;
116116
}
117+
118+
class AsymVisibility {
119+
/**
120+
* Stars should be aligned.
121+
*/
122+
public(set) int $prop = 1;
123+
124+
/**
125+
* Stars should be aligned.
126+
*/
127+
protected(set) int $prop = 1;
128+
129+
/**
130+
* Stars should be aligned.
131+
*/
132+
private(set) int $prop = 1;
133+
}

src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc.fixed

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,20 @@ final class FinalClassWithFinalProp
114114
*/
115115
final $property = 10;
116116
}
117+
118+
class AsymVisibility {
119+
/**
120+
* Stars should be aligned.
121+
*/
122+
public(set) int $prop = 1;
123+
124+
/**
125+
* Stars should be aligned.
126+
*/
127+
protected(set) int $prop = 1;
128+
129+
/**
130+
* Stars should be aligned.
131+
*/
132+
private(set) int $prop = 1;
133+
}

src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function getErrorList()
5757
112 => 1,
5858
113 => 1,
5959
114 => 1,
60+
120 => 1,
61+
121 => 1,
62+
125 => 1,
63+
126 => 1,
6064
];
6165

6266
}//end getErrorList()

src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,20 @@ class StandaloneFQNNullTrueFalseTypes
517517
*/
518518
private \FALSE $variableName = false;
519519
}
520+
521+
class AsymVisibility {
522+
/**
523+
* @var integer
524+
*/
525+
public(set) int $hasDocblockA;
526+
527+
/**
528+
* @var integer
529+
*/
530+
public protected(set) int $hasDocblockB;
531+
532+
/**
533+
* @var integer
534+
*/
535+
private(set) protected int $hasDocblockC;
536+
}

0 commit comments

Comments
 (0)