ThemeFactory::create()   F
last analyzed

Complexity

Conditions 10
Paths 256

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 34
rs 3.1304
cc 10
eloc 21
nc 256
nop 2

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 Oro\Component\Layout\Extension\Theme\Model;
4
5
class ThemeFactory implements ThemeFactoryInterface
6
{
7
    /**
8
     * {@inheritdoc}
9
     *
10
     * @SuppressWarnings(PHPMD.NPathComplexity)
11
     */
12
    public function create($themeName, array $themeDefinition)
13
    {
14
        $theme = new Theme(
15
            $themeName,
16
            isset($themeDefinition['parent']) ? $themeDefinition['parent'] : null
17
        );
18
19
        if (isset($themeDefinition['label'])) {
20
            $theme->setLabel($themeDefinition['label']);
21
        }
22
        if (isset($themeDefinition['screenshot'])) {
23
            $theme->setScreenshot($themeDefinition['screenshot']);
24
        }
25
        if (isset($themeDefinition['icon'])) {
26
            $theme->setIcon($themeDefinition['icon']);
27
        }
28
        if (isset($themeDefinition['logo'])) {
29
            $theme->setLogo($themeDefinition['logo']);
30
        }
31
        if (isset($themeDefinition['directory'])) {
32
            $theme->setDirectory($themeDefinition['directory']);
33
        }
34
        if (isset($themeDefinition['groups'])) {
35
            $theme->setGroups((array)$themeDefinition['groups']);
36
        }
37
        if (isset($themeDefinition['description'])) {
38
            $theme->setDescription($themeDefinition['description']);
39
        }
40
        if (isset($themeDefinition['data'])) {
41
            $theme->setData($themeDefinition['data']);
42
        }
43
44
        return $theme;
45
    }
46
}
47