AutoAdder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 46
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B onTerminate() 0 21 5
1
<?php
2
3
namespace Happyr\TranslationBundle\Translation;
4
5
use Happyr\TranslationBundle\Model\Message;
6
use Happyr\TranslationBundle\Service\TranslationServiceInterface;
7
use Symfony\Component\EventDispatcher\Event;
8
use Symfony\Component\Translation\DataCollectorTranslator;
9
10
/**
11
 * @author Tobias Nyholm
12
 */
13
class AutoAdder
14
{
15
    /**
16
     * @var DataCollectorTranslator
17
     */
18
    private $translator;
19
20
    /**
21
     * @var TranslationServiceInterface transService
22
     */
23
    private $transService;
24
25
    /**
26
     * @param DataCollectorTranslator     $translator
27
     * @param TranslationServiceInterface $transService
28
     * @param FilesystemUpdater           $fileSystemUpdater
29
     */
30
    public function __construct(DataCollectorTranslator $translator, TranslationServiceInterface $transService, FilesystemUpdater $fileSystemUpdater)
31
    {
32
        $this->translator = $translator;
33
        $this->transService = $transService;
34
        $this->fileSystemUpdater = $fileSystemUpdater;
0 ignored issues
show
Bug introduced by
The property fileSystemUpdater does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
    }
36
37
    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...
38
    {
39
        if ($this->translator === null) {
40
            return;
41
        }
42
43
        $messages = $this->translator->getCollectedMessages();
44
        $created = array();
45
        foreach ($messages as $message) {
46
            if ($message['state'] === DataCollectorTranslator::MESSAGE_MISSING) {
47
                $m = new Message($message);
48
                $this->transService->createAsset($m);
49
                $created[] = $m;
50
            }
51
        }
52
53
        if (count($created) > 0) {
54
            // update filesystem
55
            $this->fileSystemUpdater->updateMessageCatalog($created);
56
        }
57
    }
58
}
59