PropertySetSchema::setPropertySchema()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
/**
3
 * @link https://github.com/old-town/old-town-propertyset
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\PropertySet;
7
8
/**
9
 * Class PropertySetSchema
10
 *
11
 * @package OldTown\PropertySet
12
 */
13
class PropertySetSchema
14
{
15
    /**
16
     * @var PropertySchema[]
17
     */
18
    protected $propertySchemas = [];
19
20
    /**
21
     * @var bool
22
     */
23
    protected $restricted = false;
24
25
    /**
26
     *
27
     * @param string $key
28
     *
29
     * @return PropertySchema|null
30
     *
31
     */
32
    public function getPropertySchema($key)
33
    {
34
        $key = (string)$key;
35
        if (!array_key_exists($key, $this->propertySchemas)) {
36
            return null;
37
        }
38
39
        return $this->propertySchemas[$key];
40
    }
41
42
    /**
43
     *
44
     *
45
     * @param string $key
46
     * @param PropertySchema $ps
47
     *
48
     * @return $this
49
     */
50
    public function setPropertySchema($key, PropertySchema $ps)
51
    {
52
        $key = (string)$key;
53
        if (null !== $ps->getPropertyName()) {
54
            $ps->setPropertyName($key);
55
        }
56
        $this->propertySchemas[$key] = $ps;
57
58
        return $this;
59
    }
60
61
    /**
62
     * @param PropertySchema $ps
63
     *
64
     * @return $this
65
     */
66
    public function addPropertySchema(PropertySchema $ps)
67
    {
68
        $key = (string)$ps->getPropertyName();
69
        $this->propertySchemas[$key] = $ps;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return boolean
76
     */
77
    public function isRestricted()
78
    {
79
        return $this->restricted;
80
    }
81
82
    /**
83
     * @param boolean $restricted
84
     *
85
     * @return $this
86
     */
87
    public function setRestricted($restricted)
88
    {
89
        $this->restricted = (boolean)$restricted;
90
91
        return $this;
92
    }
93
}
94