FileWhitelistScoper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
ccs 1
cts 1
cp 1
crap 1
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\Scoper;
16
17
use function array_key_exists;
18
use function func_get_args;
19
use function Safe\array_flip;
20
21
final class FileWhitelistScoper implements Scoper
22
{
23
    private Scoper $decoratedScoper;
24
    private array $filePaths;
25
26
    public function __construct(Scoper $decoratedScoper, string ...$filePaths)
27
    {
28 1
        $this->decoratedScoper = $decoratedScoper;
29
        $this->filePaths = array_flip($filePaths);
0 ignored issues
show
Deprecated Code introduced by
The function Safe\array_flip() has been deprecated: The Safe version of this function is no longer needed in PHP 8.0+ ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

29
        $this->filePaths = /** @scrutinizer ignore-deprecated */ array_flip($filePaths);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
30 1
    }
31 1
32
    public function scope(string $filePath, string $contents): string
33
    {
34
        if (array_key_exists($filePath, $this->filePaths)) {
35
            return $contents;
36
        }
37 1
38
        return $this->decoratedScoper->scope(...func_get_args());
39 1
    }
40
}
41