Skip to content

Commit

Permalink
Merge pull request #484 from wimg/feature/remove-php52-work-arounds
Browse files Browse the repository at this point in the history
Remove php 5.2 work arounds
  • Loading branch information
wimg committed Jul 30, 2017
2 parents a358989 + 10dde1f commit f5149a8
Show file tree
Hide file tree
Showing 32 changed files with 136 additions and 558 deletions.
8 changes: 4 additions & 4 deletions PHPCompatibility/Sniffs/PHP/ForbiddenNamesAsDeclaredSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$tokenCode = $tokens[$stackPtr]['code'];
$tokenContentLc = strtolower($tokens[$stackPtr]['content']);

// For string tokens we only care about 'trait' and 'namespace' as those are
// the only ones which may not be correctly recognized as it's own token.
// For string tokens we only care about 'trait' as that is the only one
// which may not be correctly recognized as it's own token.
// This only happens in older versions of PHP where the token doesn't exist yet as a keyword.
if ($tokenCode === T_STRING && ($tokenContentLc !== 'trait' && $tokenContentLc !== 'namespace')) {
if ($tokenCode === T_STRING && $tokenContentLc !== 'trait') {
return;
}

Expand Down Expand Up @@ -169,7 +169,7 @@ public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}
} elseif ($tokenCode === T_STRING) {
// Traits and namespaces which are not yet tokenized as T_TRAIT/T_NAMESPACE.
// Traits which are not yet tokenized as T_TRAIT.
$nextNonEmpty = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if ($nextNonEmpty === false) {
return;
Expand Down
4 changes: 1 addition & 3 deletions PHPCompatibility/Sniffs/PHP/ForbiddenNamesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ public function processString(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $toke
* - namespace keyword in PHP < 5.3
* - trait keyword in PHP < 5.4
*/
if ((version_compare(phpversion(), '5.3', '<') && $tokenContentLc === 'namespace')
|| (version_compare(phpversion(), '5.4', '<') && $tokenContentLc === 'trait')
) {
if (version_compare(PHP_VERSION_ID, '50400', '<') && $tokenContentLc === 'trait') {
$this->processNonString($phpcsFile, $stackPtr, $tokens);
return;
}
Expand Down
35 changes: 35 additions & 0 deletions PHPCompatibility/Sniffs/PHP/NewKeywordsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ class NewKeywordsSniff extends AbstractNewFeatureSniff
'5.3' => true,
'description' => '"use" keyword (for traits/namespaces/anonymous functions)',
),
'T_START_NOWDOC' => array(
'5.2' => false,
'5.3' => true,
'description' => 'nowdoc functionality',
),
'T_END_NOWDOC' => array(
'5.2' => false,
'5.3' => true,
'description' => 'nowdoc functionality',
),
'T_START_HEREDOC' => array(
'5.2' => false,
'5.3' => true,
'description' => '(Double) quoted Heredoc identifier',
'condition' => 'isNotQuoted', // Heredoc is only new with quoted identifier.
),
'T_TRAIT' => array(
'5.3' => false,
'5.4' => true,
Expand Down Expand Up @@ -323,4 +339,23 @@ protected function filterErrorData(array $data, array $itemInfo, array $errorInf
}


/**
* Callback for the quoted heredoc identifier condition.
*
* A double quoted identifier will have the opening quote on position 3
* in the string: `<<<"ID"`.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return bool
*/
public function isNotQuoted(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
return ($tokens[$stackPtr]['content'][3] !== '"');
}


}//end class
191 changes: 0 additions & 191 deletions PHPCompatibility/Sniffs/PHP/NewNowdocQuotedHeredocSniff.php

This file was deleted.

4 changes: 1 addition & 3 deletions PHPCompatibility/Sniffs/PHP/NewNullableTypesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ protected function processReturnType(\PHP_CodeSniffer_File $phpcsFile, $stackPtr
$error = true;
}
// Deal with namespaced class names.
elseif ($tokens[($stackPtr - 1)]['code'] === T_NS_SEPARATOR
|| (version_compare(PHP_VERSION, '5.3.0', '<') && $tokens[($stackPtr - 1)]['code'] === T_STRING)
) {
elseif ($tokens[($stackPtr - 1)]['code'] === T_NS_SEPARATOR) {
$validTokens = array(
T_STRING,
T_NS_SEPARATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RemovedAlternativePHPTagsSniff extends Sniff
*/
public function register()
{
if (version_compare(phpversion(), '7.0', '<') === true) {
if (version_compare(PHP_VERSION_ID, '70000', '<') === true) {
$this->aspTags = (boolean) ini_get('asp_tags');
}

Expand Down Expand Up @@ -105,12 +105,7 @@ public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
&& preg_match('`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match) === 1
) {
$found = $match[1];
if (version_compare(phpversion(), '5.3', '<')) {
// Add the missing '<s' at the start of the match for PHP 5.2.
$found = '<s' . $match[1];
}

$data = array(
$data = array(
'Script',
$found,
);
Expand Down
2 changes: 1 addition & 1 deletion PHPCompatibility/Sniffs/PHP/ValidIntegersSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ValidIntegersSniff extends Sniff
*/
public function register()
{
$this->isLowPHPVersion = version_compare(phpversion(), '5.4', '<');
$this->isLowPHPVersion = version_compare(PHP_VERSION_ID, '50400', '<');

return array(
T_LNUMBER, // Binary, octal integers.
Expand Down
2 changes: 1 addition & 1 deletion PHPCompatibility/Tests/BaseClass/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
*/
public static function setUpBeforeClass()
{
require_once dirname(__FILE__) . '/TestHelperPHPCompatibility.php';
require_once __DIR__ . '/TestHelperPHPCompatibility.php';
parent::setUpBeforeClass();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class GetFQClassNameFromDoubleColonTokenTest extends MethodTestFrame
/**
* testGetFQClassNameFromDoubleColonToken
*
* @requires PHP 5.3
*
* @dataProvider dataGetFQClassNameFromDoubleColonToken
*
* @covers \PHPCompatibility\Sniff::getFQClassNameFromDoubleColonToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class GetFQClassNameFromNewTokenTest extends MethodTestFrame
/**
* testGetFQClassNameFromNewToken
*
* @requires PHP 5.3
*
* @dataProvider dataGetFQClassNameFromNewToken
*
* @covers \PHPCompatibility\Sniff::getFQClassNameFromNewToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class GetFQExtendedClassNameTest extends MethodTestFrame
/**
* testGetFQExtendedClassName
*
* @requires PHP 5.3
*
* @dataProvider dataGetFQExtendedClassName
*
* @covers \PHPCompatibility\Sniff::getFQExtendedClassName
Expand Down
2 changes: 1 addition & 1 deletion PHPCompatibility/Tests/BaseClass/IsClassPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class IsClassPropertyTest extends MethodTestFrame
public static function setUpBeforeClass()
{
// When using PHPCS 2.3.4 or lower combined with PHP 5.3 or lower, traits are not recognized.
if (version_compare(PHPCSHelper::getVersion(), '2.4.0', '<') && version_compare(phpversion(), '5.4', '<')) {
if (version_compare(PHPCSHelper::getVersion(), '2.4.0', '<') && version_compare(PHP_VERSION_ID, '50400', '<')) {
self::$recognizesTraits = false;
}

Expand Down
2 changes: 1 addition & 1 deletion PHPCompatibility/Tests/BaseClass/MethodTestFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class MethodTestFrame extends \PHPUnit_Framework_TestCase
*/
public static function setUpBeforeClass()
{
require_once dirname(__FILE__) . '/TestHelperPHPCompatibility.php';
require_once __DIR__ . '/TestHelperPHPCompatibility.php';
parent::setUpBeforeClass();
}

Expand Down
4 changes: 2 additions & 2 deletions PHPCompatibility/Tests/BaseSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function setUp()
self::$phpcs->initStandard(self::STANDARD_NAME, array($this->getSniffCode()));
} else {
// PHPCS 1.x.
self::$phpcs->process(array(), dirname(dirname(__FILE__)) . '/', array($this->getSniffCode()));
self::$phpcs->process(array(), dirname(__DIR__) . '/', array($this->getSniffCode()));
}

self::$phpcs->setIgnorePatterns(array());
Expand Down Expand Up @@ -137,7 +137,7 @@ public function sniffFile($filename, $targetPhpVersion = 'none')
PHPCSHelper::setConfigData('testVersion', $targetPhpVersion, true);
}

$pathToFile = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $filename;
$pathToFile = realpath(__DIR__) . DIRECTORY_SEPARATOR . $filename;
try {
if (class_exists('\PHP_CodeSniffer\Files\LocalFile')) {
// PHPCS 3.x.
Expand Down

0 comments on commit f5149a8

Please sign in to comment.