From 77d668a81fe933605e2f3203c86c536d4a5638d4 Mon Sep 17 00:00:00 2001 From: Jelle Kok Date: Wed, 20 Sep 2023 15:14:49 +0200 Subject: [PATCH] Php 8.2 support --- Kunena/Sniffs/Commenting/FileCommentSniff.php | 4 ++-- .../Sniffs/Commenting/SingleCommentSniff.php | 24 +++++++++---------- .../StatementNotFunctionUnitTest.inc | 2 -- .../WhiteSpace/MemberVarSpacingUnitTest.inc | 3 --- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Kunena/Sniffs/Commenting/FileCommentSniff.php b/Kunena/Sniffs/Commenting/FileCommentSniff.php index 7ad05e0..e8f83ec 100644 --- a/Kunena/Sniffs/Commenting/FileCommentSniff.php +++ b/Kunena/Sniffs/Commenting/FileCommentSniff.php @@ -420,13 +420,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) . '_'; } } diff --git a/Kunena/Sniffs/Commenting/SingleCommentSniff.php b/Kunena/Sniffs/Commenting/SingleCommentSniff.php index 059ce54..51ae4b5 100644 --- a/Kunena/Sniffs/Commenting/SingleCommentSniff.php +++ b/Kunena/Sniffs/Commenting/SingleCommentSniff.php @@ -43,7 +43,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', '# ...'); @@ -58,21 +58,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.'; @@ -92,9 +92,9 @@ 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"'; @@ -102,13 +102,13 @@ public function process(File $phpcsFile, $stackPtr) 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, '* '); @@ -120,7 +120,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); diff --git a/Kunena/Tests/Functions/StatementNotFunctionUnitTest.inc b/Kunena/Tests/Functions/StatementNotFunctionUnitTest.inc index 90038fe..3c660a1 100644 --- a/Kunena/Tests/Functions/StatementNotFunctionUnitTest.inc +++ b/Kunena/Tests/Functions/StatementNotFunctionUnitTest.inc @@ -12,6 +12,4 @@ echo $a; require(realpath(__DIR__) . '/' . $a); -require (realpath(__DIR__) . '/no_file.php'); - require ($a); diff --git a/Kunena/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc b/Kunena/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc index ea8e6f4..1a48b8c 100644 --- a/Kunena/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc +++ b/Kunena/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc @@ -30,9 +30,6 @@ class MyClass class MyClass { - - - /** * Var description. *