Schema   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 29
c 1
b 0
f 0
dl 0
loc 110
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A addAttribute() 0 3 1
A getResourceType() 0 3 1
A deserializeObject() 0 12 2
A serializeObject() 0 11 2
A getAttributes() 0 3 1
A setName() 0 3 1
A setDescription() 0 3 1
A findAttribute() 0 9 3
A getName() 0 3 1
A getDescription() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the tmilos/scim-schema package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\ScimSchema\Model;
13
14
use Tmilos\ScimSchema\ScimConstants;
15
16
abstract class Schema extends Resource
17
{
18
    /** @var string */
19
    protected $name;
20
21
    /** @var string */
22
    protected $description;
23
24
    /** @var Schema\Attribute[] */
25
    protected $attributes = [];
26
27
    public function getResourceType()
28
    {
29
        return ScimConstants::RESOURCE_TYPE_SCHEMA;
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getName()
36
    {
37
        return $this->name;
38
    }
39
40
    /**
41
     * @param string $name
42
     */
43
    public function setName($name)
44
    {
45
        $this->name = $name;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getDescription()
52
    {
53
        return $this->description;
54
    }
55
56
    /**
57
     * @param string $description
58
     */
59
    public function setDescription($description)
60
    {
61
        $this->description = $description;
62
    }
63
64
    /**
65
     * @param Schema\Attribute $attribute
66
     */
67
    public function addAttribute(Schema\Attribute $attribute)
68
    {
69
        $this->attributes[] = $attribute;
70
    }
71
72
    /**
73
     * @return Schema\Attribute[]
74
     */
75
    public function getAttributes()
76
    {
77
        return $this->attributes;
78
    }
79
80
    /**
81
     * @param string $name
82
     *
83
     * @return null|Schema\Attribute
84
     */
85
    public function findAttribute($name)
86
    {
87
        foreach ($this->attributes as $attribute) {
88
            if ($attribute->getName() === $name) {
89
                return $attribute;
90
            }
91
        }
92
93
        return null;
94
    }
95
96
    public function serializeObject()
97
    {
98
        $result = parent::serializeObject();
99
        $result['name'] = $this->name;
100
        $result['description'] = $this->description;
101
        $result['attributes'] = [];
102
        foreach ($this->attributes as $attribute) {
103
            $result['attributes'][] = $attribute->serializeObject();
104
        }
105
106
        return $result;
107
    }
108
109
    /**
110
     * @param array $data
111
     *
112
     * @return Schema
113
     */
114
    public static function deserializeObject(array $data)
115
    {
116
        /** @var Schema $result */
117
        $result = self::deserializeCommonAttributes($data);
118
        $result->name = $data['name'];
119
        $result->description = $data['description'];
120
        $result->attributes = [];
121
        foreach ($data['attributes'] as $attribute) {
122
            $result->attributes[] = Schema\Attribute::deserializeObject($attribute);
123
        }
124
125
        return $result;
126
    }
127
}
128