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 UnitEnum $case |
25
|
|
|
* @param array<array-key, mixed> $arguments |
|
|
|
|
26
|
|
|
* @throws InvalidArgumentException |
27
|
|
|
* @throws \ValueError |
28
|
|
|
*/ |
29
|
9 |
|
public function __invoke(object $case, string $name, array $arguments): mixed |
30
|
|
|
{ |
31
|
|
|
try { |
32
|
9 |
|
$value = $case->resolveMetaAttribute($name); |
33
|
5 |
|
} catch (Throwable $e) { |
34
|
5 |
|
return $this->translate($case, $name, $arguments) ?: throw $e; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return match (true) { |
38
|
4 |
|
! is_string($value) => $value, /** @phpstan-ignore-next-line argument.type */ |
39
|
4 |
|
method_exists($value, '__invoke') => call_user_func_array(App::make($value), $arguments), |
40
|
2 |
|
namespaceExists($value) => App::make($value, $arguments), |
41
|
4 |
|
default => $value, |
42
|
|
|
}; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Retrieve the translation of the given key. |
47
|
|
|
* |
48
|
|
|
* @param array<array-key, mixed> $arguments |
|
|
|
|
49
|
|
|
* @throws InvalidArgumentException |
50
|
|
|
*/ |
51
|
5 |
|
protected function translate(UnitEnum $case, string $name, array $arguments): ?string |
52
|
|
|
{ |
53
|
5 |
|
$key = Enums::resolveTranslationKey($case, $name); |
54
|
|
|
|
55
|
5 |
|
if ($key === Lang::get($key)) { |
56
|
1 |
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
4 |
|
if ($arguments && array_is_list($arguments)) { |
|
|
|
|
60
|
1 |
|
$method = sprintf('%s::%s->%s()', $case::class, $case->name, $name); |
61
|
|
|
|
62
|
1 |
|
throw new InvalidArgumentException("The method {$method} must be called with its named arguments"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** @var string */ |
66
|
3 |
|
return Lang::get($key, $arguments); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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