Completed
Push — master ( 90ccc1...22512f )
by Kamil
35:43
created

ThemeFactory::createFromArray()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 26
rs 8.439
c 2
b 0
f 1
cc 5
eloc 13
nc 16
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\ThemeBundle\Factory;
13
14
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
15
use Sylius\Component\Resource\Factory\FactoryInterface;
16
17
/**
18
 * @author Kamil Kokot <[email protected]>
19
 */
20
final class ThemeFactory implements ThemeFactoryInterface
21
{
22
    /**
23
     * @var FactoryInterface
24
     */
25
    private $basicThemeFactory;
26
27
    /**
28
     * @param FactoryInterface $basicThemeFactory
29
     */
30
    public function __construct(FactoryInterface $basicThemeFactory)
31
    {
32
        $this->basicThemeFactory = $basicThemeFactory;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function createFromArray(array $themeData)
39
    {
40
        /** @var ThemeInterface $theme */
41
        $theme = $this->basicThemeFactory->createNew();
42
43
        $theme->setName($themeData['name']);
44
        $theme->setPath($themeData['path']);
45
46
        if (isset($themeData['authors'])) {
47
            $theme->setAuthors($themeData['authors']);
48
        }
49
50
        if (isset($themeData['title'])) {
51
            $theme->setTitle($themeData['title']);
52
        }
53
54
        if (isset($themeData['description'])) {
55
            $theme->setDescription($themeData['description']);
56
        }
57
58
        if (isset($themeData['parents'])) {
59
            $theme->setParentsNames($themeData['parents']);
60
        }
61
62
        return $theme;
63
    }
64
}
65