Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
11 / 11
57.14% covered (warning)
57.14%
4 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Arguments
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
11 / 11
57.14% covered (warning)
57.14%
4 / 7
100.00% covered (success)
100.00%
2 / 2
6.97
100.00% covered (success)
100.00%
1 / 1
 named
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
4 / 4
33.33% covered (danger)
33.33%
1 / 3
100.00% covered (success)
100.00%
1 / 1
3.19
 keyed
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
7 / 7
75.00% covered (warning)
75.00%
3 / 4
100.00% covered (success)
100.00%
1 / 1
3.14
1<?php
2
3declare(strict_types=1);
4
5namespace Celema\Sire;
6
7/** @internal */
8final class Arguments
9{
10    /**
11     * Gives rule arguments the names their rule declares, by position.
12     *
13     * @param list<string> $args
14     * @return array<array-key, string>
15     */
16    public static function named(array $args, Contract\NamedArguments $rule): array
17    {
18        $names = $rule->arguments;
19        $named = [];
20
21        foreach ($args as $index => $arg) {
22            $named[$names[$index] ?? $index] = $arg;
23        }
24
25        return $named;
26    }
27
28    /**
29     * Placeholder names: a named argument keeps its name, a positional one
30     * becomes `argN` by its position.
31     *
32     * @template T
33     * @param array<array-key, T> $args
34     * @return array<string, T>
35     */
36    public static function keyed(array $args): array
37    {
38        $keyed = [];
39
40        foreach ($args as $key => $arg) {
41            $keyed[is_int($key) ? 'arg' . ($key + 1) : $key] = $arg;
42        }
43
44        return $keyed;
45    }
46}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

Arguments->keyed
36    public static function keyed(array $args): array
37    {
38        $keyed = [];
39
40        foreach ($args as $key => $arg) {
40        foreach ($args as $key => $arg) {
40        foreach ($args as $key => $arg) {
41            $keyed[is_int($key) ? 'arg' . ($key + 1) : $key] = $arg;
41            $keyed[is_int($key) ? 'arg' . ($key + 1) : $key] = $arg;
41            $keyed[is_int($key) ? 'arg' . ($key + 1) : $key] = $arg;
40        foreach ($args as $key => $arg) {
41            $keyed[is_int($key) ? 'arg' . ($key + 1) : $key] = $arg;
40        foreach ($args as $key => $arg) {
41            $keyed[is_int($key) ? 'arg' . ($key + 1) : $key] = $arg;
42        }
43
44        return $keyed;
45    }
Arguments->named
16    public static function named(array $args, Contract\NamedArguments $rule): array
17    {
18        $names = $rule->arguments;
19        $named = [];
20
21        foreach ($args as $index => $arg) {
21        foreach ($args as $index => $arg) {
21        foreach ($args as $index => $arg) {
21        foreach ($args as $index => $arg) {
22            $named[$names[$index] ?? $index] = $arg;
23        }
24
25        return $named;
26    }