示例#1
0
 public function convert(Stmt\Do_ $node)
 {
     $condition = clone $node;
     $collected = $this->assignManipulator->collectAssignInCondition($condition->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     return 'do {' . $this->dispatcher->pStmts($node->stmts) . $collected->getCollected() . "\n" . '} while (' . $this->dispatcher->p($node->cond) . ');';
 }
示例#2
0
 public function convert(Stmt\Do_ $node)
 {
     $condition = clone $node;
     $collected = $this->assignManipulator->collectAssignInCondition($condition->cond);
     $collected = !empty($collected['extracted']) ? "\n" . implode("\n", $collected['extracted']) : '';
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     return 'do {' . $this->dispatcher->pStmts($node->stmts) . $collected . "\n" . '} while (' . $this->dispatcher->p($node->cond) . ');';
 }
示例#3
0
 /**
  * @param Stmt\If_ $node
  *
  * @return string
  */
 public function convert(Stmt\If_ $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     if (empty($node->stmts)) {
         $node->stmts = array(new Stmt\Echo_(array(new Scalar\String("not allowed"))));
         $this->logger->logNode('Empty if not allowed, add "echo not allowed"', $node, $this->dispatcher->getMetadata()->getClass());
     }
     return implode(";\n", $collected['extracted']) . "\n" . 'if ' . $this->dispatcher->p($node->cond) . ' {' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}' . $this->implodeElseIfs($node);
 }
示例#4
0
 /**
  * @param Stmt\If_ $node
  *
  * @return string
  */
 public function convert(Stmt\If_ $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     if (empty($node->stmts)) {
         $node->stmts = array(new Stmt\Echo_(array(new Scalar\String_('not allowed'))));
         $this->logger->logIncompatibility('Empty if', 'Empty if not allowed, add "echo not allowed"', $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     }
     return $collected->getCollected() . 'if ' . $this->dispatcher->p($node->cond) . ' {' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}' . $this->implodeElseIfs($node);
 }
