|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Interceptors\Context; |
|
6
|
|
|
|
|
7
|
|
|
final class Target implements TargetInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param list<string> $path |
|
|
|
|
|
|
11
|
|
|
* @param \ReflectionFunctionAbstract|null $reflection |
|
12
|
|
|
*/ |
|
13
|
|
|
private function __construct( |
|
14
|
|
|
private ?array $path = null, |
|
15
|
|
|
private ?\ReflectionFunctionAbstract $reflection = null, |
|
16
|
|
|
private readonly string $delimiter = '.', |
|
17
|
|
|
) { |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function __toString(): string |
|
21
|
|
|
{ |
|
22
|
|
|
return match (true) { |
|
23
|
|
|
$this->path !== null => \implode($this->delimiter, $this->path), |
|
|
|
|
|
|
24
|
|
|
$this->reflection !== null => $this->reflection->getName(), |
|
|
|
|
|
|
25
|
|
|
}; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public static function fromReflection(\ReflectionFunctionAbstract $reflection): self |
|
29
|
|
|
{ |
|
30
|
|
|
return new self(reflection: $reflection); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public static function fromPathString(string $path, string $delimiter = '.'): self |
|
34
|
|
|
{ |
|
35
|
|
|
/** @psalm-suppress ArgumentTypeCoercion */ |
|
36
|
|
|
return new self(path: \explode($delimiter, $path), delimiter: $delimiter); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param list<string> $path |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function fromPathArray(array $path, string $delimiter = '.'): self |
|
43
|
|
|
{ |
|
44
|
|
|
return new self(path: $path, delimiter: $delimiter); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function fromPair(string $controller, string $action): self |
|
48
|
|
|
{ |
|
49
|
|
|
return \method_exists($controller, $action) |
|
50
|
|
|
? self::fromReflection(new \ReflectionMethod($controller, $action)) |
|
51
|
|
|
: self::fromPathArray([$controller, $action]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getPath(): array |
|
55
|
|
|
{ |
|
56
|
|
|
return match (true) { |
|
57
|
|
|
$this->path !== null => $this->path, |
|
58
|
|
|
$this->reflection instanceof \ReflectionMethod => [ |
|
59
|
|
|
$this->reflection->getDeclaringClass()->getName(), |
|
|
|
|
|
|
60
|
|
|
$this->reflection->getName(), |
|
61
|
|
|
], |
|
62
|
|
|
$this->reflection instanceof \ReflectionFunction => [$this->reflection->getName()], |
|
63
|
|
|
default => [], |
|
64
|
|
|
}; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function withPath(array $path): static |
|
68
|
|
|
{ |
|
69
|
|
|
$clone = clone $this; |
|
70
|
|
|
$clone->path = $path; |
|
|
|
|
|
|
71
|
|
|
return $clone; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getReflection(): ?\ReflectionFunctionAbstract |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->reflection; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function withReflection(?\ReflectionFunctionAbstract $reflection): static |
|
80
|
|
|
{ |
|
81
|
|
|
$clone = clone $this; |
|
82
|
|
|
$clone->reflection = $reflection; |
|
83
|
|
|
return $clone; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
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