Skip to content

Commit

Permalink
Merge pull request #259 from jrfnl/feature/fix-php-7.4-compat-3.x
Browse files Browse the repository at this point in the history
Fix compatibility with PHP 7.4 (3.x)
  • Loading branch information
Michael Babker authored Jan 21, 2020
2 parents fc041ba + 9c1768e commit 57a1433
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Joomla/Sniffs/Commenting/FileCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ protected function processPackage(File $phpcsFile, array $tags)
{
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}) . substr($firstBit, 1) . '_';
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';

foreach ($nameBits as $bit)
{
if ($bit !== '')
{
$newName .= strtoupper($bit{0}) . substr($bit, 1) . '_';
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}
}

Expand Down
24 changes: 12 additions & 12 deletions Joomla/Sniffs/Commenting/SingleCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr)
$comment = trim($tokens[$stackPtr]['content']);

// Hash comments are not allowed.
if ($tokens[$stackPtr]['content']{0} === '#')
if ($tokens[$stackPtr]['content'][0] === '#')
{
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '# ...');

Expand All @@ -57,21 +57,21 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->replaceToken($stackPtr, $newComment);
}
}
elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '/')
elseif ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '/')
{
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '// ...');
$singleLine = true;
}
elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '*')
elseif ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '*')
{
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '/* ... */');
}

// Always have a space between // and the start of the comment text.
// The exception to this is if the preceding line consists of a single open bracket.
if ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '/' && isset($tokens[$stackPtr]['content']{2})
&& $tokens[$stackPtr]['content']{2} !== ' ' && isset($tokens[($stackPtr - 1)]['content']{0})
&& $tokens[($stackPtr - 1)]['content']{0} !== '}'
if ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '/' && isset($tokens[$stackPtr]['content'][2])
&& $tokens[$stackPtr]['content'][2] !== ' ' && isset($tokens[($stackPtr - 1)]['content'][0])
&& $tokens[($stackPtr - 1)]['content'][0] !== '}'
)
{
$error = 'Missing space between the // and the start of the comment text.';
Expand All @@ -91,23 +91,23 @@ public function process(File $phpcsFile, $stackPtr)
* the line is a continuation of a complete sentence,
* the term is code and is case sensitive.(@todo)
*/
if (($singleLine === true && isset($tokens[$stackPtr]['content']{3}) && $tokens[$stackPtr]['content']{2} === ' '
&& $tokens[$stackPtr]['content']{3} !== strtoupper($tokens[$stackPtr]['content']{3})) || (isset($comment{2}) && $comment{0} === '*'
&& $comment{1} === ' ' && $comment{2} !== strtoupper($comment{2}))
if (($singleLine === true && isset($tokens[$stackPtr]['content'][3]) && $tokens[$stackPtr]['content'][2] === ' '
&& $tokens[$stackPtr]['content'][3] !== strtoupper($tokens[$stackPtr]['content'][3])) || (isset($comment[2]) && $comment[0] === '*'
&& $comment[1] === ' ' && $comment[2] !== strtoupper($comment[2]))
)
{
$error = 'Comment must start with a capital letter; found "%s"';
$previous = $phpcsFile->findPrevious(T_COMMENT, $stackPtr - 1);

if ($singleLine === true)
{
$data = array($comment{3});
$data = array($comment[3]);
$newComment = ltrim($tokens[$stackPtr]['content'], '\// ');
$newComment = '// ' . ucfirst($newComment);
}
else
{
$data = array($comment{2});
$data = array($comment[2]);
$padding = (strlen($tokens[$stackPtr]['content']) - strlen($comment));
$padding = str_repeat("\t", $padding - 2);
$newComment = ltrim($comment, '* ');
Expand All @@ -119,7 +119,7 @@ public function process(File $phpcsFile, $stackPtr)
{
$test = trim($tokens[$previous]['content']);

if ('.' === $test{(strlen($test) - 1)})
if ('.' === $test[(strlen($test) - 1)])
{
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'LowerCaseAfterSentenceEnd', $data);

Expand Down
4 changes: 2 additions & 2 deletions Joomla/Sniffs/NamingConventions/ValidFunctionNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
}

// Joomla change: Methods must not have an underscore on the front.
if ($scopeSpecified === true && $methodName{0} === '_')
if ($scopeSpecified === true && $methodName[0] === '_')
{
$error = '%s method name "%s" must not be prefixed with an underscore';
$data = array(
Expand All @@ -105,7 +105,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
*/
$testMethodName = $methodName;

if ($scopeSpecified === false && $methodName{0} === '_')
if ($scopeSpecified === false && $methodName[0] === '_')
{
$testMethodName = substr($methodName, 1);
}
Expand Down

0 comments on commit 57a1433

Please sign in to comment.