/**
  * @param string $parsed_template
  * @return string[]
  */
 public function parse($parsed_template)
 {
     $node = \ast\parse_code($parsed_template);
     $this->walk($node);
     $result = array_unique($this->includes);
     sort($result);
     return $result;
 }
Example #2
0
 public function testClassContext()
 {
     $code = "<?php\n            class C {\n                private function f() {\n                    return 42;\n                }\n            }";
     $stmt_list_node = \ast\parse_code($code, Config::get()->ast_version);
     $class_node = $stmt_list_node->children[0];
     $context = new Context();
     $context = (new ParseVisitor($this->code_base, $context))($class_node);
     $stmt_list_node = $class_node->children['stmts'];
     $method_node = $stmt_list_node->children[0];
     $context = (new ParseVisitor($this->code_base, $context))($method_node);
 }
Example #3
0
 /**
  * @return string
  * A string representation of the union type begotten from
  * the first statement in the statement list in the given
  * code.
  */
 private function typeStringFromCode(string $code) : string
 {
     return UnionType::fromNode($this->context, $this->code_base, \ast\parse_code($code, Config::get()->ast_version)->children[0])->asExpandedTypes($this->code_base)->__toString();
 }
Example #4
0
 /**
  * Get a Context after parsing the given
  * bit of code.
  */
 private function contextForCode(string $code_stub) : Context
 {
     return Analysis::parseNodeInContext($this->code_base, new Context(), \ast\parse_code('<?php ' . $code_stub, Config::get()->ast_version));
 }
Example #5
0
 /**
  * Get a Context after parsing the given
  * bit of code.
  */
 private function contextForCode(string $code_stub) : Context
 {
     return (new Phan())->parseNodeInContext(\ast\parse_code('<?php ' . $code_stub, Config::get()->ast_version), new Context(), $this->code_base);
 }