Test Setup Failed
Push — master ( be22eb...d6400f )
by Théo
02:19
created

ScoperAutoloadGenerator::createStatements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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