Completed
Pull Request — master (#68)
by Raúl
02:28 queued 01:14
created

EntryFactory   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 1
dl 0
loc 57
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C createFromArray() 0 50 12
1
<?php
2
3
namespace Sepia\PoParser\Catalog;
4
5
class EntryFactory
6
{
7
    /**
8
     * @param array $entry
0 ignored issues
show
Bug introduced by
There is no parameter named $entry. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
9
     * @return Entry
10
     */
11
    public static function createFromArray(array $entryArray)
12
    {
13
        $entry = new Entry(
14
            $entryArray['msgid'],
15
            isset($entryArray['msgstr']) ? $entryArray['msgstr'] : null
16
        );
17
        $plurals = array();
18
19
        foreach ($entryArray as $key => $value) {
20
            switch (true) {
21
                case $key === 'msgctxt':
22
                    $entry->setMsgCtxt($entryArray['msgctxt']);
23
                    break;
24
25
                case $key === 'flags':
26
                    $entry->setFlags($entryArray['flags']);
27
                    break;
28
29
                case $key === 'reference':
30
                    $entry->setReference($entryArray['reference']);
31
                    break;
32
33
                case $key === 'previous':
34
                    $entry->setPreviousEntry(self::createFromArray($entryArray['previous']));
35
                    break;
36
37
                case $key === 'tcomment':
38
                    $entry->setTranslatorComments($value);
39
                    break;
40
41
                case $key === 'ccomment':
42
                    $entry->setDeveloperComments($value);
43
                    break;
44
45
                case $key === 'obsolete':
46
                    $entry->setObsolete(true);
47
                    break;
48
49
                case 0 === strpos($key, 'msgstr['):
50
                    $plurals[] = $value;
51
                    break;
52
            }
53
        }
54
55
        if (count($plurals) > 0) {
56
            $entry->setMsgStrPlurals($plurals);
57
        }
58
59
        return $entry;
60
    }
61
}
62