AbstractCollectionBehavior   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 0
cbo 0
dl 0
loc 77
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A getItemName() 0 4 1
A getMethods() 0 4 1
1
<?php
2
3
namespace Accessible\Annotation;
4
5
/**
6
 * This class is the base of the collection-based behavior annotations.
7
 */
8
abstract class AbstractCollectionBehavior
9
{
10
    /**
11
     * The property can be accessed through an addX method.
12
     *
13
     * @var string
14
     */
15
    const ADD = "add";
16
17
    /**
18
     * The property can be accessed through a removeX method.
19
     *
20
     * @var string
21
     */
22
    const REMOVE = "remove";
23
24
    /**
25
     * The name of an item in the collection. It is used to deduce the methods names.
26
     * If it is not defined, it will be the singularized version of the property name.
27
     *
28
     * @var string
29
     */
30
    protected $itemName;
31
32
    /**
33
     * The list of methods that can be used with the collection.
34
     *
35
     * @var array
36
     */
37
    protected $methods;
38
39
    /**
40
     * The default methods that can be used.
41
     *
42
     * @var array<string>
43
     */
44
    protected $defaultMethods;
45
46
    /**
47
     * Initializes the annotation.
48
     *
49
     * @param mixed $values The annotation's parameters.
50
     */
51 6
    public function __construct($values)
52
    {
53 6
        $this->defaultMethods = array(AbstractCollectionBehavior::ADD, AbstractCollectionBehavior::REMOVE);
54
55
        $defaults = array(
56 6
            'itemName' => null,
57 6
            'methods' => $this->defaultMethods
58 6
        );
59
60 6
        foreach ($defaults as $property => $defaultValue) {
61 6
            $this->$property = (empty($values[$property])) ? $defaultValue : $values[$property];
62 6
        }
63 6
    }
64
65
    /**
66
     * Get the item name.
67
     *
68
     * @return string
69
     */
70 6
    public function getItemName()
71
    {
72 6
        return $this->itemName;
73
    }
74
75
    /**
76
     * Get the list of methods that can be used.
77
     *
78
     * @return array<string>
79
     */
80 6
    public function getMethods()
81
    {
82 6
        return $this->methods;
83
    }
84
}
85