Passed
Push — master ( 6c9c0e...70f2f0 )
by Théo
02:22
created

ScoperAutoloadGenerator::dump()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 28
ccs 11
cts 11
cp 1
crap 1
rs 8.8571
c 0
b 0
f 0
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\Autoload;
16
17
final class ScoperAutoloadGenerator
18
{
19
    private $whitelist;
20
21
    /**
22
     * @param string[] $whitelist
23
     */
24 1
    public function __construct(array $whitelist)
25
    {
26 1
        $this->whitelist = $whitelist;
27
    }
28
29 1
    public function dump(string $prefix): string
30
    {
31 1
        $statements = array_map(
32 1
            function (string $whitelist) use ($prefix): string {
33 1
                return sprintf(
34 1
                    'class_exists(\'%s\%s\');',
35 1
                    $prefix,
36 1
                    $whitelist
37
                );
38 1
            },
39 1
            $this->whitelist
40
        );
41
42 1
        $statements = implode(PHP_EOL, $statements);
43
44
        return <<<PHP
45
<?php
46
47
// scoper-autoload.php @generated by PhpScoper
48
49
\$loader = require_once __DIR__.'/autoload.php'; 
50
51 1
$statements
52
53
return \$loader;
54
55
PHP;
56
    }
57
}
58