Passed
Push — master ( dfcc34...e877b3 )
by Matt
02:35
created

Alias::aliasHelper()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.2222
c 0
b 0
f 0
cc 6
nc 5
nop 1
crap 6
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)
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 array
40
     */
41 7
    public function getAlias(): array
42
    {
43 7
        return $this->alias;
44
    }
45
}
46