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 InvalidArgumentException; |
11
|
|
|
use Throwable; |
12
|
|
|
use UnitEnum; |
|
|
|
|
13
|
|
|
|
14
|
|
|
use function Cerbero\LaravelEnum\namespaceExists; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The logic to handle an inaccessible case method call. |
18
|
|
|
*/ |
19
|
|
|
class OnCall |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Handle the call to an inaccessible case method. |
23
|
|
|
* |
24
|
|
|
* @param array<array-key, mixed> $arguments |
|
|
|
|
25
|
|
|
* @throws InvalidArgumentException |
26
|
|
|
* @throws \ValueError |
27
|
|
|
*/ |
28
|
9 |
|
public function __invoke(UnitEnum $case, string $name, array $arguments): mixed |
29
|
|
|
{ |
30
|
|
|
try { |
31
|
9 |
|
$value = $case->resolveMetaAttribute($name); |
32
|
5 |
|
} catch (Throwable $e) { |
33
|
5 |
|
return $this->translate($case, $name, $arguments) ?? throw $e; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return match (true) { |
37
|
4 |
|
! is_string($value) => $value, /** @phpstan-ignore-next-line argument.type */ |
38
|
4 |
|
method_exists($value, '__invoke') => call_user_func_array(App::make($value), $arguments), |
39
|
2 |
|
namespaceExists($value) => App::make($value, $arguments), |
40
|
4 |
|
default => $value, |
41
|
|
|
}; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Retrieve the translation of the given key. |
46
|
|
|
* |
47
|
|
|
* @param array<array-key, mixed> $arguments |
|
|
|
|
48
|
|
|
* @throws InvalidArgumentException |
49
|
|
|
*/ |
50
|
5 |
|
protected function translate(UnitEnum $case, string $name, array $arguments): ?string |
51
|
|
|
{ |
52
|
5 |
|
$key = Enums::resolveTranslationKey($case, $name); |
53
|
|
|
|
54
|
5 |
|
if (Lang::get($key) === $key) { |
55
|
1 |
|
return null; |
56
|
|
|
} |
57
|
|
|
|
58
|
4 |
|
if ($arguments && array_is_list($arguments)) { |
|
|
|
|
59
|
1 |
|
$method = sprintf('%s::%s->%s()', $case::class, $case->name, $name); |
60
|
|
|
|
61
|
1 |
|
throw new InvalidArgumentException("The method {$method} must be called with its named arguments"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** @var string */ |
65
|
3 |
|
return Lang::get($key, $arguments); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths