Alias::getAlias()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Maiorano\Shortcodes\Contracts\Traits;
4
5
use Maiorano\Shortcodes\Contracts\AliasInterface;
6
use Maiorano\Shortcodes\Contracts\ContainerAwareInterface;
7
use Maiorano\Shortcodes\Exceptions\RegisterException;
8
9
/**
10
 * Trait Alias
11
 * Assists in satisfying the AliasInterface requirements
12
 * Allows shortcodes to be aliased.
13
 */
14
trait Alias
15
{
16
    /**
17
     * @param string $alias
18
     *
19
     * @throws RegisterException
20
     *
21
     * @return void
22
     */
23 6
    public function aliasHelper(string $alias): void
24
    {
25 6
        if (!($this instanceof AliasInterface)) {
26 1
            throw RegisterException::noAlias();
27
        }
28 5
        if (!$alias) {
29 1
            throw RegisterException::blank();
30
        }
31 4
        if ($this instanceof ContainerAwareInterface && $this->isBound()) {
32 1
            if (!$this->getManager()->isRegistered($alias)) {
33 1
                $this->getManager()->register($this, $alias);
34
            }
35
        }
36 4
    }
37
38
    /**
39
     * @return string[]
40
     */
41 5
    public function getAlias(): array
42
    {
43 5
        return $this->alias;
44
    }
45
}
46