-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature completeness
NewScalarTypeDeclarations
sniff (code review).
This adds a number of additional checks to the `NewScalarTypeDeclarations` sniff. * Check that type hints are not being used in pre-PHP 5.0 code. * Check for valid usage of the `array` and `callable` type hints. * Check for invalid type hints which are typical mistakes. * Check that the `self` type hint is only used within the class scope. Also: * The `description` key in the `$newTypes` array did not actually add any value, so I've removed it. * Minor tweaks to the original error message text. Was along the lines of: _"int type is not present in PHP version 5.6 or earlier"_. Now: _"'int' type declaration is not present in PHP version 5.6 or earlier"_. Includes unit tests covering all changes. This PR also adds two new utility methods to the abstract `PHPCompatibility_Sniff` class. One is a copy of an existing method from PHPCS with some minor tweaks which have been send in as a PR to PHPCS. That PR is expected to be merged for the 2.7.0 release. Unit tests for this method are available within the PHPCS test suite. The other is a new PHPCompatibility native method `inClassScope` and is accompanied by unit tests for the method. Similarly to an earlier PR, the file/sniff name does now no longer cover what the sniff actually does. File and sniff renaming advised.
- Loading branch information
Showing
6 changed files
with
530 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* In class scope test file | ||
* | ||
* @package PHPCompatibility | ||
*/ | ||
|
||
|
||
/** | ||
* In class scope function tests | ||
* | ||
* @uses BaseSniffTest | ||
* @package PHPCompatibility | ||
*/ | ||
class InClassScopeTest extends BaseAbstractClassMethodTest | ||
{ | ||
|
||
public $filename = 'sniff-examples/utility-functions/in_class_scope.php'; | ||
|
||
/** | ||
* testInClassScope | ||
* | ||
* @group utilityFunctions | ||
* | ||
* @dataProvider dataInClassScope | ||
* | ||
* @param int $stackPtr Stack pointer for an arbitrary token in the test file. | ||
* @param string $expected The expected boolean return value. | ||
*/ | ||
public function testInClassScope($stackPtr, $expected) | ||
{ | ||
$result = $this->helperClass->inClassScope($this->_phpcsFile, $stackPtr); | ||
$this->assertSame($expected, $result); | ||
} | ||
|
||
/** | ||
* dataInClassScope | ||
* | ||
* @see testInClassScope() | ||
* | ||
* @return array | ||
*/ | ||
public function dataInClassScope() | ||
{ | ||
return array( | ||
array(2, false), // $var | ||
array(9, false), // function | ||
array(28, true), // $property | ||
array(32, true), // function | ||
array(49, false), // function | ||
array(67, true), // function | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.