type = $props['type']; $this->filename = $props['filename']; $this->lineNumStart = $props['lineNumStart']; $this->lineNumEnd = $props['lineNumEnd']; $this->comment = $comment ?: null; } /** * Return a friendly error message related to this item. * @param string $desc The error description. * @param ?string $text Optional additional context. * @return string The error message string, including the line number and * filename of this item. */ public function errorMsg( string $desc, ?string $text = null ): string { $start = $this->lineNumStart; $end = $this->lineNumEnd; $lineDesc = $end > $start ? "lines $start-$end" : "line $start"; $fileDesc = $this->filename; // trim path in future? $extraText = $text ? ": $text" : ""; return "$desc on $lineDesc of $fileDesc$extraText"; } /** * Throw an error related to this item. * @param string $desc The error description. * @param ?string $text Optional additional context. * @throws \Error * @return never */ public function error( string $desc, ?string $text = null ) { throw new \Error( $this->errorMsg( $desc, $text ) ); } }