Skip to content

Commit

Permalink
Merge pull request #8 from vossik/update
Browse files Browse the repository at this point in the history
added sniffs for php 8
  • Loading branch information
peldax committed May 20, 2021
2 parents 1fbe30c + 43c2a37 commit 32ccf27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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

0 comments on commit 32ccf27

Please sign in to comment.