Completed
Push — master ( bdaaf9...c29061 )
by Tobias
09:51
created

AutoAddMissingTranslations::onTerminate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 9.2
c 1
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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 Translation\Bundle\EventListener;
13
14
use Translation\Common\Model\Message;
15
use Symfony\Component\EventDispatcher\Event;
16
use Symfony\Component\Translation\DataCollectorTranslator;
17
use Translation\Bundle\Service\StorageService;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
class AutoAddMissingTranslations
23
{
24
    /**
25
     * @var DataCollectorTranslator
26
     */
27
    private $dataCollector;
28
29
    /**
30
     * @var StorageService
31
     */
32
    private $storage;
33
34
    /**
35
     * @param DataCollectorTranslator $translator
36
     * @param StorageService          $storage
37
     */
38
    public function __construct(StorageService $storage, DataCollectorTranslator $translator = null)
39
    {
40
        $this->dataCollector = $translator;
41
        $this->storage = $storage;
42
    }
43
44
    public function onTerminate(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        if ($this->dataCollector === null) {
47
            return;
48
        }
49
50
        $messages = $this->dataCollector->getCollectedMessages();
51
        foreach ($messages as $message) {
52
            if ($message['state'] === DataCollectorTranslator::MESSAGE_MISSING) {
53
                $m = new Message($message['id'], $message['domain'], $message['locale'], $message['translation']);
54
                $this->storage->create($m);
55
            }
56
        }
57
    }
58
}
59