/**
  * Remove unneded ?> from the file-end
  *
  * @param \PHP\Manipulator\TokenContainer $container
  * @param mixed $params
  */
 public function run(TokenContainer $container)
 {
     $stripWhitespaceFromEnd = $this->getOption('stripWhitespaceFromEnd');
     $iterator = $container->getReverseIterator();
     $helper = new NewlineDetector("\n");
     while ($iterator->valid()) {
         $token = $iterator->current();
         if (!$this->_isNotAllowedTag($token)) {
             break;
         } elseif ($this->isType($token, T_CLOSE_TAG)) {
             if ($this->evaluateConstraint('EndsWithNewline', $token)) {
                 $newline = $helper->getNewlineFromToken($token);
                 $token->setType(T_WHITESPACE);
                 $token->setValue($newline);
             } else {
                 $container->removeToken($token);
             }
             break;
         }
         $iterator->next();
     }
     $container->retokenize();
     if (true === $stripWhitespaceFromEnd) {
         $this->runAction('RemoveWhitespaceFromEnd', $container);
     }
 }
 /**
  * @param \PHP\Manipulator\Token $token
  * @param mixed $params (unused)
  */
 public function manipulate(Token $token, $params = null)
 {
     $helper = new NewlineDetector();
     $newline = $helper->getNewlineFromToken($token);
     $lines = new ArrayObject(preg_split('~(\\r\\n|\\r|\\n)~', $token->getValue()));
     if (count($lines) >= 3) {
         // delete empty lines from begin
         $this->_iterateLines($lines);
         // delete empty lines from end
         $lines = new ArrayObject(array_reverse($lines->getArrayCopy()));
         $this->_iterateLines($lines);
         $token->setValue(implode($newline, array_reverse($lines->getArrayCopy())));
     }
 }
 /**
  * @param \PHP\Manipulator\Token $token
  * @param mixed $params
  */
 public function manipulate(Token $token, $params = null)
 {
     if (!$this->evaluateConstraint('IsMultilineComment', $token)) {
         throw new \Exception('Token is no Multiline-comment');
     }
     $this->manipulateToken('RemoveCommentIndention', $token);
     $value = preg_split('~(\\r\\n|\\n|\\r)~', $token->getValue());
     $newValue = '';
     $helper = new NewlineDetector();
     $newline = $helper->getNewlineFromToken($token);
     foreach ($value as $line) {
         // removes */ and * and /** and /**
         $newValue .= '//' . preg_replace('~^(\\*\\/|\\*|\\/\\*\\*|\\/\\*){1,}(.*?)$~', '\\2', $line) . $newline;
     }
     $token->setType(T_COMMENT);
     $token->setValue($newValue);
 }
 /**
  * Manipulate Token
  *
  * @param \PHP\Manipulator\Token $token
  * @param mixed $params
  */
 public function manipulate(Token $token, $params = null)
 {
     $regexNewline = '(\\n|\\r\\n|\\r)';
     $indention = $params;
     $value = $token->getValue();
     $lines = preg_split('~' . $regexNewline . '~', $value);
     $helper = new NewlineDetector();
     $newline = $helper->getNewlineFromToken($token);
     $first = true;
     $value = '';
     foreach ($lines as $key => $line) {
         if ($first) {
             $first = false;
         } else {
             $temp = trim($line);
             if (!empty($temp)) {
                 $lines[$key] = $indention . ' ' . $line;
             }
         }
     }
     $token->setValue(implode($newline, $lines));
 }
 /**
  * @dataProvider tokenProvider
  * @covers \PHP\Manipulator\Helper\NewlineDetector::getNewlineFromToken
  * @covers \PHP\Manipulator\Helper\NewlineDetector::<protected>
  */
 public function testGetNewlineFromToken($token, $defaultNewline, $expectedNewline)
 {
     $detector = new NewlineDetector($defaultNewline);
     $actualNewline = $detector->getNewlineFromToken($token);
     $this->assertEquals($expectedNewline, $actualNewline);
 }