Passed
Push — develop ( 9b8c4e...79e7ae )
by Andrea Marco
03:34 queued 14s
created

Enums   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 8
c 4
b 0
f 0
dl 0
loc 44
ccs 8
cts 8
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A translateFrom() 0 3 1
A resolveTranslationKey() 0 5 3
A handleCall() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LaravelEnum;
6
7
use Cerbero\Enum\Enums as BaseEnums;
8
use Cerbero\LaravelEnum\Actions\OnCall;
9
use Closure;
10
use UnitEnum;
0 ignored issues
show
Bug introduced by
The type UnitEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * The enums manager.
14
 */
15
final class Enums extends BaseEnums
16
{
17
    /**
18
     * The logic to resolve the translation key.
19
     *
20
     * @var ?Closure(UnitEnum $case, string $method): string
21
     */
22
    protected static ?Closure $translateFrom = null;
23
24
    /**
25
     * The glob paths to find enums in.
26
     *
27
     * @var string[]
28
     */
29
    protected static array $paths = ['app/Enums'];
30
31
    /**
32
     * Handle the call to an inaccessible case method.
33
     *
34
     * @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...
35
     */
36 10
    public static function handleCall(UnitEnum $case, string $name, array $arguments): mixed
37
    {
38 10
        return (static::$onCall ?: new OnCall())($case, $name, $arguments);
39
    }
40
41
    /**
42
     * Set the logic to resolve the translation key.
43
     *
44
     * @param callable(UnitEnum $case, string $method): string $callback
45
     */
46 1
    public static function translateFrom(callable $callback): void
47
    {
48 1
        static::$translateFrom = $callback(...);
49
    }
50
51
    /**
52
     * Retrieve the translation key for the given case.
53
     */
54 6
    public static function resolveTranslationKey(UnitEnum $case, ?string $method = null): string
55
    {
56 6
        return static::$translateFrom
57 1
            ? (static::$translateFrom)($case, (string) $method)
58 6
            : sprintf('enums.%s.%s%s', $case::class, $case->name, $method ? ".{$method}" : '');
59
    }
60
}
61