Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute(File $file, $pointer)
 {
     $openCurlyBrackets = $file->findNext(T_OPEN_CURLY_BRACKET, $pointer);
     $closeParenthesis = $file->findNext(T_CLOSE_PARENTHESIS, $pointer);
     $file->fixer->beginChangeset();
     foreach ($file->findAllBetween([T_STRING, T_COLON], $closeParenthesis, $openCurlyBrackets) as $token) {
         $file->fixer->replaceToken($token, '');
     }
     $file->fixer->endChangeset();
     return $file->fixer->getContents();
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function execute(File $file, $pointer)
 {
     $openParenthesis = $file->findNext(T_OPEN_PARENTHESIS, $pointer);
     $closeParenthesis = $file->findNext(T_CLOSE_PARENTHESIS, $pointer);
     $variables = $file->findAllBetween(T_VARIABLE, $openParenthesis, $closeParenthesis);
     $file->fixer->beginChangeset();
     foreach ($variables as $variable) {
         $typeHint = $file->findPrevious(T_STRING, $variable, $openParenthesis);
         if (!$typeHint) {
             continue;
         }
         $file->fixer->replaceToken($typeHint, '');
         $file->fixer->replaceToken($typeHint + 1, '');
     }
     $file->fixer->endChangeset();
     return $file->fixer->getContents();
 }
Exemplo n.º 3
0
 /**
  * @param  File
  * @return bool if file was changed
  */
 public function transpile(File $file)
 {
     $oldSource = $source = file_get_contents($file->getFilename());
     foreach ($file->getTokens() as $key => $token) {
         if (isset($this->listeners[$token['code']])) {
             /** @var Rule $rule */
             foreach ($this->listeners[$token['code']] as $rule) {
                 $source = $rule->execute($file, $key);
             }
         }
     }
     if ($oldSource !== $source) {
         $this->writer->writeFile($file->getFilename(), $source);
         return TRUE;
     } else {
         $this->writer->writeFile($file->getFilename(), $oldSource);
         return FALSE;
     }
 }