Completed
Branch TASK/11208/update-bundled-gate... (60edbd)
by
unknown
12:10
created

FullyQualifiedName::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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