ConfigGenerator::generateConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
rs 9.4285
cc 3
eloc 10
nc 3
nop 0
1
<?php
2
3
namespace ClassDumper;
4
5
use Zend\Code\Generator\ValueGenerator;
6
use Zend\Code\Reflection\ClassReflection;
7
8
class ConfigGenerator
9
{
10
    private $skip = [
11
        'ComposerAutoloaderInit',
12
        'ClassDumper\\',
13
    ];
14
15
    private function shouldSkip(ClassReflection $class)
16
    {
17
        if ($class->isInternal()) {
18
            return true;
19
        }
20
        foreach ($this->skip as $prefix) {
21
            if (strpos($class->getName(), $prefix) === 0) {
0 ignored issues
show
Bug introduced by
Consider using $class->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
22
                return true;
23
            }
24
        }
25
26
        return false;
27
    }
28
29
    private function generateConfig()
30
    {
31
        $allClasses = get_declared_classes();
32
        $classList = [];
33
34
        foreach ($allClasses as $class) {
35
            $class = new ClassReflection($class);
36
37
            if ($this->shouldSkip($class)) {
38
                continue;
39
            }
40
41
            $classList[] = $class->getName();
0 ignored issues
show
Bug introduced by
Consider using $class->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
42
        }
43
44
        $generator = new ValueGenerator($classList);
45
        return $generator->generate();
46
    }
47
48
    public function dumpIncludedClasses($fileName)
49
    {
50
        $config = $this->generateConfig();
51
52
        file_put_contents(
53
            $fileName,
54
            "<?php\n\nreturn " . $config . ";\n"
55
        );
56
    }
57
}
58