diff --git a/src/PhpDocument.php b/src/PhpDocument.php index 7820701..ff3cf8b 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -46,13 +46,6 @@ class PhpDocument */ private $uri; - /** - * The content of the document - * - * @var string - */ - private $content; - /** * The AST of the document * @@ -133,8 +126,6 @@ class PhpDocument */ public function updateContent(string $content) { - $this->content = $content; - // Unregister old definitions if (isset($this->definitions)) { foreach ($this->definitions as $fqn => $definition) { @@ -182,10 +173,10 @@ class PhpDocument */ public function getFormattedText() { - if (empty($this->content)) { + if (empty($this->getContent())) { return []; } - return Formatter::format($this->content, $this->uri); + return Formatter::format($this->getContent(), $this->uri); } /** @@ -195,7 +186,7 @@ class PhpDocument */ public function getContent() { - return $this->content; + return $this->sourceFileNode->fileContents; } /** @@ -256,12 +247,10 @@ class PhpDocument */ public function getRange(Range $range) { - if ($this->content === null) { - return null; - } - $start = $range->start->toOffset($this->content); - $length = $range->end->toOffset($this->content) - $start; - return substr($this->content, $start, $length); + $content = $this->getContent(); + $start = $range->start->toOffset($content); + $length = $range->end->toOffset($content) - $start; + return substr($content, $start, $length); } /** diff --git a/src/TreeAnalyzer.php b/src/TreeAnalyzer.php index 3296ae8..2e34aa6 100644 --- a/src/TreeAnalyzer.php +++ b/src/TreeAnalyzer.php @@ -45,7 +45,6 @@ class TreeAnalyzer $this->parser = $parser; $this->docBlockFactory = $docBlockFactory; $this->definitionResolver = $definitionResolver; - $this->content = $content; $this->sourceFileNode = $this->parser->parseSourceFile($content, $uri); // TODO - docblock errors @@ -76,7 +75,7 @@ class TreeAnalyzer } if (($error = PhpParser\DiagnosticsProvider::checkDiagnostics($node)) !== null) { - $range = PhpParser\PositionUtilities::getRangeFromPosition($error->start, $error->length, $this->content); + $range = PhpParser\PositionUtilities::getRangeFromPosition($error->start, $error->length, $this->sourceFileNode->fileContents); $this->diagnostics[] = new Diagnostic( $error->message,