Ejemplo n.º 1
0
 /**
  * Evaluate if the token is a multiline comment
  *
  * @param \PHP\Manipulator\Token $token
  * @param mixed $param
  * @return boolean
  */
 public function evaluate(Token $token, $param = null)
 {
     if ($token->getType() === T_COMMENT) {
         $value = $token->getValue();
         if (strlen($value) > 2 && substr($value, 0, 2) === '/*') {
             return true;
         }
     } elseif ($token->getType() === T_DOC_COMMENT) {
         return true;
     }
     return false;
 }
 /**
  * Evaluate if the token is
  *
  * @param \PHP\Manipulator\Token $token
  * @param mixed $param
  * @return boolean
  */
 public function evaluate(Token $token, $params = null)
 {
     if (null === $token->getType() && '@' === $token->getValue()) {
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * @covers \PHP\Manipulator\Token::setType
  * @covers \PHP\Manipulator\Token::getType
  */
 public function testSetTypeAndGetType()
 {
     $token = new Token('foo');
     $this->assertNull($token->getType(), 'wrong type');
     $fluent = $token->setType(T_ABSTRACT);
     $this->assertSame($fluent, $token, 'No fluent interface');
     $this->assertEquals(T_ABSTRACT, $token->getType(), 'wrong type');
 }
Ejemplo n.º 4
0
 /**
  * @param \PHP\Manipulator\Token $token
  * @return boolean
  */
 protected function _isOperatorWithoutToken(Token $token)
 {
     foreach ($this->_operatorsWithoutTokens as $operator) {
         if (null === $token->getType() && $operator === $token->getValue()) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param \PHP\Manipulator\Token $token
  * @param array $whitespaces
  * @return mixed
  */
 public function getWhitespaceForToken(Token $token, array $whitespaces)
 {
     if (null === $token->getType()) {
         $tokenval = $token->getValue();
     } else {
         $tokenval = $token->getType();
     }
     if (array_key_exists($tokenval, $whitespaces)) {
         return $whitespaces[$tokenval];
     } else {
         $message = 'No option found for: ' . $token->getTokenName() . ' (' . $tokenval . ')';
         throw new \Exception($message);
     }
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 /**
  * @param \PHP\Manipulator\Token $token
  * @return boolean
  */
 public function isQuestionMark(Token $token)
 {
     if ($token->getType() === null && $token->getValue() === '?') {
         return true;
     }
     return false;
 }