Skip to content

Commit 8471ae7

Browse files
committed
Better comment conditionals
1 parent 47ef1b0 commit 8471ae7

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/Tokenizer/Parser/Comment.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,37 @@ final class Comment
2525
*/
2626
public static function isCommentString($string)
2727
{
28-
return
29-
$string[0] === '#'
30-
|| (
31-
isset($string[1])
32-
&& ($string[0] === '-' && $string[1] === '-')
33-
|| ($string[0] === '/' && $string[1] === '*')
34-
);
28+
return $string[0] === '#' || self::isTwoCharacterComment($string);
29+
}
30+
31+
/**
32+
* @param $string
33+
*
34+
* @return bool
35+
*/
36+
protected static function isTwoCharacterComment($string)
37+
{
38+
return isset($string[1]) && (self::startsWithDoubleDash($string) || self::startsAsBlock($string));
39+
}
40+
41+
/**
42+
* @param $string
43+
*
44+
* @return bool
45+
*/
46+
protected static function startsWithDoubleDash($string)
47+
{
48+
return $string[0] === '-' && ($string[1] === $string[0]);
49+
}
50+
51+
/**
52+
* @param $string
53+
*
54+
* @return bool
55+
*/
56+
protected static function startsAsBlock($string)
57+
{
58+
return $string[0] === '/' && $string[1] === '*';
3559
}
3660

3761
/**

0 commit comments

Comments
 (0)