Completed
Branch Gutenberg/master (b3a823)
by
unknown
73:52 queued 60:28
created

FullyQualifiedName::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 4
nop 1
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\values;
4
5
use EventEspresso\core\exceptions\InvalidClassException;
6
use EventEspresso\core\exceptions\InvalidDataTypeException;
7
use EventEspresso\core\exceptions\InvalidInterfaceException;
8
9
/**
10
 * Class FullyQualifiedName
11
 * Value Object representing a Fully Qualified Class or Interface Name
12
 *
13
 * @package EventEspresso\core\domain\values
14
 * @author  Brent Christensen
15
 * @since   4.9.51
16
 */
17
class FullyQualifiedName
18
{
19
20
    /**
21
     * @var string $fully_qualified_name
22
     */
23
    private $fully_qualified_name;
24
25
26
    /**
27
     * FullyQualifiedName constructor.
28
     *
29
     * @param string $fully_qualified_name
30
     * @throws InvalidClassException
31
     * @throws InvalidInterfaceException
32
     * @throws InvalidDataTypeException
33
     */
34
    public function __construct($fully_qualified_name)
35
    {
36
        if (! is_string($fully_qualified_name)) {
37
            throw new InvalidDataTypeException(
38
                '$fully_qualified_name',
39
                $fully_qualified_name,
40
                'string'
41
            );
42
        }
43
        if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) {
44
            if (strpos($fully_qualified_name, 'Interface') !== false) {
45
                throw new InvalidInterfaceException($fully_qualified_name);
46
            }
47
            throw new InvalidClassException($fully_qualified_name);
48
        }
49
        $this->fully_qualified_name = $fully_qualified_name;
50
    }
51
52
53
    /**
54
     * @return string
55
     */
56
    public function string()
57
    {
58
        return $this->fully_qualified_name;
59
    }
60
61
62
    /**
63
     * @return string
64
     */
65
    public function __toString()
66
    {
67
        return $this->fully_qualified_name;
68
    }
69
}
70