/** * If $constantToken is the token holding the value of the constant, update the value to $value * * @param Token $constantToken * @param mixed $value */ private function attemptUpdate(Token $constantToken, $value) { $type = $constantToken->getType(); if ($type === T_CONSTANT_ENCAPSED_STRING) { $constantToken->setValue(sprintf("'%s'", $value)); } elseif ($type === T_LNUMBER || $type === T_ARRAY) { $constantToken->setValue($value); } }
/** * @param Token $token * @return bool */ protected function isValidBodyEndToken(Token $token) { if (T_WHITESPACE !== $token->getType()) { return false; } if ($this->linesNum === 0 and strpos($token->getValue(), "\n") === false) { return true; } return $this->linesNum === count(explode("\n", $token->getValue())) - 2; }
/** * @param Token $token * @param string $emptyLines * @return string */ protected function getTokenNewValue(Token $token, $emptyLines) { if ($token->getType() !== T_WHITESPACE) { return $token->getValue() . $emptyLines; } $lines = explode("\n", $token->getValue()); $lineStart = current($lines); $lineEnd = end($lines); return $lineStart . $emptyLines . $lineEnd; }