Skip to content

Commit

Permalink
5.x: Enable missing native type hint sniffs
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Dec 15, 2021
1 parent b2b9589 commit bd20ff2
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 47 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ on:
push:
branches:
- master
- '5.0'
- '5.x'
pull_request:
branches:
- '*'

jobs:
testsuite:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
php-version: ['7.2', '7.4', '8.0']
php-version: ['7.4', '8.0']
prefer-lowest: ['']
include:
- php-version: '7.2'
- php-version: '7.4'
prefer-lowest: 'prefer-lowest'

steps:
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: '7.4'
extensions: mbstring, intl
tools: cs2pr
coverage: none
Expand Down
11 changes: 4 additions & 7 deletions CakePHP/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,15 @@ class FunctionCommentSniff implements Sniff
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
*/
public function register()
{
return [T_FUNCTION];
}

/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @return void
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
Expand Down Expand Up @@ -115,7 +112,7 @@ public function process(File $phpcsFile, $stackPtr)
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @return void
*/
protected function processTagSpacing(File $phpcsFile, int $stackPtr, int $commentStart)
protected function processTagSpacing(File $phpcsFile, int $stackPtr, int $commentStart): void
{
$tokens = $phpcsFile->getTokens();
$tags = $tokens[$commentStart]['comment_tags'];
Expand All @@ -142,7 +139,7 @@ protected function processTagSpacing(File $phpcsFile, int $stackPtr, int $commen
* @param int $commentStart The position in the stack where the comment started.
* @return void
*/
protected function processThrows(File $phpcsFile, int $stackPtr, int $commentStart)
protected function processThrows(File $phpcsFile, int $stackPtr, int $commentStart): void
{
$tokens = $phpcsFile->getTokens();

Expand Down
15 changes: 6 additions & 9 deletions CakePHP/Sniffs/Commenting/TypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class TypeHintSniff implements Sniff
/**
* @var bool
*/
public $convertArraysToGenerics = true;
public bool $convertArraysToGenerics = true;

/**
* @var array<string>
*/
protected static $typeHintTags = [
protected static array $typeHintTags = [
'@var',
'@psalm-var',
'@phpstan-var',
Expand All @@ -62,18 +62,15 @@ class TypeHintSniff implements Sniff
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
*/
public function register()
{
return [T_DOC_COMMENT_OPEN_TAG];
}

/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @return void
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
Expand Down Expand Up @@ -233,7 +230,7 @@ protected function getSortedTypeHint(array $types): string
}

$sorted = [];
array_walk($sortable, function ($types) use (&$sorted) {
array_walk($sortable, function ($types) use (&$sorted): void {
$sorted = array_merge($sorted, $types);
});

Expand All @@ -258,7 +255,7 @@ protected function renderUnionTypes(array $typeNodes): string
* @param string $tagComment tag comment
* @return \PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode
*/
protected static function getValueNode(string $tagName, $tagComment): PhpDocTagValueNode
protected static function getValueNode(string $tagName, string $tagComment): PhpDocTagValueNode
{
static $phpDocParser;
if (!$phpDocParser) {
Expand Down
10 changes: 0 additions & 10 deletions CakePHP/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@
*/
class BlankLineBeforeReturnSniff implements Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = [
'PHP',
'JS',
];

/**
* @inheritDoc
*/
Expand Down
1 change: 1 addition & 0 deletions CakePHP/Sniffs/PHP/DisallowShortOpenTagSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DisallowShortOpenTagSniff implements Sniff
* So include T_INLINE_HTML which is what "<?" is detected as
*
* @return array
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
*/
public function register()
{
Expand Down
4 changes: 2 additions & 2 deletions CakePHP/Sniffs/WhiteSpace/FunctionSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function process(File $phpCsFile, $stackPointer)
* @param int|null $nextContentIndex Index
* @return void
*/
protected function assertNewLineAtTheEnd(File $phpCsFile, $closingBraceIndex, $nextContentIndex)
protected function assertNewLineAtTheEnd(File $phpCsFile, int $closingBraceIndex, ?int $nextContentIndex): void
{
$tokens = $phpCsFile->getTokens();

Expand All @@ -123,7 +123,7 @@ protected function assertNewLineAtTheEnd(File $phpCsFile, $closingBraceIndex, $n
* @param int $stackPointer Stack pointer
* @return void
*/
protected function assertNewLineAtTheBeginning(File $phpCsFile, $stackPointer)
protected function assertNewLineAtTheBeginning(File $phpCsFile, int $stackPointer): void
{
$tokens = $phpCsFile->getTokens();

Expand Down
11 changes: 0 additions & 11 deletions CakePHP/Sniffs/WhiteSpace/TabAndSpaceSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@

class TabAndSpaceSniff implements Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = [
'PHP',
'JS',
'CSS',
];

/**
* @inheritDoc
*/
Expand Down
3 changes: 0 additions & 3 deletions CakePHP/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
<property name="enableMixedTypeHint" type="boolean" value="true"/>
<property name="enableUnionTypeHint" type="boolean" value="true"/>
</properties>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation"/>
<exclude-pattern>*/tests/*</exclude-pattern>
Expand All @@ -189,7 +188,6 @@
<property name="enableStaticTypeHint" type="boolean" value="true"/>
<property name="enableUnionTypeHint" type="boolean" value="true"/>
</properties>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation"/>
<exclude-pattern>*/tests/*</exclude-pattern>
Expand All @@ -200,7 +198,6 @@
<property name="enableStaticTypeHint" type="boolean" value="true"/>
<property name="enableUnionTypeHint" type="boolean" value="true"/>
</properties>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation"/>
<exclude-pattern>*/tests/*</exclude-pattern>
Expand Down

0 comments on commit bd20ff2

Please sign in to comment.