Passed
Push — feature/second-release ( dba095...aa282f )
by Andrea Marco
02:34
created

OnCall   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LaravelEnum\Actions;
6
7
use Cerbero\LaravelEnum\Enums;
8
use Illuminate\Support\Facades\App;
9
use Illuminate\Support\Facades\Lang;
10
use Throwable;
11
use UnitEnum;
12
13
/**
14
 * The logic to handle an inaccessible case method call.
15
 */
16
class OnCall
17
{
18
    /**
19
     * Handle the call to an inaccessible case method.
20
     *
21
     * @param array<array-key, mixed> $arguments
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, mixed> at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, mixed>.
Loading history...
22
     * @throws \ValueError
23
     */
24 6
    public function __invoke(object $case, string $name, array $arguments): mixed
25
    {
26
        try {
27
            /** @phpstan-ignore method.notFound */
28 6
            $value = $case->resolveMetaAttribute($name);
29 4
        } catch (Throwable $e) {
30
            /** @var UnitEnum $case */
31 4
            $key = Enums::resolveTranslationKey($case, $name);
32
33
            /** @var array{array<string, mixed>, ?string, bool} $arguments */
34 4
            return ($key === $translation = Lang::get($key, ...$arguments)) ? throw $e : $translation;
35
        }
36
37 2
        return is_string($value) && method_exists($value, '__invoke')
38 2
            ? call_user_func_array(App::make($value), $arguments) /** @phpstan-ignore argument.type */
39 2
            : $value;
40
    }
41
}
42