key = new SourceRange( $keyStart, $keyEnd ); $this->value = new SourceRange( $valueStart, $valueEnd ); } /** * Return a new key-value source offset range shifted by $amount. * @param int $amount The amount to shift by * @return KVSourceRange */ public function offset( int $amount ): KVSourceRange { return new KVSourceRange( $this->key->start + $amount, $this->key->end + $amount, $this->value->start + $amount, $this->value->end + $amount ); } /** * Create a new key-value source offset range from an array of * integers (such as created during JSON serialization). * @param int[] $so * @return KVSourceRange */ public static function fromArray( array $so ): KVSourceRange { Assert::invariant( count( $so ) === 4, 'Not enough elements in KVSourceRange array' ); return new KVSourceRange( $so[0], $so[1], $so[2], $so[3] ); } /** * @inheritDoc */ public function jsonSerialize(): array { return [ $this->key->start, $this->key->end, $this->value->start, $this->value->end, ]; } }