/** * @return string */ public function render() { $classes = $this->sourceFile->getClasses(); $classOutput = array(); foreach ($classes as $class) { $classOutput[] = (new PhpClassView($class))->render(); } return ' Analyzing ' . count($classes) . " classes in " . $this->sourceFile->getPath() . ":\n" . join("\n", $classOutput); }
public function fix() { $tokens = $this->sourceFile->sourceTree(); $fixes = $this->requireUses(); $positions = array_keys($fixes); $slices = array(); $offset = 0; if ((bool) $fixes === true) { while ((bool) $positions) { $length = array_shift($positions) - $offset; $slices[] = array_slice($tokens, $offset, $length); $slices[] = array_slice($tokens, $offset + 1 + $length); $offset += $length; } $res = array(); while ($fixes) { $res = array_merge($res, array_shift($slices)); $res = array_merge($res, array_shift($fixes)->sourceTree()); $res = array_merge($res, array_shift($slices)); } $this->sourceFile->setStringContent($this->nodesToSource($res)); } return $this->sourceFile; }