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

added sniffs for php 8 #8

Merged
merged 2 commits into from May 20, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -10,12 +10,8 @@ class MemberVarSpacingSniff extends \PHP_CodeSniffer\Sniffs\AbstractVariableSnif
public int $spacingBeforeFirst = 1;
public bool $ignoreFirstMemberVar = false;

/**
* @return int|void
*/
//@phpcs:ignore Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
//@phpcs:ignore SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $stackPtr)
protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $stackPtr) : ?int
{
$tokens = $phpcsFile->getTokens();

Expand All @@ -25,7 +21,7 @@ protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $sta
$startOfStatement = $phpcsFile->findPrevious($validPrefixes, $stackPtr - 1, null, false, null, true);

if ($startOfStatement === false) {
return;
return null;
}

$endOfStatement = $phpcsFile->findNext(\T_SEMICOLON, $stackPtr + 1, null, false, null, true);
Expand Down Expand Up @@ -97,13 +93,13 @@ protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $sta
&& isset($tokens[$prev]['scope_condition']) === true
&& $tokens[$tokens[$prev]['scope_condition']]['code'] === \T_FUNCTION
) {
return;
return null;
}

$prevVar = $phpcsFile->findPrevious(\T_VARIABLE, $first - 1);

if ($this->ignoreFirstMemberVar && $tokens[$prevVar]['code'] !== \T_VARIABLE) {
return;
return null;
}

if ($tokens[$prev]['code'] === \T_OPEN_CURLY_BRACKET
Expand Down Expand Up @@ -131,7 +127,7 @@ protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $sta
return $endOfStatement;
}

return;
return null;
}

$data = [
Expand Down
11 changes: 11 additions & 0 deletions InfinityloopCodingStandard/ruleset.xml
Expand Up @@ -308,6 +308,7 @@
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>
Expand Down Expand Up @@ -389,8 +390,10 @@
</properties>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch"/>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="psr12Compatible" value="true"/>
Expand Down Expand Up @@ -455,6 +458,13 @@
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
<rule ref="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
<properties>
<property name="withSpaces" value="no"/>
<property name="shortNullable" value="yes"/>
<property name="nullPosition" value="last"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma">
<properties>
Expand All @@ -469,6 +479,7 @@
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<rule ref="SlevomatCodingStandard.Numbers.DisallowNumericLiteralSeparator"/>
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
Expand Down