• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jojo1981 / json-ast-builder / 17578743546

09 Sep 2025 09:50AM UTC coverage: 35.019%. First build
17578743546

push

github

web-flow
Merge pull request #2 from jojo1981/feature/upgrade-php-versions

Fix: Make compatible with PHP versions: ^8.0|^8.1|^8.2|^8.3|^8.4

161 of 407 new or added lines in 17 files covered. (39.56%)

374 of 1068 relevant lines covered (35.02%)

3.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Exception/ParseException.php
1
<?php
2
/*
3
 * This file is part of the jojo1981/json-ast-builder package
4
 *
5
 * Copyright (c) 2019 Joost Nijhuis <jnijhuis81@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed in the root of the source code
9
 */
10
declare(strict_types=1);
11

12
namespace Jojo1981\JsonAstBuilder\Exception;
13

14
use Jojo1981\JsonAstBuilder\Lexer\Token;
15
use function count;
16
use function implode;
17
use function sprintf;
18

19
/**
20
 * @package Jojo1981\JsonAstBuilder\Exception
21
 */
22
final class ParseException extends JsonException
23
{
24
    /**
25
     * @param string $char
26
     * @param int $position
27
     * @param int $lineNumber
28
     * @param int $linePosition
29
     * @return ParseException
30
     */
31
    public static function unknownCharacterFound(
32
        string $char,
33
        int $position,
34
        int $lineNumber,
35
        int $linePosition
36
    ): ParseException {
NEW
37
        return new self(sprintf(
×
38
            'Unknown character: `%s` found at position: %d [%d:%d].',
×
39
            $char,
×
40
            $position,
×
41
            $lineNumber,
×
42
            $linePosition
×
43
        ));
×
44
    }
45

46
    /**
47
     * @param int $position
48
     * @param int $lineNumber
49
     * @param int $linePosition
50
     * @return ParseException
51
     */
52
    public static function unexpectedEndOfFileFound(int $position, int $lineNumber, int $linePosition): ParseException
53
    {
NEW
54
        return new self(sprintf(
×
55
            'Unexpected end of file reached at position: %d [%d:%d]',
×
56
            $position,
×
57
            $lineNumber,
×
58
            $linePosition
×
59
        ));
×
60
    }
61

62
    /**
63
     * @return ParseException
64
     */
65
    public static function invalidInput(): ParseException
66
    {
NEW
67
        return new self('Empty input given which is invalid json content');
×
68
    }
69

70
    /**
71
     * @param string $chars
72
     * @param int $position
73
     * @param int $lineNumber
74
     * @param int $linePosition
75
     * @param string $expectedKeyWord
76
     * @return ParseException
77
     */
78
    public static function invalidKeywordFound(
79
        string $chars,
80
        int $position,
81
        int $lineNumber,
82
        int $linePosition,
83
        string $expectedKeyWord
84
    ): ParseException {
NEW
85
        return new self(sprintf(
×
86
            'Invalid characters: `%s` found at position: %d [%d:%d]. Did you mean: `%s`?',
×
87
            $chars,
×
88
            $position,
×
89
            $lineNumber,
×
90
            $linePosition,
×
91
            $expectedKeyWord
×
92
        ));
×
93
    }
94

95
    /**
96
     * @param int $position
97
     * @param int $lineNumber
98
     * @param int $linePosition
99
     * @return ParseException
100
     */
101
    public static function unterminatedStringFound(int $position, int $lineNumber, int $linePosition): ParseException
102
    {
NEW
103
        return new self(sprintf(
×
104
            'Unterminated string found at position: %d [%d:%d]',
×
105
            $position,
×
106
            $lineNumber,
×
107
            $linePosition
×
108
        ));
×
109
    }
110

111
    /**
112
     * @param int $position
113
     * @param int $lineNumber
114
     * @param int $linePosition
115
     * @param string $char
116
     * @return ParseException
117
     */
118
    public static function illegalCharacterInStringFound(int $position, int $lineNumber, int $linePosition, string $char): ParseException
119
    {
NEW
120
        return new self(sprintf(
×
121
            'Illegal character in string found: %s at position: %d [%d:%d]',
×
122
            ord($char) < 32 ? ord($char) : $char,
×
123
            $position,
×
124
            $lineNumber,
×
125
            $linePosition
×
126
        ));
×
127
    }
128

129
    /**
130
     * @param int $position
131
     * @param int $lineNumber
132
     * @param int $linePosition
133
     * @return ParseException
134
     */
135
    public static function illegalEscapeUsed(int $position, int $lineNumber, int $linePosition): ParseException
136
    {
NEW
137
        return new self(sprintf(
×
138
            'Illegal escape in string used at position: %d [%d:%d]',
×
139
            $position,
×
140
            $lineNumber,
×
141
            $linePosition
×
142
        ));
×
143
    }
144

145
    /**
146
     * @param int $position
147
     * @param int $lineNumber
148
     * @param int $linePosition
149
     * @param string $char
150
     * @return ParseException
151
     */
152
    public static function illegalOctalLiteral(int $position, int $lineNumber, int $linePosition, string $char): ParseException
153
    {
NEW
154
        return new self(sprintf(
×
155
            'Illegal octal literal: %s at position: %d [%d:%d]',
×
156
            $char,
×
157
            $position,
×
158
            $lineNumber,
×
159
            $linePosition
×
160
        ));
×
161
    }
162

163
    /**
164
     * @param int $position
165
     * @param int $lineNumber
166
     * @param int $linePosition
167
     * @return ParseException
168
     */
169
    public static function illegalTrailingDecimal(int $position, int $lineNumber, int $linePosition): ParseException
170
    {
NEW
171
        return new self(sprintf(
×
172
            'Illegal trailing decimal at position: %d [%d:%d], a decimal point must be followed with ath least 1 digit',
×
173
            $position,
×
174
            $lineNumber,
×
175
            $linePosition
×
176
        ));
×
177
    }
178

179
    /**
180
     * @param int $position
181
     * @param int $lineNumber
182
     * @param int $linePosition
183
     * @return ParseException
184
     */
185
    public static function illegalNegativeSign(int $position, int $lineNumber, int $linePosition): ParseException
186
    {
NEW
187
        return new self(sprintf(
×
188
            'Illegal negative sign at position: %d [%d:%d], a negative sign may only precede numbers.',
×
189
            $position,
×
190
            $lineNumber,
×
191
            $linePosition
×
192
        ));
×
193
    }
194

195
    /**
196
     * @param int $position
197
     * @param int $lineNumber
198
     * @param int $linePosition
199
     * @return ParseException
200
     */
201
    public static function illegalEmptyExponent(int $position, int $lineNumber, int $linePosition): ParseException
202
    {
NEW
203
        return new self(sprintf(
×
204
            'Illegal empty exponent at position: %d [%d:%d], an exponent must be followed with ath least 1 digit.',
×
205
            $position,
×
206
            $lineNumber,
×
207
            $linePosition
×
208
        ));
×
209
    }
210

211
    /**
212
     * @param Token $currentToken
213
     * @param string[] $expectedTokens
214
     * @return ParseException
215
     */
216
    public static function unexpectedEndOfFile(Token $currentToken, array $expectedTokens): ParseException
217
    {
NEW
218
        $plural = count($expectedTokens) > 1;
×
219

NEW
220
        return new self(sprintf(
×
221
            'Unexpected EOF found. Last seen token: `%s`. Expected token %s: %s',
×
222
            $currentToken->getName(),
×
223
            $plural ? 'to be one of' : 'to be',
×
NEW
224
            $plural ? '[' . implode(', ', $expectedTokens) . ']' : $expectedTokens
×
225
        ));
×
226
    }
227

228
    /**
229
     * @param Token $currentToken
230
     * @param string[] $expectedTokens
231
     * @return ParseException
232
     */
233
    public static function unexpectedToken(Token $currentToken, array $expectedTokens): ParseException
234
    {
NEW
235
        $plural = count($expectedTokens) > 1;
×
236

NEW
237
        return new self(sprintf(
×
238
            'Unexpected token: `%s` found. Expected token %s: [%s]',
×
239
            $currentToken->getName(),
×
240
            $plural ? 'to be one of' : 'to be',
×
NEW
241
            $plural ? '[' . implode(', ', $expectedTokens) . ']' : $expectedTokens
×
242
        ));
×
243
    }
244

245
    /**
246
     * @param Token $commaToken
247
     * @return ParseException
248
     */
249
    public static function illegalTrailingComma(Token $commaToken): ParseException
250
    {
NEW
251
        return new self(sprintf(
×
252
            'Illegal trailing comma found at position: %d [%d:%d]',
×
253
            $commaToken->getPosition(),
×
254
            $commaToken->getLineNumber(),
×
255
            $commaToken->getLinePosition()
×
256
        ));
×
257
    }
258
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc