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%
4 / 4
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Argument
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 optional
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 variadic
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 convert
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Celema\Console;
6
7use BackedEnum;
8use Celema\Console\Exception\InvalidUsage;
9use ReflectionParameter;
10
11/**
12 * An `#[Arg]` parameter of a command's `__invoke()`.
13 *
14 * @internal
15 */
16final class Argument
17{
18    public readonly string $name;
19
20    public function __construct(
21        public readonly ReflectionParameter $parameter,
22        public readonly Arg $arg,
23        public readonly Type $type,
24    ) {
25        $this->name = Signature::kebab($parameter->getName());
26    }
27
28    public function optional(): bool
29    {
30        return $this->parameter->isDefaultValueAvailable();
31    }
32
33    public function variadic(): bool
34    {
35        return $this->type->name === 'array';
36    }
37
38    public function convert(string $value): string|int|float|BackedEnum
39    {
40        return (
41            $this->type->convert($value)
42                ?? throw new InvalidUsage(
43                    "Argument '<{$this->name}>' expects {$this->type->expected()}, got '{$value}'",
44                )
45        );
46    }
47}

Paths

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

Argument->__construct
21        public readonly ReflectionParameter $parameter,
22        public readonly Arg $arg,
23        public readonly Type $type,
24    ) {
25        $this->name = Signature::kebab($parameter->getName());
26    }
Argument->convert
38    public function convert(string $value): string|int|float|BackedEnum
39    {
40        return (
41            $this->type->convert($value)
42                ?? throw new InvalidUsage(
43                    "Argument '<{$this->name}>' expects {$this->type->expected()}, got '{$value}'",
44                )
45        );
46    }
Argument->optional
30        return $this->parameter->isDefaultValueAvailable();
31    }
Argument->variadic
35        return $this->type->name === 'array';
36    }