Subject   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createFromObject() 0 8 1
A createFromClass() 0 7 1
A getObject() 0 4 1
A getClass() 0 4 1
A hasObject() 0 4 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