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

jojo1981 / json-ast-builder / 17578687754

09 Sep 2025 09:48AM UTC coverage: 35.019%. Remained the same
17578687754

push

github

jojo1981
Fix: Make compatible with PHP versions: ^8.0|^8.1|^8.2|^8.3|^8.4. Closes #1
https://github.com/jojo1981/json-ast-builder/issues/1

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

290 existing lines in 25 files now uncovered.

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

37.5
/src/Lexer/TokenType.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\Lexer;
13

14
use UnexpectedValueException;
15
use function array_key_exists;
16
use function implode;
17
use function sprintf;
18

19
/**
20
 * @package Jojo1981\JsonAstBuilder\Lexer
21
 */
22
final class TokenType
23
{
24
    /** @var int */
25
    public const TOKEN_EOF = -1;
26

27
    /** @var int */
28
    public const TOKEN_WHITE_SPACE = 1;
29

30
    /** @var int */
31
    public const TOKEN_NEWLINE = 2;
32

33
    /** @var int */
34
    public const TOKEN_INT = 3;
35

36
    /** @var int */
37
    public const TOKEN_NUMBER = 4;
38

39
    /** @var int */
40
    public const TOKEN_STRING = 5;
41

42
    /** @var int */
43
    public const TOKEN_COMMA = 6;
44

45
    /** @var int */
46
    public const TOKEN_COLON = 7;
47

48
    /** @var int */
49
    public const TOKEN_LEFT_SQUARE_BRACKET = 8;
50

51
    /** @var int */
52
    public const TOKEN_RIGHT_SQUARE_BRACKET = 9;
53

54
    /** @var int */
55
    public const TOKEN_LEFT_CURLY_BRACKET = 10;
56

57
    /** @var int */
58
    public const TOKEN_RIGHT_CURLY_BRACKET = 11;
59

60
    /** @var int */
61
    public const TOKEN_KEYWORD = 12;
62

63
    /** @var string[] */
64
    private const TOKEN_NAMES = [
65
        self::TOKEN_EOF => 'EOF',
66
        self::TOKEN_WHITE_SPACE => 'WHITE_SPACE',
67
        self::TOKEN_NEWLINE => 'NEWLINE',
68
        self::TOKEN_INT => 'INT',
69
        self::TOKEN_NUMBER => 'NUMBER',
70
        self::TOKEN_STRING => 'STRING',
71
        self::TOKEN_COMMA => 'COMMA',
72
        self::TOKEN_COLON => 'COLON',
73
        self::TOKEN_LEFT_SQUARE_BRACKET => 'LEFT_SQUARE_BRACKET',
74
        self::TOKEN_RIGHT_SQUARE_BRACKET => 'RIGHT_SQUARE_BRACKET',
75
        self::TOKEN_LEFT_CURLY_BRACKET => 'LEFT_CURLY_BRACKET',
76
        self::TOKEN_RIGHT_CURLY_BRACKET => 'RIGHT_CURLY_BRACKET',
77
        self::TOKEN_KEYWORD => 'KEYWORD'
78
    ];
79

80
    /**
81
     * @param int $tokenType
82
     * @return string
83
     * @throws UnexpectedValueException
84
     */
85
    public static function getLiteral(int $tokenType): string
86
    {
87
        return '<' . self::getNameForTokenType($tokenType) . '(' . $tokenType . ')>';
5✔
88
    }
89

90
    /**
91
     * @param int $tokenType
92
     * @return string
93
     * @throws UnexpectedValueException
94
     */
95
    public static function getNameForTokenType(int $tokenType): string
96
    {
97
        if (!array_key_exists($tokenType, self::TOKEN_NAMES)) {
10✔
NEW
98
            throw new UnexpectedValueException(sprintf(
×
NEW
99
                'Can not get token name for type: %d. The following token types are valid: [%s]',
×
NEW
100
                $tokenType,
×
NEW
101
                implode(', ', self::TOKEN_NAMES)
×
NEW
102
            ));
×
103
        }
104

105
        return self::TOKEN_NAMES[$tokenType];
10✔
106
    }
107
}
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

© 2025 Coveralls, Inc