Subject::createFromClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Psi\Component\Description;
4
5
/**
6
 * Subject encapsulate the subject which is to be described.
7
 *
8
 * This can either be an object or a class name.
9
 *
10
 * The Subject should be instantiated with the static constructors
11
 * `createFromObject` and `createFromClass` as required.
12
 */
13
final class Subject
14
{
15
    private $object;
16
    private $class;
17
18
    final public function __construct()
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
19
    {
20
    }
21
22
    public static function createFromObject($object): Subject
23
    {
24
        $subject = new self();
25
        $subject->object = $object;
26
        $subject->class = new \ReflectionClass($object);
27
28
        return $subject;
29
    }
30
31
    public static function createFromClass(string $class): Subject
32
    {
33
        $subject = new self();
34
        $subject->class = new \ReflectionClass($class);
35
36
        return $subject;
37
    }
38
39
    public function getObject()
40
    {
41
        return $this->object;
42
    }
43
44
    public function getClass()
45
    {
46
        return $this->class;
47
    }
48
49
    public function hasObject()
50
    {
51
        return null !== $this->object;
52
    }
53
}
54