Example #1
0
 /**
  * @covers \PHP\Manipulator\Token::setLinenumber
  * @covers \PHP\Manipulator\Token::getLinenumber
  */
 public function testSetLinenumberAndGetLinenumber()
 {
     $token = new Token('foo');
     $this->assertNull($token->getLinenumber(), 'wrong linenumber');
     $fluent = $token->setLinenumber(10);
     $this->assertSame($fluent, $token, 'No fluent interface');
     $this->assertEquals(10, $token->getLinenumber(), 'wrong linenumber');
 }
Example #2
0
 /**
  * Dump a token
  *
  * Replaces spaces, linebreaks and tabs with visual representations:
  * \t \r\n \n \r .
  *
  * @param \PHP\Manipulator\Token $token
  * @return string
  */
 public static function dumpToken(Token $token, $add = true)
 {
     $type = $token->getType();
     $value = $token->getValue();
     $typeName = '[SIMPLE]';
     if (null !== $type) {
         $typeName = $token->getTokenName();
     }
     $length = (string) mb_strlen($value, 'utf-8');
     $search = array("\n\r", "\n", "\r", "\t", ' ');
     $replace = array('\\n\\\\r', '\\n', '\\r', '\\t', '.');
     $value = str_replace($search, $replace, $value);
     $line = $token->getLinenumber();
     if (null === $line) {
         $line = 'NULL';
     }
     return str_pad($typeName, 28, ' ', STR_PAD_RIGHT) . '| ' . str_pad($length, 4, ' ', STR_PAD_LEFT) . ' | ' . str_pad($line, 4, ' ', STR_PAD_LEFT) . ' | ' . $value;
 }