Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions CodeSniffer/Tokenizers/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
*/

for ($c = 0; $c < $numChars; $c++) {
if ($string[$c] !== '/' && $string[$c] !== '*') {
if (substr($string, $c, 1) !== '/' && substr($string, $c, 1) !== '*') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge old code does the same as new code. Am I missing something.

Old code won't work on PHP7, but new code will however. That's good thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old code works perfectly fine on PHP7. The unit tests have been running on it most of the year.

break;
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
*/

for ($i = ($numChars - 1); $i > $c; $i--) {
if ($string[$i] !== '/' && $string[$i] !== '*') {
if (substr($string, $i, 1) !== '/' && substr($string, $i, 1) !== '*') {
break;
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
}
}

if ($string[$c] === '*') {
if (substr($string, $c, 1) === '*') {
// This is a function or class doc block line.
$c++;
$tokens[$stackPtr] = array(
Expand Down Expand Up @@ -198,14 +198,19 @@ private function _processLine($string, $eolChar, $start, $end)
$start += strlen($space['content']);
}

if (isset($string[$start]) === false) {
if ($start >= strlen($string)) {
return $tokens;
}

if ($string[$start] === '@') {
if (substr($string, $start, 1) === '@') {
// The content up until the first whitespace is the tag name.
$matches = array();
preg_match('/@[^\s]+/', $string, $matches, 0, $start);
if (function_exists('mb_strlen')) {
$startBit = mb_strlen(substr($string, 0, $start), '8bit');
} else {
$startBit = $start;
}
preg_match('/@[^\s]+/', $string, $matches, 0, $startBit);
if (isset($matches[0]) === true) {
$tagName = $matches[0];
$start += strlen($tagName);
Expand Down Expand Up @@ -264,11 +269,11 @@ private function _collectWhitespace($string, $start, $end)
{
$space = '';
for ($start; $start < $end; $start++) {
if ($string[$start] !== ' ' && $string[$start] !== "\t") {
if (substr($string, $start, 1) !== ' ' && substr($string, $start, 1) !== "\t") {
break;
}

$space .= $string[$start];
$space .= substr($string, $start, 1);
}

if ($space === '') {
Expand Down