1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the humbug/php-scoper package. |
||
7 | * |
||
8 | * Copyright (c) 2017 Théo FIDRY <[email protected]>, |
||
9 | * Pádraic Brady <[email protected]> |
||
10 | * |
||
11 | * For the full copyright and license information, please view the LICENSE |
||
12 | * file that was distributed with this source code. |
||
13 | */ |
||
14 | |||
15 | namespace Humbug\PhpScoper\Patcher; |
||
16 | |||
17 | use function array_reduce; |
||
18 | |||
19 | final class PatcherChain implements Patcher |
||
20 | { |
||
21 | /** |
||
22 | * @var array<(callable(string, string, string): string)|Patcher> |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
23 | */ |
||
24 | private array $patchers; |
||
25 | |||
26 | /** |
||
27 | * @param array<(callable(string, string, string): string)|Patcher> $patchers |
||
0 ignored issues
–
show
|
|||
28 | */ |
||
29 | public function __construct(array $patchers = []) |
||
30 | { |
||
31 | $this->patchers = $patchers; |
||
32 | } |
||
33 | |||
34 | public function __invoke(string $filePath, string $prefix, string $contents): string |
||
35 | { |
||
36 | return array_reduce( |
||
37 | $this->patchers, |
||
38 | static fn (string $contents, callable $patcher) => $patcher($filePath, $prefix, $contents), |
||
39 | $contents, |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @internal |
||
45 | * |
||
46 | * @return array<(callable(string, string, string): string)|Patcher> |
||
0 ignored issues
–
show
|
|||
47 | */ |
||
48 | public function getPatchers(): array |
||
49 | { |
||
50 | return $this->patchers; |
||
51 | } |
||
52 | } |
||
53 |