Skip to content

Commit 1ceeaf4

Browse files
author
Michael Babker
authored
Merge pull request #258 from jrfnl/feature/fix-php-7.4-compat
Fix compatibility with PHP 7.4
2 parents c6970aa + 8bb22db commit 1ceeaf4

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Joomla/Sniffs/Commenting/FileCommentSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,13 @@ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags)
427427
{
428428
$nameBits = explode('_', $newContent);
429429
$firstBit = array_shift($nameBits);
430-
$newName = strtoupper($firstBit{0}) . substr($firstBit, 1) . '_';
430+
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
431431

432432
foreach ($nameBits as $bit)
433433
{
434434
if ($bit !== '')
435435
{
436-
$newName .= strtoupper($bit{0}) . substr($bit, 1) . '_';
436+
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
437437
}
438438
}
439439

Joomla/Sniffs/Commenting/SingleCommentSniff.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3939
$comment = trim($tokens[$stackPtr]['content']);
4040

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

@@ -54,21 +54,21 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
5454
$phpcsFile->fixer->replaceToken($stackPtr, $newComment);
5555
}
5656
}
57-
elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '/')
57+
elseif ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '/')
5858
{
5959
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '// ...');
6060
$singleLine = true;
6161
}
62-
elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '*')
62+
elseif ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '*')
6363
{
6464
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '/* ... */');
6565
}
6666

6767
// Always have a space between // and the start of the comment text.
6868
// The exception to this is if the preceding line consists of a single open bracket.
69-
if ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '/' && isset($tokens[$stackPtr]['content']{2})
70-
&& $tokens[$stackPtr]['content']{2} !== ' ' && isset($tokens[($stackPtr - 1)]['content']{0})
71-
&& $tokens[($stackPtr - 1)]['content']{0} !== '}'
69+
if ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '/' && isset($tokens[$stackPtr]['content'][2])
70+
&& $tokens[$stackPtr]['content'][2] !== ' ' && isset($tokens[($stackPtr - 1)]['content'][0])
71+
&& $tokens[($stackPtr - 1)]['content'][0] !== '}'
7272
)
7373
{
7474
$error = 'Missing space between the // and the start of the comment text.';
@@ -88,23 +88,23 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8888
* the line is a continuation of a complete sentence,
8989
* the term is code and is case sensitive.(@todo)
9090
*/
91-
if (($singleLine === true && isset($tokens[$stackPtr]['content']{3}) && $tokens[$stackPtr]['content']{2} === ' '
92-
&& $tokens[$stackPtr]['content']{3} !== strtoupper($tokens[$stackPtr]['content']{3})) || (isset($comment{2}) && $comment{0} === '*'
93-
&& $comment{1} === ' ' && $comment{2} !== strtoupper($comment{2}))
91+
if (($singleLine === true && isset($tokens[$stackPtr]['content'][3]) && $tokens[$stackPtr]['content'][2] === ' '
92+
&& $tokens[$stackPtr]['content'][3] !== strtoupper($tokens[$stackPtr]['content'][3])) || (isset($comment[2]) && $comment[0] === '*'
93+
&& $comment[1] === ' ' && $comment[2] !== strtoupper($comment[2]))
9494
)
9595
{
9696
$error = 'Comment must start with a capital letter; found "%s"';
9797
$previous = $phpcsFile->findPrevious(T_COMMENT, $stackPtr - 1);
9898

9999
if ($singleLine === true)
100100
{
101-
$data = array($comment{3});
101+
$data = array($comment[3]);
102102
$newComment = ltrim($tokens[$stackPtr]['content'], '\// ');
103103
$newComment = '// ' . ucfirst($newComment);
104104
}
105105
else
106106
{
107-
$data = array($comment{2});
107+
$data = array($comment[2]);
108108
$padding = (strlen($tokens[$stackPtr]['content']) - strlen($comment));
109109
$padding = str_repeat("\t", $padding - 2);
110110
$newComment = ltrim($comment, '* ');
@@ -116,7 +116,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
116116
{
117117
$test = trim($tokens[$previous]['content']);
118118

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

Joomla/Sniffs/NamingConventions/ValidFunctionNameSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $sta
8484
}
8585

8686
// Joomla change: Methods must not have an underscore on the front.
87-
if ($scopeSpecified === true && $methodName{0} === '_')
87+
if ($scopeSpecified === true && $methodName[0] === '_')
8888
{
8989
$error = '%s method name "%s" must not be prefixed with an underscore';
9090
$data = array(
@@ -105,7 +105,7 @@ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $sta
105105
*/
106106
$testMethodName = $methodName;
107107

108-
if ($scopeSpecified === false && $methodName{0} === '_')
108+
if ($scopeSpecified === false && $methodName[0] === '_')
109109
{
110110
$testMethodName = substr($methodName, 1);
111111
}

0 commit comments

Comments
 (0)