Completed
Push — phpstan ( a6870d...9a9c44 )
by Akihito
03:00
created

ClassFileName::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use Ray\Aop\WeavedInterface;
8
9
final class ClassFileName
10
{
11
    public function __invoke($object) : string
12
    {
13
        if (! $object instanceof WeavedInterface) {
14
            return get_class($object);
15
        }
16
17
        $class = new \ReflectionClass($object);
18
        if (! $class instanceof \ReflectionClass) {
19
            throw new \ReflectionException;
20
        }
21
        $parent = $class->getParentClass();
22
        if (! $parent instanceof \ReflectionClass) {
23
            throw new \ReflectionException;
24
        }
25
26
        return (string) $parent->getFileName();
27
    }
28
}
29