Passed
Pull Request — 3.x (#894)
by Anders
08:59 queued 04:44
created

PHPParserVersion84   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
dl 0
loc 39
ccs 0
cts 16
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseOptionalExpressionForVersion() 0 4 2
A parseExpressionVersion84() 0 21 2
1
<?php
2
3
/**
4
 * This file is part of PDepend.
5
 *
6
 * PHP Version 5
7
 *
8
 * Copyright (c) 2025 Oliver Eglseder <[email protected]>.
9
 * All rights reserved.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 *
15
 *   * Redistributions of source code must retain the above copyright
16
 *     notice, this list of conditions and the following disclaimer.
17
 *
18
 *   * Redistributions in binary form must reproduce the above copyright
19
 *     notice, this list of conditions and the following disclaimer in
20
 *     the documentation and/or other materials provided with the
21
 *     distribution.
22
 *
23
 *   * Neither the name of Manuel Pichler nor the names of his
24
 *     contributors may be used to endorse or promote products derived
25
 *     from this software without specific prior written permission.
26
 *
27
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
 * POSSIBILITY OF SUCH DAMAGE.
39
 *
40
 * @copyright 2025 Oliver Eglseder <[email protected]>. All rights reserved.
41
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
42
 *
43
 * @since 3.0
44
 */
45
46
namespace PDepend\Source\Language\PHP;
47
48
use PDepend\Source\AST\ASTNode;
49
use PDepend\Source\Parser\UnexpectedTokenException;
50
use PDepend\Source\Tokenizer\Tokens;
51
52
/**
53
 * Concrete parser implementation that supports features up to PHP version 8.4
54
 *
55
 * @copyright 2025 Oliver Eglseder <[email protected]>. All rights reserved.
56
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
57
 *
58
 * @since 3.0
59
 */
60
abstract class PHPParserVersion84 extends PHPParserVersion83
61
{
62
    /**
63
     * This method will be called when the base parser cannot handle an expression
64
     * in the base version. In this method you can implement version specific
65
     * expressions.
66
     *
67
     * @throws UnexpectedTokenException
68
     */
69
    protected function parseOptionalExpressionForVersion(): ?ASTNode
70
    {
71
        return $this->parseExpressionVersion84()
72
            ?: parent::parseOptionalExpressionForVersion();
73
    }
74
75
    /**
76
     * In this method we implement parsing of PHP 8.4 specific expressions.
77
     */
78
    protected function parseExpressionVersion84(): ?ASTNode
79
    {
80
        $this->consumeComments();
81
        $nextTokenType = $this->tokenizer->peek();
82
83
        switch ($nextTokenType) {
84
            case Tokens::T_OBJECT_OPERATOR:
85
                $token = $this->consumeToken($nextTokenType);
86
87
                $expr = $this->builder->buildAstExpression($token->image);
88
                $expr->configureLinesAndColumns(
89
                    $token->startLine,
90
                    $token->endLine,
91
                    $token->startColumn,
92
                    $token->endColumn
93
                );
94
95
                return $expr;
96
        }
97
98
        return null;
99
    }
100
}
101