Conditions | 4 |
Paths | 4 |
Total Lines | 17 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 4.0218 |
Changes | 0 |
1 | <?php |
||
7 | 2 | public function updateTranslations(TranslatableInterface $entity, array $translations, callable $add, callable $update = null) |
|
8 | { |
||
9 | 2 | foreach ($translations as $translation) { |
|
10 | 2 | if (null === $oldTranslation = $entity->getTranslation($translation['locale'], false)) { |
|
11 | 2 | $add($translation); |
|
12 | 2 | continue; |
|
13 | } |
||
14 | |||
15 | 1 | if ($update === null) { |
|
16 | // This will called only when there's update action and $update function not defined |
||
17 | // But you still can keep it as null if you creating entity |
||
18 | throw new \InvalidArgumentException('Unexpected behavior: founded old translation but $update function not defined'); |
||
19 | } |
||
20 | |||
21 | 1 | $update($translation, $oldTranslation); |
|
22 | } |
||
23 | } |
||
24 | } |