Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule for trailing command in function call. #398

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ on:

jobs:
testsuite:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3']
php-version: ['8.1', '8.2', '8.3', '8.4']
dependencies: ['highest']
include:
- php-version: '8.1'
Expand All @@ -40,10 +40,10 @@ jobs:

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
8 changes: 4 additions & 4 deletions CakePHP/Sniffs/Classes/ReturnTypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addError(
'Chaining methods (@return $this) should not have any return-type-hint.',
$startIndex,
'InvalidSelf'
'InvalidSelf',
);

return;
Expand All @@ -76,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr)
$fix = $phpcsFile->addFixableError(
'Chaining methods (@return $this) should not have any return-type-hint (Remove "self").',
$startIndex,
'InvalidSelf'
'InvalidSelf',
);
if (!$fix) {
return;
Expand Down Expand Up @@ -175,7 +175,7 @@ protected function assertNotThisOrStatic(File $phpCsFile, int $stackPointer): vo
$phpCsFile->addError(
'Class name repeated, expected `self` or `$this`.',
$classNameIndex,
'InvalidClass'
'InvalidClass',
);
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ protected function getClassNameWithNamespace(File $phpCsFile): ?string

return ClassHelper::getFullyQualifiedName(
$phpCsFile,
$phpCsFile->findPrevious(TokenHelper::$typeKeywordTokenCodes, $lastToken)
$phpCsFile->findPrevious(TokenHelper::$typeKeywordTokenCodes, $lastToken),
);
}
}
2 changes: 1 addition & 1 deletion CakePHP/Sniffs/Commenting/DocBlockAlignmentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function process(File $phpcsFile, $stackPtr)
$commentBorder = $phpcsFile->findNext(
[T_DOC_COMMENT_STAR, T_DOC_COMMENT_CLOSE_TAG],
$searchToken,
$commentClose + 1
$commentClose + 1,
);
if ($commentBorder !== false) {
$tokensToIndent[$commentBorder] = $codeIndentation + 1;
Expand Down
10 changes: 5 additions & 5 deletions CakePHP/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public function process(File $phpcsFile, $stackPtr)
$docCommentEnd = $phpcsFile->findPrevious(
[T_DOC_COMMENT_CLOSE_TAG, T_SEMICOLON, T_CLOSE_CURLY_BRACKET, T_OPEN_CURLY_BRACKET],
$stackPtr - 1,
null
null,
);
if ($docCommentEnd === false || $tokens[$docCommentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) {
$phpcsFile->addError(
'Missing doc comment for function %s()',
$stackPtr,
'Missing',
[$phpcsFile->getDeclarationName($stackPtr)]
[$phpcsFile->getDeclarationName($stackPtr)],
);

return;
Expand All @@ -77,14 +77,14 @@ public function process(File $phpcsFile, $stackPtr)
$attribute = $phpcsFile->findNext(
[T_ATTRIBUTE],
$lastEndToken + 1,
$stackPtr
$stackPtr,
);
if ($attribute !== false) {
if ($tokens[$lastEndToken]['line'] !== $tokens[$attribute]['line'] - 1) {
$phpcsFile->addError(
'There must be no blank lines after the function comment or attribute',
$lastEndToken,
'SpacingAfter'
'SpacingAfter',
);

return;
Expand All @@ -98,7 +98,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addError(
'There must be no blank lines after the function comment or attribute',
$lastEndToken,
'SpacingAfter'
'SpacingAfter',
);
}

Expand Down
10 changes: 5 additions & 5 deletions CakePHP/Sniffs/Commenting/TypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function process(File $phpcsFile, $stackPtr)
'%s type hint is not formatted properly, expected "%s"',
$tag,
'IncorrectFormat',
[$tokens[$tag]['content'], $sortedTypeHint]
[$tokens[$tag]['content'], $sortedTypeHint],
);
if (!$fix) {
continue;
Expand All @@ -135,7 +135,7 @@ public function process(File $phpcsFile, $stackPtr)
'%s %s %s',
$sortedTypeHint,
$valueNode->variableName,
$valueNode->description
$valueNode->description,
));
if ($tagComment[-1] === ' ') {
// tags above variables in code have a trailing space
Expand All @@ -147,13 +147,13 @@ public function process(File $phpcsFile, $stackPtr)
$sortedTypeHint,
$valueNode->isVariadic ? '...' : '',
$valueNode->parameterName,
$valueNode->description
$valueNode->description,
));
} elseif ($valueNode instanceof ReturnTagValueNode) {
$newComment = trim(sprintf(
'%s %s',
$sortedTypeHint,
$valueNode->description
$valueNode->description,
));
}

