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

nikic / PHP-Parser / 16402120908

20 Jul 2025 04:50PM UTC coverage: 92.855% (-0.4%) from 93.274%
16402120908

push

github

nikic
Add support for pipe operator

163 of 163 new or added lines in 5 files covered. (100.0%)

36 existing lines in 2 files now uncovered.

7615 of 8201 relevant lines covered (92.85%)

226.34 hits per line

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

50.0
/lib/PhpParser/Lexer/TokenEmulator/PipeOperatorEmulator.php
1
<?php declare(strict_types=1);
2

3
namespace PhpParser\Lexer\TokenEmulator;
4

5
use PhpParser\Lexer\TokenEmulator\TokenEmulator;
6
use PhpParser\PhpVersion;
7
use PhpParser\Token;
8

9
class PipeOperatorEmulator extends TokenEmulator {
10
    public function getPhpVersion(): PhpVersion {
11
        return PhpVersion::fromComponents(8, 5);
1,272✔
12
    }
13

14
    public function isEmulationNeeded(string $code): bool {
15
        return \strpos($code, '|>') !== false;
1,222✔
16
    }
17

18
    public function emulate(string $code, array $tokens): array {
19
        for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
9✔
20
            $token = $tokens[$i];
9✔
21
            if ($token->text === '|' && isset($tokens[$i + 1]) && $tokens[$i + 1]->text === '>') {
9✔
22
                array_splice($tokens, $i, 2, [
8✔
23
                    new Token(\T_PIPE, '|>', $token->line, $token->pos),
8✔
24
                ]);
8✔
25
                $c--;
8✔
26
            }
27
        }
28
        return $tokens;
9✔
29
    }
30

31
    public function reverseEmulate(string $code, array $tokens): array {
UNCOV
32
        for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
×
33
            $token = $tokens[$i];
×
34
            if ($token->id === \T_PIPE) {
×
35
                array_splice($tokens, $i, 1, [
×
36
                    new Token(\ord('|'), '|', $token->line, $token->pos),
×
37
                    new Token(\ord('>'), '>', $token->line, $token->pos + 1),
×
38
                ]);
×
39
                $i++;
×
40
                $c++;
×
41
            }
42
        }
43
        return $tokens;
×
44
    }
45
}
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