Passed
Pull Request — master (#562)
by Théo
02:07
created

PatcherChain   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Humbug\PhpScoper\Patcher;
6
7
use function array_reduce;
8
9
final class PatcherChain implements Patcher
10
{
11
    /**
12
     * @var array<(callable(string, string, string): string)|Patcher>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<(callable(string, ...ring): string)|Patcher> at position 3 could not be parsed: Expected ')' at position 3, but found 'callable'.
Loading history...
13
     */
14
    private array $patchers;
15
16
    /**
17
     * @param array<callable(string, string, string): string> $patchers
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<callable(string, string, string): string> at position 2 could not be parsed: Expected '>' at position 2, but found 'callable'.
Loading history...
18
     */
19
    public function __construct(array $patchers = [])
20
    {
21
        $this->patchers = $patchers;
22
    }
23
24
    public function __invoke(string $filePath, string $prefix, string $contents): string
25
    {
26
        return (string) array_reduce(
27
            $this->patchers,
28
            static fn (string $contents, callable $patcher) => $patcher($filePath, $prefix, $contents),
29
            $contents,
30
        );
31
    }
32
}
33