77use Sabberworm \CSS \Comment \Comment ;
88use Sabberworm \CSS \Settings ;
99
10- use function Safe \iconv ;
11- use function Safe \preg_match ;
12- use function Safe \preg_split ;
13-
1410/**
1511 * @internal since 8.7.0
1612 */
@@ -121,7 +117,12 @@ public function parseIdentifier(bool $ignoreCase = true): string
121117 }
122118 $ character = null ;
123119 while (!$ this ->isEnd () && ($ character = $ this ->parseCharacter (true )) !== null ) {
124- if (preg_match ('/[a-zA-Z0-9 \\x{00A0}- \\x{FFFF}_-]/Sux ' , $ character ) !== 0 ) {
120+ /** @phpstan-ignore theCodingMachineSafe.function */
121+ $ matchResult = \preg_match ('/[a-zA-Z0-9 \\x{00A0}- \\x{FFFF}_-]/Sux ' , $ character );
122+ if ($ matchResult === false ) {
123+ throw new \RuntimeException ('Unexpected error ' );
124+ }
125+ if ($ matchResult !== 0 ) {
125126 $ result .= $ character ;
126127 } else {
127128 $ result .= '\\' . $ character ;
@@ -145,13 +146,23 @@ public function parseCharacter(bool $isForIdentifier): ?string
145146 if ($ this ->comes ('\\n ' ) || $ this ->comes ('\\r ' )) {
146147 return '' ;
147148 }
148- if (preg_match ('/[0-9a-fA-F]/Su ' , $ this ->peek ()) === 0 ) {
149+ /** @phpstan-ignore theCodingMachineSafe.function */
150+ $ hexMatch = \preg_match ('/[0-9a-fA-F]/Su ' , $ this ->peek ());
151+ if ($ hexMatch === false ) {
152+ throw new \RuntimeException ('Unexpected error ' );
153+ }
154+ if ($ hexMatch === 0 ) {
149155 return $ this ->consume (1 );
150156 }
151157 $ hexCodePoint = $ this ->consumeExpression ('/^[0-9a-fA-F]{1,6}/u ' , 6 );
152158 if ($ this ->strlen ($ hexCodePoint ) < 6 ) {
153159 // Consume whitespace after incomplete unicode escape
154- if (preg_match ('/ \\s/isSu ' , $ this ->peek ()) !== 0 ) {
160+ /** @phpstan-ignore theCodingMachineSafe.function */
161+ $ whitespaceMatch = \preg_match ('/ \\s/isSu ' , $ this ->peek ());
162+ if ($ whitespaceMatch === false ) {
163+ throw new \RuntimeException ('Unexpected error ' );
164+ }
165+ if ($ whitespaceMatch !== 0 ) {
155166 if ($ this ->comes ('\\r \\n ' )) {
156167 $ this ->consume (2 );
157168 } else {
@@ -165,7 +176,8 @@ public function parseCharacter(bool $isForIdentifier): ?string
165176 $ utf32EncodedCharacter .= \chr ($ codePoint & 0xff );
166177 $ codePoint = $ codePoint >> 8 ;
167178 }
168- return iconv ('utf-32le ' , $ this ->charset , $ utf32EncodedCharacter );
179+ /** @phpstan-ignore theCodingMachineSafe.function */
180+ return \iconv ('utf-32le ' , $ this ->charset , $ utf32EncodedCharacter );
169181 }
170182 if ($ isForIdentifier ) {
171183 $ peek = \ord ($ this ->peek ());
@@ -205,7 +217,15 @@ public function consumeWhiteSpace(array &$comments = []): string
205217 {
206218 $ consumed = '' ;
207219 do {
208- while (preg_match ('/ \\s/isSu ' , $ this ->peek ()) === 1 ) {
220+ while (true ) {
221+ /** @phpstan-ignore theCodingMachineSafe.function */
222+ $ whitespaceCheck = \preg_match ('/ \\s/isSu ' , $ this ->peek ());
223+ if ($ whitespaceCheck === false ) {
224+ throw new \RuntimeException ('Unexpected error ' );
225+ }
226+ if ($ whitespaceCheck !== 1 ) {
227+ break ;
228+ }
209229 $ consumed .= $ this ->consume (1 );
210230 }
211231 if ($ this ->parserSettings ->usesLenientParsing ()) {
@@ -319,7 +339,8 @@ public function consumeExpression(string $expression, ?int $maximumLength = null
319339 {
320340 $ matches = null ;
321341 $ input = ($ maximumLength !== null ) ? $ this ->peek ($ maximumLength ) : $ this ->inputLeft ();
322- if (preg_match ($ expression , $ input , $ matches , PREG_OFFSET_CAPTURE ) !== 1 ) {
342+ /** @phpstan-ignore theCodingMachineSafe.function */
343+ if (\preg_match ($ expression , $ input , $ matches , PREG_OFFSET_CAPTURE ) !== 1 ) {
323344 throw new UnexpectedTokenException ($ expression , $ this ->peek (5 ), 'expression ' , $ this ->lineNumber );
324345 }
325346
@@ -468,7 +489,11 @@ private function strsplit(string $string): array
468489 {
469490 if ($ this ->parserSettings ->hasMultibyteSupport ()) {
470491 if ($ this ->streql ($ this ->charset , 'utf-8 ' )) {
471- $ result = preg_split ('//u ' , $ string , -1 , PREG_SPLIT_NO_EMPTY );
492+ /** @phpstan-ignore theCodingMachineSafe.function */
493+ $ result = \preg_split ('//u ' , $ string , -1 , PREG_SPLIT_NO_EMPTY );
494+ if ($ result === false ) {
495+ throw new \RuntimeException ('Unexpected error ' );
496+ }
472497 } else {
473498 $ length = \mb_strlen ($ string , $ this ->charset );
474499 $ result = [];
0 commit comments