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

TranslationCollection::add()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
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