SourceExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A contentsOf() 0 3 1
A reflectionOf() 0 9 2
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