AutoAddMissingTranslations::onTerminate()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 2
b 0
f 0
nc 4
nop 1
dl 0
loc 11
ccs 0
cts 10
cp 0
crap 20
rs 10
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 Symfony\Component\HttpKernel\Event\PostResponseEvent;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...Event\PostResponseEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Symfony\Component\HttpKernel\Event\TerminateEvent;
16
use Symfony\Component\Translation\DataCollectorTranslator;
17
use Translation\Bundle\Service\StorageService;
18
use Translation\Common\Model\Message;
19
20
/**
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
final class AutoAddMissingTranslations
24
{
25
    /**
26
     * @var DataCollectorTranslator
27
     */
28
    private $dataCollector;
29
30
    /**
31
     * @var StorageService
32
     */
33
    private $storage;
34
35
    /**
36
     * @param DataCollectorTranslator $translator
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(TerminateEvent $event): void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
    public function onTerminate(/** @scrutinizer ignore-unused */ TerminateEvent $event): void

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

Loading history...
45
    {
46
        if (null === $this->dataCollector) {
47
            return;
48
        }
49
50
        $messages = $this->dataCollector->getCollectedMessages();
51
        foreach ($messages as $message) {
52
            if (DataCollectorTranslator::MESSAGE_MISSING === $message['state']) {
53
                $m = new Message($message['id'], $message['domain'], $message['locale'], $message['translation']);
54
                $this->storage->create($m);
55
            }
56
        }
57
    }
58
}
59
60
// PostResponseEvent have been renamed into ResponseEvent in sf 4.3
61
// @see https://github.com/symfony/symfony/blob/master/UPGRADE-4.3.md#httpkernel
62
// To be removed once sf ^4.3 become the minimum supported version.
63
if (!\class_exists(TerminateEvent::class) && \class_exists(PostResponseEvent::class)) {
64
    \class_alias(PostResponseEvent::class, TerminateEvent::class);
65
}
66