Completed
Push — master ( e24a08...649c71 )
by Joshua
9s
created

MixinsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addMixin() 0 10 2
A hasMixin() 0 4 1
A getMixins() 0 4 1
applyMixinProperties() 0 1 ?
1
<?php
2
3
namespace As3\Modlr\Metadata\Traits;
4
5
use As3\Modlr\Exception\MetadataException;
6
use As3\Modlr\Metadata\MixinMetadata;
7
8
/**
9
 * Common mixin metadata get, set, and add methods.
10
 *
11
 * @author Jacob Bare <[email protected]>
12
 */
13
trait MixinsTrait
14
{
15
    /**
16
     * All mixins assigned to this object.
17
     *
18
     * @var     MixinMetadata[]
19
     */
20
    public $mixins = [];
21
22
    /**
23
     * Adds a mixin (and applies its properties) to this object.
24
     *
25
     * @param   MixinMetadata   $mixin
26
     * @return  self
27
     */
28
    public function addMixin(MixinMetadata $mixin)
29
    {
30
        if (isset($this->mixins[$mixin->name])) {
31
            return $this;
32
        }
33
34
        $this->applyMixinProperties($mixin);
35
        $this->mixins[$mixin->name] = $mixin;
36
        return $this;
37
    }
38
39
    /**
40
     * Determines if a mixin exists.
41
     *
42
     * @param   string  $mixinName
43
     * @return  bool
44
     */
45
    public function hasMixin($mixinName)
46
    {
47
        return isset($this->mixins[$mixinName]);
48
    }
49
50
    /**
51
     * Gets all assigned mixins.
52
     *
53
     * @return  MixinMetadata[]
54
     */
55
    public function getMixins()
56
    {
57
        return $this->mixins;
58
    }
59
60
    /**
61
     * Applies the mixin properties to the implementing object.
62
     *
63
     * @param   MixinMetadata
64
     * @throws  MetadataException
65
     * @return  self
66
     */
67
    protected abstract function applyMixinProperties(MixinMetadata $mixin);
68
}
69