Completed
Pull Request — develop (#225)
by
unknown
09:12 queued 07:20
created

AttributeCollectionAggregate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 13 1
A getAttributes() 0 8 2
1
<?php
2
3
/**
4
 * Copyright 2020 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Value;
20
21
use Surfnet\StepupSelfService\SelfServiceBundle\Assert;
22
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Dto\AttributeListDto;
23
24
class AttributeCollectionAggregate implements AttributeCollectionInterface
25
{
26
    /**
27
     * @var AttributeCollectionInterface[]
28
     */
29
    private $attributeCollections = [];
30
31
    public function add($name, AttributeCollectionInterface $collection)
32
    {
33
        Assert::string(
34
            $name,
35
            'The name of the attribute collection should not be null, and should identify the purpose of the collection'
36
        );
37
        Assert::keyNotExists(
38
            $this->attributeCollections,
39
            $name,
40
            sprintf('The collection named: "%s" is already present in the collection', $name)
41
        );
42
        $this->attributeCollections[$name] = $collection;
43
    }
44
45
    /**
46
     * @return AttributeListDto[]
47
     */
48
    public function getAttributes()
49
    {
50
        $output = [];
51
        foreach ($this->attributeCollections as $name => $collection) {
52
            $output[$name] = $collection->getAttributes();
53
        }
54
        return $output;
55
    }
56
}
57