Conditions | 119 |
Paths | > 20000 |
Total Lines | 609 |
Code Lines | 341 |
Lines | 40 |
Ratio | 6.57 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
260 | public function tokenizeString($string, $eolChar='\n') |
||
261 | { |
||
262 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
263 | echo "\t*** START JS TOKENIZING ***".PHP_EOL; |
||
264 | } |
||
265 | |||
266 | $maxTokenLength = 0; |
||
267 | foreach ($this->tokenValues as $token => $values) { |
||
268 | if (strlen($token) > $maxTokenLength) { |
||
269 | $maxTokenLength = strlen($token); |
||
270 | } |
||
271 | } |
||
272 | |||
273 | $tokens = array(); |
||
274 | $inString = ''; |
||
275 | $stringChar = null; |
||
276 | $inComment = ''; |
||
277 | $buffer = ''; |
||
278 | $preStringBuffer = ''; |
||
279 | $cleanBuffer = false; |
||
280 | |||
281 | $commentTokenizer = new PHP_CodeSniffer_Tokenizers_Comment(); |
||
282 | |||
283 | $tokens[] = array( |
||
284 | 'code' => T_OPEN_TAG, |
||
285 | 'type' => 'T_OPEN_TAG', |
||
286 | 'content' => '', |
||
287 | ); |
||
288 | |||
289 | // Convert newlines to single characters for ease of |
||
290 | // processing. We will change them back later. |
||
291 | $string = str_replace($eolChar, "\n", $string); |
||
292 | |||
293 | $chars = str_split($string); |
||
294 | $numChars = count($chars); |
||
295 | for ($i = 0; $i < $numChars; $i++) { |
||
296 | $char = $chars[$i]; |
||
297 | |||
298 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
299 | $content = PHP_CodeSniffer::prepareForOutput($char); |
||
300 | $bufferContent = PHP_CodeSniffer::prepareForOutput($buffer); |
||
301 | |||
302 | if ($inString !== '') { |
||
303 | echo "\t"; |
||
304 | } |
||
305 | |||
306 | if ($inComment !== '') { |
||
307 | echo "\t"; |
||
308 | } |
||
309 | |||
310 | echo "\tProcess char $i => $content (buffer: $bufferContent)".PHP_EOL; |
||
311 | }//end if |
||
312 | |||
313 | if ($inString === '' && $inComment === '' && $buffer !== '') { |
||
314 | // If the buffer only has whitespace and we are about to |
||
315 | // add a character, store the whitespace first. |
||
316 | View Code Duplication | if (trim($char) !== '' && trim($buffer) === '') { |
|
317 | $tokens[] = array( |
||
318 | 'code' => T_WHITESPACE, |
||
319 | 'type' => 'T_WHITESPACE', |
||
320 | 'content' => str_replace("\n", $eolChar, $buffer), |
||
321 | ); |
||
322 | |||
323 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
324 | $content = PHP_CodeSniffer::prepareForOutput($buffer); |
||
325 | echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL; |
||
326 | } |
||
327 | |||
328 | $buffer = ''; |
||
329 | } |
||
330 | |||
331 | // If the buffer is not whitespace and we are about to |
||
332 | // add a whitespace character, store the content first. |
||
333 | if ($inString === '' |
||
334 | && $inComment === '' |
||
335 | && trim($char) === '' |
||
336 | && trim($buffer) !== '' |
||
337 | ) { |
||
338 | $tokens[] = array( |
||
339 | 'code' => T_STRING, |
||
340 | 'type' => 'T_STRING', |
||
341 | 'content' => str_replace("\n", $eolChar, $buffer), |
||
342 | ); |
||
343 | |||
344 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
345 | $content = PHP_CodeSniffer::prepareForOutput($buffer); |
||
346 | echo "\t=> Added token T_STRING ($content)".PHP_EOL; |
||
347 | } |
||
348 | |||
349 | $buffer = ''; |
||
350 | } |
||
351 | }//end if |
||
352 | |||
353 | // Process strings. |
||
354 | if ($inComment === '' && isset($this->stringTokens[$char]) === true) { |
||
355 | if ($inString === $char) { |
||
356 | // This could be the end of the string, but make sure it |
||
357 | // is not escaped first. |
||
358 | $escapes = 0; |
||
359 | for ($x = ($i - 1); $x >= 0; $x--) { |
||
360 | if ($chars[$x] !== '\\') { |
||
361 | break; |
||
362 | } |
||
363 | |||
364 | $escapes++; |
||
365 | } |
||
366 | |||
367 | if ($escapes === 0 || ($escapes % 2) === 0) { |
||
368 | // There is an even number escape chars, |
||
369 | // so this is not escaped, it is the end of the string. |
||
370 | $tokens[] = array( |
||
371 | 'code' => T_CONSTANT_ENCAPSED_STRING, |
||
372 | 'type' => 'T_CONSTANT_ENCAPSED_STRING', |
||
373 | 'content' => str_replace("\n", $eolChar, $buffer).$char, |
||
374 | ); |
||
375 | |||
376 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
377 | echo "\t\t* found end of string *".PHP_EOL; |
||
378 | $content = PHP_CodeSniffer::prepareForOutput($buffer.$char); |
||
379 | echo "\t=> Added token T_CONSTANT_ENCAPSED_STRING ($content)".PHP_EOL; |
||
380 | } |
||
381 | |||
382 | $buffer = ''; |
||
383 | $preStringBuffer = ''; |
||
384 | $inString = ''; |
||
385 | $stringChar = null; |
||
386 | continue; |
||
387 | }//end if |
||
388 | } else if ($inString === '') { |
||
389 | $inString = $char; |
||
390 | $stringChar = $i; |
||
391 | $preStringBuffer = $buffer; |
||
392 | |||
393 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
394 | echo "\t\t* looking for string closer *".PHP_EOL; |
||
395 | } |
||
396 | }//end if |
||
397 | }//end if |
||
398 | |||
399 | if ($inString !== '' && $char === "\n") { |
||
400 | // Unless this newline character is escaped, the string did not |
||
401 | // end before the end of the line, which means it probably |
||
402 | // wasn't a string at all (maybe a regex). |
||
403 | if ($chars[($i - 1)] !== '\\') { |
||
404 | $i = $stringChar; |
||
405 | $buffer = $preStringBuffer; |
||
406 | $preStringBuffer = ''; |
||
407 | $inString = ''; |
||
408 | $stringChar = null; |
||
409 | $char = $chars[$i]; |
||
410 | |||
411 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
412 | echo "\t\t* found newline before end of string, bailing *".PHP_EOL; |
||
413 | } |
||
414 | } |
||
415 | } |
||
416 | |||
417 | $buffer .= $char; |
||
418 | |||
419 | // We don't look for special tokens inside strings, |
||
420 | // so if we are in a string, we can continue here now |
||
421 | // that the current char is in the buffer. |
||
422 | if ($inString !== '') { |
||
423 | continue; |
||
424 | } |
||
425 | |||
426 | // Special case for T_DIVIDE which can actually be |
||
427 | // the start of a regular expression. |
||
428 | if ($buffer === $char && $char === '/' && $chars[($i + 1)] !== '*') { |
||
429 | $regex = $this->getRegexToken( |
||
430 | $i, |
||
431 | $string, |
||
432 | $chars, |
||
433 | $tokens, |
||
434 | $eolChar |
||
435 | ); |
||
436 | |||
437 | if ($regex !== null) { |
||
438 | $tokens[] = array( |
||
439 | 'code' => T_REGULAR_EXPRESSION, |
||
440 | 'type' => 'T_REGULAR_EXPRESSION', |
||
441 | 'content' => $regex['content'], |
||
442 | ); |
||
443 | |||
444 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
445 | $content = PHP_CodeSniffer::prepareForOutput($regex['content']); |
||
446 | echo "\t=> Added token T_REGULAR_EXPRESSION ($content)".PHP_EOL; |
||
447 | } |
||
448 | |||
449 | $i = $regex['end']; |
||
450 | $buffer = ''; |
||
451 | $cleanBuffer = false; |
||
452 | continue; |
||
453 | }//end if |
||
454 | }//end if |
||
455 | |||
456 | // Check for known tokens, but ignore tokens found that are not at |
||
457 | // the end of a string, like FOR and this.FORmat. |
||
458 | if (isset($this->tokenValues[strtolower($buffer)]) === true |
||
459 | && (preg_match('|[a-zA-z0-9_]|', $char) === 0 |
||
460 | || isset($chars[($i + 1)]) === false |
||
461 | || preg_match('|[a-zA-z0-9_]|', $chars[($i + 1)]) === 0) |
||
462 | ) { |
||
463 | $matchedToken = false; |
||
464 | $lookAheadLength = ($maxTokenLength - strlen($buffer)); |
||
465 | |||
466 | if ($lookAheadLength > 0) { |
||
467 | // The buffer contains a token type, but we need |
||
468 | // to look ahead at the next chars to see if this is |
||
469 | // actually part of a larger token. For example, |
||
470 | // FOR and FOREACH. |
||
471 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
472 | echo "\t\t* buffer possibly contains token, looking ahead $lookAheadLength chars *".PHP_EOL; |
||
473 | } |
||
474 | |||
475 | $charBuffer = $buffer; |
||
476 | for ($x = 1; $x <= $lookAheadLength; $x++) { |
||
477 | if (isset($chars[($i + $x)]) === false) { |
||
478 | break; |
||
479 | } |
||
480 | |||
481 | $charBuffer .= $chars[($i + $x)]; |
||
482 | |||
483 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
484 | $content = PHP_CodeSniffer::prepareForOutput($charBuffer); |
||
485 | echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL; |
||
486 | } |
||
487 | |||
488 | if (isset($this->tokenValues[strtolower($charBuffer)]) === true) { |
||
489 | // We've found something larger that matches |
||
490 | // so we can ignore this char. Except for 1 very specific |
||
491 | // case where a comment like /**/ needs to tokenize as |
||
492 | // T_COMMENT and not T_DOC_COMMENT. |
||
493 | $oldType = $this->tokenValues[strtolower($buffer)]; |
||
494 | $newType = $this->tokenValues[strtolower($charBuffer)]; |
||
495 | if ($oldType === 'T_COMMENT' |
||
496 | && $newType === 'T_DOC_COMMENT' |
||
497 | && $chars[($i + $x + 1)] === '/' |
||
498 | ) { |
||
499 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
500 | echo "\t\t* look ahead ignored T_DOC_COMMENT, continuing *".PHP_EOL; |
||
501 | } |
||
502 | } else { |
||
503 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
504 | echo "\t\t* look ahead found more specific token ($newType), ignoring $i *".PHP_EOL; |
||
505 | } |
||
506 | |||
507 | $matchedToken = true; |
||
508 | break; |
||
509 | } |
||
510 | }//end if |
||
511 | }//end for |
||
512 | }//end if |
||
513 | |||
514 | if ($matchedToken === false) { |
||
515 | if (PHP_CODESNIFFER_VERBOSITY > 1 && $lookAheadLength > 0) { |
||
516 | echo "\t\t* look ahead found nothing *".PHP_EOL; |
||
517 | } |
||
518 | |||
519 | $value = $this->tokenValues[strtolower($buffer)]; |
||
520 | |||
521 | if ($value === 'T_FUNCTION' && $buffer !== 'function') { |
||
522 | // The function keyword needs to be all lowercase or else |
||
523 | // it is just a function called "Function". |
||
524 | $value = 'T_STRING'; |
||
525 | } |
||
526 | |||
527 | $tokens[] = array( |
||
528 | 'code' => constant($value), |
||
529 | 'type' => $value, |
||
530 | 'content' => $buffer, |
||
531 | ); |
||
532 | |||
533 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
534 | $content = PHP_CodeSniffer::prepareForOutput($buffer); |
||
535 | echo "\t=> Added token $value ($content)".PHP_EOL; |
||
536 | } |
||
537 | |||
538 | $cleanBuffer = true; |
||
539 | }//end if |
||
540 | } else if (isset($this->tokenValues[strtolower($char)]) === true) { |
||
541 | // No matter what token we end up using, we don't |
||
542 | // need the content in the buffer any more because we have |
||
543 | // found a valid token. |
||
544 | $newContent = substr(str_replace("\n", $eolChar, $buffer), 0, -1); |
||
545 | if ($newContent !== '') { |
||
546 | $tokens[] = array( |
||
547 | 'code' => T_STRING, |
||
548 | 'type' => 'T_STRING', |
||
549 | 'content' => $newContent, |
||
550 | ); |
||
551 | |||
552 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
553 | $content = PHP_CodeSniffer::prepareForOutput(substr($buffer, 0, -1)); |
||
554 | echo "\t=> Added token T_STRING ($content)".PHP_EOL; |
||
555 | } |
||
556 | } |
||
557 | |||
558 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
559 | echo "\t\t* char is token, looking ahead ".($maxTokenLength - 1).' chars *'.PHP_EOL; |
||
560 | } |
||
561 | |||
562 | // The char is a token type, but we need to look ahead at the |
||
563 | // next chars to see if this is actually part of a larger token. |
||
564 | // For example, = and ===. |
||
565 | $charBuffer = $char; |
||
566 | $matchedToken = false; |
||
567 | for ($x = 1; $x <= $maxTokenLength; $x++) { |
||
568 | if (isset($chars[($i + $x)]) === false) { |
||
569 | break; |
||
570 | } |
||
571 | |||
572 | $charBuffer .= $chars[($i + $x)]; |
||
573 | |||
574 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
575 | $content = PHP_CodeSniffer::prepareForOutput($charBuffer); |
||
576 | echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL; |
||
577 | } |
||
578 | |||
579 | if (isset($this->tokenValues[strtolower($charBuffer)]) === true) { |
||
580 | // We've found something larger that matches |
||
581 | // so we can ignore this char. |
||
582 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
583 | $type = $this->tokenValues[strtolower($charBuffer)]; |
||
584 | echo "\t\t* look ahead found more specific token ($type), ignoring $i *".PHP_EOL; |
||
585 | } |
||
586 | |||
587 | $matchedToken = true; |
||
588 | break; |
||
589 | } |
||
590 | }//end for |
||
591 | |||
592 | if ($matchedToken === false) { |
||
593 | $value = $this->tokenValues[strtolower($char)]; |
||
594 | $tokens[] = array( |
||
595 | 'code' => constant($value), |
||
596 | 'type' => $value, |
||
597 | 'content' => $char, |
||
598 | ); |
||
599 | |||
600 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
601 | echo "\t\t* look ahead found nothing *".PHP_EOL; |
||
602 | $content = PHP_CodeSniffer::prepareForOutput($char); |
||
603 | echo "\t=> Added token $value ($content)".PHP_EOL; |
||
604 | } |
||
605 | |||
606 | $cleanBuffer = true; |
||
607 | } else { |
||
608 | $buffer = $char; |
||
609 | }//end if |
||
610 | }//end if |
||
611 | |||
612 | // Keep track of content inside comments. |
||
613 | if ($inComment === '' |
||
614 | && array_key_exists($buffer, $this->commentTokens) === true |
||
615 | ) { |
||
616 | // This is not really a comment if the content |
||
617 | // looks like \// (i.e., it is escaped). |
||
618 | if (isset($chars[($i - 2)]) === true && $chars[($i - 2)] === '\\') { |
||
619 | $lastToken = array_pop($tokens); |
||
620 | $lastContent = $lastToken['content']; |
||
621 | View Code Duplication | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
622 | $value = $this->tokenValues[strtolower($lastContent)]; |
||
623 | $content = PHP_CodeSniffer::prepareForOutput($lastContent); |
||
624 | echo "\t=> Removed token $value ($content)".PHP_EOL; |
||
625 | } |
||
626 | |||
627 | $lastChars = str_split($lastContent); |
||
628 | $lastNumChars = count($lastChars); |
||
629 | for ($x = 0; $x < $lastNumChars; $x++) { |
||
630 | $lastChar = $lastChars[$x]; |
||
631 | $value = $this->tokenValues[strtolower($lastChar)]; |
||
632 | $tokens[] = array( |
||
633 | 'code' => constant($value), |
||
634 | 'type' => $value, |
||
635 | 'content' => $lastChar, |
||
636 | ); |
||
637 | |||
638 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
639 | $content = PHP_CodeSniffer::prepareForOutput($lastChar); |
||
640 | echo "\t=> Added token $value ($content)".PHP_EOL; |
||
641 | } |
||
642 | } |
||
643 | } else { |
||
644 | // We have started a comment. |
||
645 | $inComment = $buffer; |
||
646 | |||
647 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
648 | echo "\t\t* looking for end of comment *".PHP_EOL; |
||
649 | } |
||
650 | }//end if |
||
651 | } else if ($inComment !== '') { |
||
652 | if ($this->commentTokens[$inComment] === null) { |
||
653 | // Comment ends at the next newline. |
||
654 | if (strpos($buffer, "\n") !== false) { |
||
655 | $inComment = ''; |
||
656 | } |
||
657 | } else { |
||
658 | if ($this->commentTokens[$inComment] === $buffer) { |
||
659 | $inComment = ''; |
||
660 | } |
||
661 | } |
||
662 | |||
663 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
664 | if ($inComment === '') { |
||
665 | echo "\t\t* found end of comment *".PHP_EOL; |
||
666 | } |
||
667 | } |
||
668 | |||
669 | View Code Duplication | if ($inComment === '' && $cleanBuffer === false) { |
|
670 | $tokens[] = array( |
||
671 | 'code' => T_STRING, |
||
672 | 'type' => 'T_STRING', |
||
673 | 'content' => str_replace("\n", $eolChar, $buffer), |
||
674 | ); |
||
675 | |||
676 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
677 | $content = PHP_CodeSniffer::prepareForOutput($buffer); |
||
678 | echo "\t=> Added token T_STRING ($content)".PHP_EOL; |
||
679 | } |
||
680 | |||
681 | $buffer = ''; |
||
682 | } |
||
683 | }//end if |
||
684 | |||
685 | if ($cleanBuffer === true) { |
||
686 | $buffer = ''; |
||
687 | $cleanBuffer = false; |
||
688 | } |
||
689 | }//end for |
||
690 | |||
691 | if (empty($buffer) === false) { |
||
692 | // Buffer contains whitespace from the end of the file. |
||
693 | $tokens[] = array( |
||
694 | 'code' => T_WHITESPACE, |
||
695 | 'type' => 'T_WHITESPACE', |
||
696 | 'content' => str_replace("\n", $eolChar, $buffer), |
||
697 | ); |
||
698 | |||
699 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
700 | $content = PHP_CodeSniffer::prepareForOutput($buffer); |
||
701 | echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL; |
||
702 | } |
||
703 | } |
||
704 | |||
705 | $tokens[] = array( |
||
706 | 'code' => T_CLOSE_TAG, |
||
707 | 'type' => 'T_CLOSE_TAG', |
||
708 | 'content' => '', |
||
709 | ); |
||
710 | |||
711 | /* |
||
712 | Now that we have done some basic tokenizing, we need to |
||
713 | modify the tokens to join some together and split some apart |
||
714 | so they match what the PHP tokenizer does. |
||
715 | */ |
||
716 | |||
717 | $finalTokens = array(); |
||
718 | $newStackPtr = 0; |
||
719 | $numTokens = count($tokens); |
||
720 | for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) { |
||
721 | $token = $tokens[$stackPtr]; |
||
722 | |||
723 | /* |
||
724 | Look for comments and join the tokens together. |
||
725 | */ |
||
726 | |||
727 | if ($token['code'] === T_COMMENT || $token['code'] === T_DOC_COMMENT) { |
||
728 | $newContent = ''; |
||
729 | $tokenContent = $token['content']; |
||
730 | $endContent = $this->commentTokens[$tokenContent]; |
||
731 | while ($tokenContent !== $endContent) { |
||
732 | if ($endContent === null |
||
733 | && strpos($tokenContent, $eolChar) !== false |
||
734 | ) { |
||
735 | // A null end token means the comment ends at the end of |
||
736 | // the line so we look for newlines and split the token. |
||
737 | $tokens[$stackPtr]['content'] = substr( |
||
738 | $tokenContent, |
||
739 | (strpos($tokenContent, $eolChar) + strlen($eolChar)) |
||
740 | ); |
||
741 | |||
742 | $tokenContent = substr( |
||
743 | $tokenContent, |
||
744 | 0, |
||
745 | (strpos($tokenContent, $eolChar) + strlen($eolChar)) |
||
746 | ); |
||
747 | |||
748 | // If the substr failed, skip the token as the content |
||
749 | // will now be blank. |
||
750 | if ($tokens[$stackPtr]['content'] !== false |
||
751 | && $tokens[$stackPtr]['content'] !== '' |
||
752 | ) { |
||
753 | $stackPtr--; |
||
754 | } |
||
755 | |||
756 | break; |
||
757 | }//end if |
||
758 | |||
759 | $stackPtr++; |
||
760 | $newContent .= $tokenContent; |
||
761 | if (isset($tokens[$stackPtr]) === false) { |
||
762 | break; |
||
763 | } |
||
764 | |||
765 | $tokenContent = $tokens[$stackPtr]['content']; |
||
766 | }//end while |
||
767 | |||
768 | if ($token['code'] === T_DOC_COMMENT) { |
||
769 | $commentTokens = $commentTokenizer->tokenizeString($newContent.$tokenContent, $eolChar, $newStackPtr); |
||
770 | foreach ($commentTokens as $commentToken) { |
||
771 | $finalTokens[$newStackPtr] = $commentToken; |
||
772 | $newStackPtr++; |
||
773 | } |
||
774 | |||
775 | continue; |
||
776 | } else { |
||
777 | // Save the new content in the current token so |
||
778 | // the code below can chop it up on newlines. |
||
779 | $token['content'] = $newContent.$tokenContent; |
||
780 | } |
||
781 | }//end if |
||
782 | |||
783 | /* |
||
784 | If this token has newlines in its content, split each line up |
||
785 | and create a new token for each line. We do this so it's easier |
||
786 | to ascertain where errors occur on a line. |
||
787 | Note that $token[1] is the token's content. |
||
788 | */ |
||
789 | |||
790 | if (strpos($token['content'], $eolChar) !== false) { |
||
791 | $tokenLines = explode($eolChar, $token['content']); |
||
792 | $numLines = count($tokenLines); |
||
793 | |||
794 | for ($i = 0; $i < $numLines; $i++) { |
||
795 | $newToken['content'] = $tokenLines[$i]; |
||
796 | View Code Duplication | if ($i === ($numLines - 1)) { |
|
797 | if ($tokenLines[$i] === '') { |
||
798 | break; |
||
799 | } |
||
800 | } else { |
||
801 | $newToken['content'] .= $eolChar; |
||
802 | } |
||
803 | |||
804 | $newToken['type'] = $token['type']; |
||
805 | $newToken['code'] = $token['code']; |
||
806 | $finalTokens[$newStackPtr] = $newToken; |
||
807 | $newStackPtr++; |
||
808 | } |
||
809 | } else { |
||
810 | $finalTokens[$newStackPtr] = $token; |
||
811 | $newStackPtr++; |
||
812 | }//end if |
||
813 | |||
814 | // Convert numbers, including decimals. |
||
815 | if ($token['code'] === T_STRING |
||
816 | || $token['code'] === T_OBJECT_OPERATOR |
||
817 | ) { |
||
818 | $newContent = ''; |
||
819 | $oldStackPtr = $stackPtr; |
||
820 | while (preg_match('|^[0-9\.]+$|', $tokens[$stackPtr]['content']) !== 0) { |
||
821 | $newContent .= $tokens[$stackPtr]['content']; |
||
822 | $stackPtr++; |
||
823 | } |
||
824 | |||
825 | if ($newContent !== '' && $newContent !== '.') { |
||
826 | $finalTokens[($newStackPtr - 1)]['content'] = $newContent; |
||
827 | if (ctype_digit($newContent) === true) { |
||
828 | $finalTokens[($newStackPtr - 1)]['code'] = constant('T_LNUMBER'); |
||
829 | $finalTokens[($newStackPtr - 1)]['type'] = 'T_LNUMBER'; |
||
830 | } else { |
||
831 | $finalTokens[($newStackPtr - 1)]['code'] = constant('T_DNUMBER'); |
||
832 | $finalTokens[($newStackPtr - 1)]['type'] = 'T_DNUMBER'; |
||
833 | } |
||
834 | |||
835 | $stackPtr--; |
||
836 | continue; |
||
837 | } else { |
||
838 | $stackPtr = $oldStackPtr; |
||
839 | } |
||
840 | }//end if |
||
841 | |||
842 | // Convert the token after an object operator into a string, in most cases. |
||
843 | if ($token['code'] === T_OBJECT_OPERATOR) { |
||
844 | for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { |
||
845 | if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true) { |
||
846 | continue; |
||
847 | } |
||
848 | |||
849 | if ($tokens[$i]['code'] !== T_PROTOTYPE |
||
850 | && $tokens[$i]['code'] !== T_LNUMBER |
||
851 | && $tokens[$i]['code'] !== T_DNUMBER |
||
852 | ) { |
||
853 | $tokens[$i]['code'] = T_STRING; |
||
854 | $tokens[$i]['type'] = 'T_STRING'; |
||
855 | } |
||
856 | |||
857 | break; |
||
858 | } |
||
859 | } |
||
860 | }//end for |
||
861 | |||
862 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
||
863 | echo "\t*** END TOKENIZING ***".PHP_EOL; |
||
864 | } |
||
865 | |||
866 | return $finalTokens; |
||
867 | |||
868 | }//end tokenizeString() |
||
869 | |||
1167 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.