aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/scssphp/source-span/src/SourceLocationMixin.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/scssphp/source-span/src/SourceLocationMixin.php')
-rw-r--r--vendor/scssphp/source-span/src/SourceLocationMixin.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/scssphp/source-span/src/SourceLocationMixin.php b/vendor/scssphp/source-span/src/SourceLocationMixin.php
new file mode 100644
index 000000000..1649a3d1d
--- /dev/null
+++ b/vendor/scssphp/source-span/src/SourceLocationMixin.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace SourceSpan;
+
+/**
+ * A mixin for easily implementing {@see SourceLocation}.
+ *
+ * @internal
+ */
+abstract class SourceLocationMixin implements SourceLocation
+{
+ public function distance(SourceLocation $other): int
+ {
+ if (!Util::isSameUrl($this->getSourceUrl(), $other->getSourceUrl())) {
+ throw new \InvalidArgumentException("Source URLs \"{$this->getSourceUrl()}\" and \"{$other->getSourceUrl()}\" don't match.");
+ }
+
+ return abs($this->getOffset() - $other->getOffset());
+ }
+
+ public function pointSpan(): SourceSpan
+ {
+ return new SimpleSourceSpan($this, $this, '');
+ }
+
+ public function compareTo(SourceLocation $other): int
+ {
+ if (!Util::isSameUrl($this->getSourceUrl(), $other->getSourceUrl())) {
+ throw new \InvalidArgumentException("Source URLs \"{$this->getSourceUrl()}\" and \"{$other->getSourceUrl()}\" don't match.");
+ }
+
+ return $this->getOffset() - $other->getOffset();
+ }
+}