1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\Package\Compiler; |
6
|
|
|
|
7
|
|
|
use Ray\Di\Exception\Unbound; |
8
|
|
|
use Ray\Di\InjectorInterface; |
9
|
|
|
use Throwable; |
10
|
|
|
|
11
|
|
|
use function assert; |
12
|
|
|
use function class_exists; |
13
|
|
|
use function count; |
14
|
|
|
use function get_class; |
15
|
|
|
use function in_array; |
16
|
|
|
use function interface_exists; |
17
|
|
|
use function printf; |
18
|
|
|
use function sprintf; |
19
|
|
|
|
20
|
|
|
use const PHP_EOL; |
21
|
|
|
|
22
|
|
|
final class NewInstance |
23
|
|
|
{ |
24
|
|
|
/** @var list<string> */ |
|
|
|
|
25
|
|
|
private $compiled = []; |
26
|
|
|
|
27
|
|
|
/** @var array<string, string> */ |
28
|
|
|
private $failed = []; |
29
|
|
|
|
30
|
|
|
/** @var InjectorInterface */ |
31
|
|
|
private $injector; |
32
|
|
|
|
33
|
|
|
public function __construct(InjectorInterface $injector) |
34
|
|
|
{ |
35
|
|
|
$this->injector = $injector; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param ''|class-string $interface |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
public function __invoke(string $interface, string $name = ''): void |
42
|
|
|
{ |
43
|
|
|
$dependencyIndex = $interface . '-' . $name; |
44
|
|
|
if (in_array($dependencyIndex, $this->compiled, true)) { |
|
|
|
|
45
|
|
|
// @codeCoverageIgnoreStart |
46
|
|
|
printf("S %s:%s\n", $interface, $name); |
47
|
|
|
// @codeCoverageIgnoreEnd |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
try { |
51
|
|
|
$this->injector->getInstance($interface, $name); |
52
|
|
|
$this->compiled[] = $dependencyIndex; |
53
|
|
|
$this->progress('.'); |
54
|
|
|
} catch (Unbound $e) { |
55
|
|
|
if ($dependencyIndex === 'Ray\Aop\MethodInvocation-') { |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->failed[$dependencyIndex] = $e->getMessage(); |
60
|
|
|
$this->progress('F'); |
61
|
|
|
// @codeCoverageIgnoreStart |
62
|
|
|
} catch (Throwable $e) { |
63
|
|
|
$this->failed[$dependencyIndex] = sprintf('%s: %s', get_class($e), $e->getMessage()); |
64
|
|
|
$this->progress('F'); |
65
|
|
|
// @codeCoverageIgnoreEnd |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function progress(string $char): void |
70
|
|
|
{ |
71
|
|
|
/** |
72
|
|
|
* @var int |
73
|
|
|
*/ |
74
|
|
|
static $cnt = 0; |
75
|
|
|
|
76
|
|
|
echo $char; |
77
|
|
|
$cnt++; |
78
|
|
|
if ($cnt === 60) { |
79
|
|
|
$cnt = 0; |
80
|
|
|
echo PHP_EOL; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getCompiled(): int |
85
|
|
|
{ |
86
|
|
|
return count($this->compiled); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return array<string, string> |
91
|
|
|
*/ |
92
|
|
|
public function getFailed(): array |
93
|
|
|
{ |
94
|
|
|
return $this->failed; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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