start = $start; $this->end = $end; $this->insertion_text = $insertion_text; $this->preserve_indentation = $preserve_indentation; } public function getKey() : string { return sha1($this->start . ':' . $this->insertion_text); } public function transform(string $existing_contents) : string { if ($this->preserve_indentation) { $newline_pos = strrpos($existing_contents, "\n", $this->start - strlen($existing_contents)); $newline_pos = $newline_pos !== false ? $newline_pos + 1 : 0; $indentation = substr($existing_contents, $newline_pos, $this->start - $newline_pos); if (trim($indentation) === '') { $this->insertion_text = $this->insertion_text . $indentation; } } return substr($existing_contents, 0, $this->start) . $this->insertion_text . substr($existing_contents, $this->end); } }