Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Fragment
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 error
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getText
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * @author Niklas Laxström, Tim Starling
4 * @license GPL-2.0-or-later
5 * @file
6 */
7
8namespace CLDRPluralRuleParser\Converter;
9
10use CLDRPluralRuleParser\Converter;
11use CLDRPluralRuleParser\Error;
12
13/**
14 * Helper for Converter.
15 * The base class for operators and expressions, describing a region of the input string.
16 */
17class Fragment {
18    /**
19     * @var Converter
20     */
21    public $parser;
22
23    /**
24     * @var int
25     */
26    public $pos;
27
28    /**
29     * @var int
30     */
31    public $length;
32
33    /**
34     * @var int
35     */
36    public $end;
37
38    /**
39     * @param Converter $parser
40     * @param int $pos
41     * @param int $length
42     */
43    public function __construct( Converter $parser, $pos, $length ) {
44        $this->parser = $parser;
45        $this->pos = $pos;
46        $this->length = $length;
47        $this->end = $pos + $length;
48    }
49
50    /**
51     * @param string $message
52     *
53     * @throws Error
54     * @return never
55     */
56    public function error( $message ) {
57        $text = $this->getText();
58        throw new Error( "$message at position " . ( $this->pos + 1 ) . ": \"$text\"" );
59    }
60
61    /**
62     * @return string
63     */
64    public function getText() {
65        return substr( $this->parser->rule, $this->pos, $this->length );
66    }
67}