Completed
Push — master ( 04637e...d841ab )
by Matt
04:29
created

Alias::aliasHelper()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 8.8333
c 0
b 0
f 0
cc 7
nc 8
nop 1
crap 7
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
32 4
        if (!in_array($alias, $this->alias)) {
33 4
            $this->alias[] = $alias;
0 ignored issues
show
Bug Best Practice introduced by
The property alias does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
        }
35
36 4
        if ($this instanceof ContainerAwareInterface && $this->isBound()) {
37 1
            if (!$this->getManager()->isRegistered($alias)) {
38 1
                $this->getManager()->register($this, $alias);
39
            }
40
        }
41 4
    }
42
43
    /**
44
     * @return array
45
     */
46 7
    public function getAlias(): array
47
    {
48 7
        return $this->alias;
49
    }
50
}
51