SourceExtractor::reflectionOf()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PhpGenerics\Generator;
4
5
use LogicException;
6
use ReflectionClass;
7
use ReflectionException;
8
use function file_get_contents;
9
use function sprintf;
10
11
class SourceExtractor
12
{
13
    public function contentsOf(string $class): string
14
    {
15
        return file_get_contents($this->reflectionOf($class)->getFileName());
16
    }
17
18
    public function reflectionOf(string $class): ReflectionClass
19
    {
20
        try {
21
            return new ReflectionClass($class);
22
        } catch (ReflectionException $e) {
23
            throw new LogicException(
24
                sprintf('Class `%s` not found.', $class),
25
                $e->getCode(),
26
                $e
27
            );
28
        }
29
    }
30
}
31