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

nikic / PHP-Parser / 21443740219

28 Jan 2026 03:12PM UTC coverage: 92.543% (-0.01%) from 92.553%
21443740219

Pull #1138

github

web-flow
Merge ce4e824d4 into 8c360e273
Pull Request #1138: Remove assert() on CallLike::getArgs(), returns empty array on first class callable

1 of 2 new or added lines in 1 file covered. (50.0%)

7707 of 8328 relevant lines covered (92.54%)

227.14 hits per line

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

92.86
/lib/PhpParser/Node/Expr/CallLike.php
1
<?php declare(strict_types=1);
2

3
namespace PhpParser\Node\Expr;
4

5
use PhpParser\Node\Arg;
6
use PhpParser\Node\Expr;
7
use PhpParser\Node\VariadicPlaceholder;
8

9
abstract class CallLike extends Expr {
10
    /**
11
     * Return raw arguments, which may be actual Args, or VariadicPlaceholders for first-class
12
     * callables.
13
     *
14
     * @return array<Arg|VariadicPlaceholder>
15
     */
16
    abstract public function getRawArgs(): array;
17

18
    /**
19
     * Returns whether this call expression is actually a first class callable.
20
     */
21
    public function isFirstClassCallable(): bool {
22
        $rawArgs = $this->getRawArgs();
50✔
23
        return count($rawArgs) === 1 && current($rawArgs) instanceof VariadicPlaceholder;
50✔
24
    }
25

26
    /**
27
     * Return only ordinary Args.
28
     *
29
     * @return Arg[]
30
     */
31
    public function getArgs(): array {
32
        if ($this->isFirstClassCallable()) {
5✔
NEW
33
            return [];
×
34
        }
35
        return $this->getRawArgs();
5✔
36
    }
37

38
    /**
39
     * Retrieves a specific argument from the raw arguments.
40
     *
41
     * Returns the named argument that matches the given `$name`, or the
42
     * positional (unnamed) argument that exists at the given `$position`,
43
     * otherwise, returns `null` for first-class callables or if no match is found.
44
     */
45
    public function getArg(string $name, int $position): ?Arg {
46
        if ($this->isFirstClassCallable()) {
40✔
47
            return null;
5✔
48
        }
49
        foreach ($this->getRawArgs() as $i => $arg) {
35✔
50
            if ($arg->unpack) {
35✔
51
                continue;
5✔
52
            }
53
            if (
54
                ($arg->name !== null && $arg->name->toString() === $name)
35✔
55
                || ($arg->name === null && $i === $position)
35✔
56
            ) {
57
                return $arg;
20✔
58
            }
59
        }
60
        return null;
15✔
61
    }
62
}
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