Skip to content

Commit

Permalink
Merge pull request #505 from wimg/feature/add-missing-valid-return-types
Browse files Browse the repository at this point in the history
NewReturnTypeDeclarations: add two missing valid types
  • Loading branch information
wimg committed Aug 6, 2017
2 parents 3d6de9a + 0c4ddcd commit 952ced8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion PHPCompatibility/Sniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,11 @@ public function getReturnTypeHintToken(\PHP_CodeSniffer_File $phpcsFile, $stackP
return false;
}

// `self` and `callable` are not being recognized as return types in PHPCS < 2.6.0.
// `self`, `parent` and `callable` are not being recognized as return types in PHPCS < 2.6.0.
$unrecognizedTypes = array(
T_CALLABLE,
T_SELF,
T_PARENT,
);

// Return types are not recognized at all in PHPCS < 2.4.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff
'5.6' => false,
'7.0' => true,
),
'parent' => array(
'5.6' => false,
'7.0' => true,
),
'self' => array(
'5.6' => false,
'7.0' => true,
Expand All @@ -67,6 +71,10 @@ class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff
'7.0' => true,
),

'iterable' => array(
'7.0' => false,
'7.1' => true,
),
'void' => array(
'7.0' => false,
'7.1' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ public function dataReturnType()
array('array', '5.6', 8, '7.0'),
array('callable', '5.6', 9, '7.0'),
array('self', '5.6', 10, '7.0'),
array('Class name', '5.6', 11, '7.0'),
array('parent', '5.6', 11, '7.0'),
array('Class name', '5.6', 12, '7.0'),
array('Class name', '5.6', 13, '7.0'),
array('Class name', '5.6', 14, '7.0'),
array('Class name', '5.6', 15, '7.0'),

array('void', '7.0', 17, '7.1'),
array('iterable', '7.0', 18, '7.1'),
array('void', '7.0', 19, '7.1'),

array('callable', '5.6', 20, '7.0'),
array('callable', '5.6', 22, '7.0'),

array('object', '7.1', 27, '7.2'),
array('object', '7.1', 29, '7.2'),
);
}

Expand Down Expand Up @@ -102,8 +104,8 @@ public function testNoFalsePositives($line)
public function dataNoFalsePositives()
{
return array(
array(23),
array(24),
array(25),
array(26),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ function foo($a): string {}
function foo($a): array {}
function foo($a): callable {}
function foo($a): self {}
function foo($a): parent {}
function foo($a): Baz {}
function foo($a): \Baz {}
function foo($a): myNamespace\Baz {}
function foo($a): \myNamespace\Baz {}

// PHP 7.1+
function foo($a): iterable {}
function foo($a): void {}

// Anonymous function.
Expand Down

0 comments on commit 952ced8

Please sign in to comment.