Skip to content

Commit

Permalink
Php 8.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
810 committed Sep 20, 2023
1 parent 1b5feb6 commit 77d668a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Kunena/Sniffs/Commenting/FileCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) . '_';
}
}

Expand Down
24 changes: 12 additions & 12 deletions Kunena/Sniffs/Commenting/SingleCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '# ...');

Expand All @@ -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.';
Expand All @@ -92,23 +92,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 @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions Kunena/Tests/Functions/StatementNotFunctionUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ echo $a;

require(realpath(__DIR__) . '/' . $a);

require (realpath(__DIR__) . '/no_file.php');

require ($a);
3 changes: 0 additions & 3 deletions Kunena/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class MyClass

class MyClass
{



/**
* Var description.
*
Expand Down

0 comments on commit 77d668a

Please sign in to comment.