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

EntryFactory::createFromArray()   C

Complexity

Conditions 12
Paths 20

Size

Total Lines 50
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 5.3904
c 0
b 0
f 0
cc 12
eloc 34
nc 20
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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