Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
12 / 12
60.00% covered (warning)
60.00%
6 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ListArray
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
12 / 12
60.00% covered (warning)
60.00%
6 / 10
100.00% covered (success)
100.00%
2 / 2
10.14
100.00% covered (success)
100.00%
1 / 1
 coerce
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
7 / 7
66.67% covered (warning)
66.67%
4 / 6
100.00% covered (success)
100.00%
1 / 1
4.59
 isEmpty
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
5 / 5
50.00% covered (danger)
50.00%
2 / 4
100.00% covered (success)
100.00%
1 / 1
4.12
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Sire\Coercer;
6
7use Celemas\Sire\Coercion;
8use Celemas\Sire\CoercionMode;
9use Celemas\Sire\Contract;
10use Celemas\Sire\Failure;
11use Override;
12
13/** @api */
14final class ListArray implements Contract\Coercer
15{
16    public string $message {
17        get => '{label} must be a list';
18    }
19
20    #[Override]
21    public function coerce(mixed $pristine, CoercionMode $mode): Contract\Coercion
22    {
23        if (
24            is_array($pristine)
25            && ($pristine === [] || array_keys($pristine) === range(0, count($pristine) - 1))
26        ) {
27            return new Coercion($pristine, $pristine, empty: $pristine === []);
28        }
29
30        return new Coercion(
31            $pristine,
32            $pristine,
33            Failure::invalid(),
34            empty: self::isEmpty($pristine),
35        );
36    }
37
38    private static function isEmpty(mixed $value): bool
39    {
40        return $value === null || $value === '' || $value === [];
41    }
42}

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.

ListArray->$message::get
17        get => '{label} must be a list';
ListArray->coerce
21    public function coerce(mixed $pristine, CoercionMode $mode): Contract\Coercion
22    {
23        if (
24            is_array($pristine)
25            && ($pristine === [] || array_keys($pristine) === range(0, count($pristine) - 1))
25            && ($pristine === [] || array_keys($pristine) === range(0, count($pristine) - 1))
25            && ($pristine === [] || array_keys($pristine) === range(0, count($pristine) - 1))
25            && ($pristine === [] || array_keys($pristine) === range(0, count($pristine) - 1))
27            return new Coercion($pristine, $pristine, empty: $pristine === []);
30        return new Coercion(
31            $pristine,
32            $pristine,
33            Failure::invalid(),
34            empty: self::isEmpty($pristine),
35        );
36    }
ListArray->isEmpty
38    private static function isEmpty(mixed $value): bool
39    {
40        return $value === null || $value === '' || $value === [];
40        return $value === null || $value === '' || $value === [];
40        return $value === null || $value === '' || $value === [];
40        return $value === null || $value === '' || $value === [];
40        return $value === null || $value === '' || $value === [];
41    }