Completed
Pull Request — master (#4)
by Fiser
04:46
created

TranslationCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A add() 0 10 3
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel package.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\SharedKernel\Domain\Model\Translation;
13
14
use LIN3S\SharedKernel\Domain\Model\Collection\Collection;
15
use LIN3S\SharedKernel\Domain\Model\Collection\CollectionElementAlreadyAddedException;
16
17
/**
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
class TranslationCollection extends Collection
21
{
22
    protected function type()
23
    {
24
        return Translation::class;
25
    }
26
27
    public function add($translation) : void
28
    {
29
        $translations = $this->toArray();
30
        foreach ($translations as $trans) {
31
            if ($translation->locale()->equals($trans->locale())) {
32
                throw new CollectionElementAlreadyAddedException();
33
            }
34
        }
35
        parent::add($translation);
36
    }
37
}
38