1
0
Fork 0

Remove content (#413)

pull/415/head v4.5.0
Felix Becker 2017-06-16 20:31:29 +02:00 committed by GitHub
parent 0e3727a8d6
commit a772d9a2d7
2 changed files with 8 additions and 20 deletions

View File

@ -46,13 +46,6 @@ class PhpDocument
*/ */
private $uri; private $uri;
/**
* The content of the document
*
* @var string
*/
private $content;
/** /**
* The AST of the document * The AST of the document
* *
@ -133,8 +126,6 @@ class PhpDocument
*/ */
public function updateContent(string $content) public function updateContent(string $content)
{ {
$this->content = $content;
// Unregister old definitions // Unregister old definitions
if (isset($this->definitions)) { if (isset($this->definitions)) {
foreach ($this->definitions as $fqn => $definition) { foreach ($this->definitions as $fqn => $definition) {
@ -182,10 +173,10 @@ class PhpDocument
*/ */
public function getFormattedText() public function getFormattedText()
{ {
if (empty($this->content)) { if (empty($this->getContent())) {
return []; return [];
} }
return Formatter::format($this->content, $this->uri); return Formatter::format($this->getContent(), $this->uri);
} }
/** /**
@ -195,7 +186,7 @@ class PhpDocument
*/ */
public function getContent() public function getContent()
{ {
return $this->content; return $this->sourceFileNode->fileContents;
} }
/** /**
@ -256,12 +247,10 @@ class PhpDocument
*/ */
public function getRange(Range $range) public function getRange(Range $range)
{ {
if ($this->content === null) { $content = $this->getContent();
return null; $start = $range->start->toOffset($content);
} $length = $range->end->toOffset($content) - $start;
$start = $range->start->toOffset($this->content); return substr($content, $start, $length);
$length = $range->end->toOffset($this->content) - $start;
return substr($this->content, $start, $length);
} }
/** /**

View File

@ -45,7 +45,6 @@ class TreeAnalyzer
$this->parser = $parser; $this->parser = $parser;
$this->docBlockFactory = $docBlockFactory; $this->docBlockFactory = $docBlockFactory;
$this->definitionResolver = $definitionResolver; $this->definitionResolver = $definitionResolver;
$this->content = $content;
$this->sourceFileNode = $this->parser->parseSourceFile($content, $uri); $this->sourceFileNode = $this->parser->parseSourceFile($content, $uri);
// TODO - docblock errors // TODO - docblock errors
@ -76,7 +75,7 @@ class TreeAnalyzer
} }
if (($error = PhpParser\DiagnosticsProvider::checkDiagnostics($node)) !== null) { 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( $this->diagnostics[] = new Diagnostic(
$error->message, $error->message,