ExcludedFilesScoper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A scope() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\PhpScoper;
16
17
use Humbug\PhpScoper\Scoper\Scoper as PhpScoperScoper;
18
use function array_flip;
19
use function array_key_exists;
20
use function func_get_args;
21
22
final class ExcludedFilesScoper implements PhpScoperScoper
23
{
24
    private readonly array $excludedFilePathsAsKeys;
25
26
    public function __construct(
27
        private readonly PhpScoperScoper $decoratedScoper,
28
        string ...$excludedFilePaths,
29
    ) {
30
        $this->excludedFilePathsAsKeys = array_flip($excludedFilePaths);
0 ignored issues
show
Bug introduced by
The property excludedFilePathsAsKeys is declared read-only in KevinGH\Box\PhpScoper\ExcludedFilesScoper.
Loading history...
31
    }
32
33
    public function scope(string $filePath, string $contents): string
34
    {
35
        if (array_key_exists($filePath, $this->excludedFilePathsAsKeys)) {
36
            return $contents;
37
        }
38
39
        return $this->decoratedScoper->scope(...func_get_args());
40
    }
41
}
42