Completed
Branch BUG/reg-status-change-recursio... (2db0c9)
by
unknown
20:03 queued 10:32
created

ClassAlias::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\services\dependencies;
4
5
use EventEspresso\core\exceptions\InvalidAliasException;
6
7
/**
8
 * ClassAlias
9
 * Simple value object for representing
10
 * a class alias such as an interface or base class
11
 * and the actual class that should be utilized instead
12
 *
13
 * @package EventEspresso\core\services\dependencies
14
 * @author  Brent Christensen
15
 * @since   $VID:$
16
 */
17
class ClassAlias
18
{
19
20
    /**
21
     * @var string $alias   an interface or base class representing what object
22
     *                      can be utilized by another object and/or function
23
     */
24
    private $alias;
25
26
    /**
27
     * @var string $fqcn the actual class that should be substituted for the alias above
28
     */
29
    private $fqcn;
30
31
    /**
32
     * ClassAlias constructor.
33
     *
34
     * @param string $alias Interface specified by implementing class
35
     * @param string $fqcn  Concrete class that satisfies interface
36
     * @throws InvalidAliasException
37
     */
38
    public function __construct($alias, $fqcn)
39
    {
40
        if (! is_subclass_of($fqcn, $alias)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if $alias can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
41
            throw new InvalidAliasException($fqcn, $alias);
42
        }
43
        $this->alias = $alias;
44
        $this->fqcn = $fqcn;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function alias()
51
    {
52
        return $this->alias;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function fqcn()
59
    {
60
        return $this->fqcn;
61
    }
62
}
63