示例#5
0
 /**
  * @param string $name
  * @param string $namespace
  */
 private function createClass($name, $namespace, Expr\Closure $node)
 {
     $class = "namespace {$namespace};\n\nclass {$name}\n{\n";
     foreach ($node->uses as $use) {
         $class .= "    private " . $use->var . ";\n";
     }
     $class .= "\n    public function __construct(" . (!empty($node->uses) ? '' . $this->dispatcher->pCommaSeparated($node->uses) : '') . ")\n    {\n        ";
     foreach ($node->uses as $use) {
         $class .= "        let this->" . $use->var . " = " . $use->var . ";\n";
     }
     $class .= "\n    }\n\n    public function __invoke(" . $this->dispatcher->pCommaSeparated($node->params) . ")\n    {" . $this->dispatcher->pStmts($this->convertUseToMemberAttribute($node->stmts, $node->uses)) . "\n    }\n}\n    ";
     return $class;
 }
 public function convert(Stmt\Class_ $node)
 {
     $this->classManipulator->registerClassImplements($node);
     $node->name = $this->reservedWordReplacer->replace($node->name);
     $addArrayPlusMethod = false;
     foreach ($this->nodeFetcher->foreachNodes($node->stmts) as $stmt) {
         if ($stmt['node'] instanceof AssignOp\Plus && $stmt['node']->expr instanceof Array_) {
             $addArrayPlusMethod = true;
             break;
         }
     }
     return $this->dispatcher->pModifiers($node->type) . 'class ' . $node->name . (null !== $node->extends ? ' extends ' . $this->dispatcher->p($node->extends) : '') . (!empty($node->implements) ? ' implements ' . $this->dispatcher->pCommaSeparated($node->implements) : '') . "\n" . '{' . $this->dispatcher->pStmts($node->stmts) . "\n" . ($addArrayPlusMethod === true ? $this->printArrayPlusMethod() : '') . '}';
 }
 public function convert(Stmt\Interface_ $node)
 {
     $node->name = $this->reservedWordReplacer->replace($node->name);
     $extendsStmt = '';
     if (!empty($node->extends)) {
         $extendsStmt = ' extends ';
         $extends = array();
         foreach ($node->extends as $extend) {
             $extends[] = $this->classManipulator->findRightClass($extend, $this->dispatcher->getMetadata());
         }
         $extendsStmt .= implode(', ', $extends);
     }
     return 'interface ' . $node->name . $extendsStmt . "\n" . '{' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}';
 }
 /**
  * @param Stmt\ClassMethod $node
  *
  * @return string
  */
 public function convert(Stmt\ClassMethod $node)
 {
     $types = $this->typeFinder->getTypes($node, $this->dispatcher->getMetadata());
     foreach ($node->params as $param) {
         if ($param->byRef === true) {
             $this->logger->logIncompatibility('reference', sprintf('Reference not supported in parametter (var "%s")', $param->name), $param, $this->dispatcher->getMetadata()->getClass());
         }
     }
     if ($node->byRef) {
         $this->logger->logIncompatibility('reference', 'Reference not supported', $node, $this->dispatcher->getMetadata()->getClass());
     }
     $this->dispatcher->setLastMethod($node->name);
     $stmt = $this->dispatcher->pModifiers($node->type) . 'function ' . $node->name . '(';
     $varsInMethodSign = array();
     if (isset($types['params']) === true) {
         $params = array();
         foreach ($types['params'] as $type) {
             $varsInMethodSign[] = $type['name'];
             $stringType = $this->printType($type);
             $params[] = (!empty($stringType) ? $stringType . ' ' : '') . '' . $type['name'] . ($type['default'] === null ? '' : ' = ' . $this->dispatcher->p($type['default']));
         }
         $stmt .= implode(', ', $params);
     }
     $stmt .= ')';
     $stmt .= $this->printReturn($node, $types);
     $stmt .= (null !== $node->stmts ? "\n{" . $this->printVars($node, $varsInMethodSign) . $this->dispatcher->pStmts($node->stmts) . "\n}" : ';') . "\n";
     return $stmt;
 }
 /**
  * @param Stmt\ClassMethod $node
  *
  * @return string
  */
 public function convert(Stmt\ClassMethod $node)
 {
     $types = $this->typeFinder->getTypes($node, $this->dispatcher->getMetadata());
     $this->dispatcher->setLastMethod($node->name);
     $stmt = $this->dispatcher->pModifiers($node->type) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(';
     $varsInMethodSign = array();
     if (isset($types['params']) === true) {
         $params = array();
         foreach ($types['params'] as $type) {
             $varsInMethodSign[] = $type['name'];
             $stringType = $this->printType($type);
             $params[] = (!empty($stringType) ? $stringType . ' ' : '') . '' . $type['name'] . ($type['default'] === null ? '' : ' = ' . $this->dispatcher->p($type['default']));
         }
         $stmt .= implode(', ', $params);
     }
     $stmt .= ')';
     $stmt .= $this->printReturn($node, $types);
     $stmt .= (null !== $node->stmts ? "\n{" . $this->printVars($node, $varsInMethodSign) . $this->dispatcher->pStmts($node->stmts) . "\n}" : ';') . "\n";
     return $stmt;
 }
示例#10
0
 /**
  * @param Stmt\While_ $node
  *
  * @return string
  */
 public function convert(Stmt\While_ $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     return implode(";\n", $collected['extracted']) . "\n" . 'while (' . $this->dispatcher->p($node->cond) . ') {' . $this->dispatcher->pStmts($node->stmts) . "\n" . implode(";\n", $collected['extracted']) . "\n" . '}';
 }
 public function convert(Stmt\Class_ $node)
 {
     $node->name = $this->reservedWordReplacer->replace($node->name);
     return $this->dispatcher->pModifiers($node->type) . 'class ' . $node->name . (null !== $node->extends ? ' extends ' . $this->dispatcher->p($node->extends) : '') . (!empty($node->implements) ? ' implements ' . $this->dispatcher->pCommaSeparated($node->implements) : '') . "\n" . '{' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}';
 }
 /**
  * @param Stmt\While_ $node
  *
  * @return string
  */
 public function convert(Stmt\While_ $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     return $collected->getCollected() . 'while (' . $this->dispatcher->p($node->cond) . ') {' . $this->dispatcher->pStmts($node->stmts) . "\n" . $collected->getCollected() . '}';
 }