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

ScoperAutoloadGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B dump() 0 28 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\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