Expand Down Expand Up @@ -276,7 +276,7 @@ protected function renderUnionTypes(array $typeNodes): string
return preg_replace(
['/ ([\|&]) /', '/<\(/', '/\)>/', '/\), /', '/, \(/'],
['${1}', '<', '>', ', ', ', '],
implode('|', $typeNodes)
implode('|', $typeNodes),
);
}

Expand Down
2 changes: 1 addition & 1 deletion CakePHP/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function process(File $phpcsFile, $stackPtr)
$fix = $phpcsFile->addFixableError(
'Missing blank line before return statement',
$stackPtr,
'BlankLineBeforeReturn'
'BlankLineBeforeReturn',
);
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
Expand Down
2 changes: 1 addition & 1 deletion CakePHP/Sniffs/PHP/SingleQuoteSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
$fix = $phpcsFile->addFixableError(
'Use single instead of double quotes for simple strings.',
$stackPtr,
'UseSingleQuote'
'UseSingleQuote',
);
if ($fix) {
$content = substr($content, 1, -1);
Expand Down
6 changes: 3 additions & 3 deletions CakePHP/Sniffs/WhiteSpace/FunctionSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function process(File $phpCsFile, $stackPointer)
$fix = $phpCsFile->addFixableError(
'Every function/method needs a newline afterwards',
$closingParenthesisIndex,
'Abstract'
'Abstract',
);
if ($fix) {
$phpCsFile->fixer->addNewline($semicolonIndex);
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function assertNewLineAtTheEnd(File $phpCsFile, int $closingBraceIndex
$fix = $phpCsFile->addFixableError(
'Every function/method needs a newline afterwards',
$closingBraceIndex,
'Concrete'
'Concrete',
);
if ($fix) {
$phpCsFile->fixer->addNewline($closingBraceIndex);
Expand Down Expand Up @@ -160,7 +160,7 @@ protected function assertNewLineAtTheBeginning(File $phpCsFile, int $stackPointe
$fix = $phpCsFile->addFixableError(
'Every function/method needs a newline before',
$firstTokenInLineIndex,
'Concrete'
'Concrete',
);
if ($fix) {
$phpCsFile->fixer->addNewline($prevContentIndex);
Expand Down
1 change: 1 addition & 0 deletions CakePHP/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration" />
<rule ref="SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing"/>
<rule ref="SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>

<!-- phpcs Zend sniffs -->
<rule ref="Zend.NamingConventions.ValidVariableName">
Expand Down
7 changes: 5 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CakePHP ruleset

The CakePHP standard contains 144 sniffs
The CakePHP standard contains 147 sniffs

CakePHP (20 sniffs)
-------------------
Expand Down Expand Up @@ -95,9 +95,11 @@ PSR12 (17 sniffs)
- PSR12.Properties.ConstantVisibility
- PSR12.Traits.UseDeclaration

SlevomatCodingStandard (40 sniffs)
SlevomatCodingStandard (43 sniffs)
----------------------------------
- SlevomatCodingStandard.Arrays.TrailingArrayComma
- SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing
- SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment
- SlevomatCodingStandard.Classes.ClassConstantVisibility
- SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces
- SlevomatCodingStandard.Classes.ModernClassNameReference
Expand All @@ -114,6 +116,7 @@ SlevomatCodingStandard (40 sniffs)
- SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator
- SlevomatCodingStandard.Exceptions.DeadCatch
- SlevomatCodingStandard.Functions.ArrowFunctionDeclaration
- SlevomatCodingStandard.Functions.RequireTrailingCommaInCall
- SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
- SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation
- SlevomatCodingStandard.Namespaces.NamespaceDeclaration
Expand Down