Skip to content

Commit 57a1433

Browse files
author
Michael Babker
authored
Merge pull request #259 from jrfnl/feature/fix-php-7.4-compat-3.x
Fix compatibility with PHP 7.4 (3.x)
2 parents fc041ba + 9c1768e commit 57a1433

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
@@ -419,13 +419,13 @@ protected function processPackage(File $phpcsFile, array $tags)
419419
{
420420
$nameBits = explode('_', $newContent);
421421
$firstBit = array_shift($nameBits);
422-
$newName = strtoupper($firstBit{0}) . substr($firstBit, 1) . '_';
422+
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
423423

424424
foreach ($nameBits as $bit)
425425
{
426426
if ($bit !== '')
427427
{
428-
$newName .= strtoupper($bit{0}) . substr($bit, 1) . '_';
428+
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
429429
}
430430
}
431431

Joomla/Sniffs/Commenting/SingleCommentSniff.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr)
4242
$comment = trim($tokens[$stackPtr]['content']);
4343

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

@@ -57,21 +57,21 @@ public function process(File $phpcsFile, $stackPtr)
5757
$phpcsFile->fixer->replaceToken($stackPtr, $newComment);
5858
}
5959
}
60-
elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '/')
60+
elseif ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '/')
6161
{
6262
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '// ...');
6363
$singleLine = true;
6464
}
65-
elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '*')
65+
elseif ($tokens[$stackPtr]['content'][0] === '/' && $tokens[$stackPtr]['content'][1] === '*')
6666
{
6767
$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '/* ... */');
6868
}
6969

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

102102
if ($singleLine === true)
103103
{
104-
$data = array($comment{3});
104+
$data = array($comment[3]);
105105
$newComment = ltrim($tokens[$stackPtr]['content'], '\// ');
106106
$newComment = '// ' . ucfirst($newComment);
107107
}
108108
else
109109
{
110-
$data = array($comment{2});
110+
$data = array($comment[2]);
111111
$padding = (strlen($tokens[$stackPtr]['content']) - strlen($comment));
112112
$padding = str_repeat("\t", $padding - 2);
113113
$newComment = ltrim($comment, '* ');
@@ -119,7 +119,7 @@ public function process(File $phpcsFile, $stackPtr)
119119
{
120120
$test = trim($tokens[$previous]['content']);
121121

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

Joomla/Sniffs/NamingConventions/ValidFunctionNameSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
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(File $phpcsFile, $stackPtr, $currScop
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)