createApplicationComponentFromPostValues()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 3
nop 1
dl 0
loc 17
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: jensk
4
 * Date: 13-3-2017
5
 * Time: 17:06
6
 */
7
8
namespace CloudControl\Cms\storage\factories;
9
10
11
use CloudControl\Cms\util\StringUtil;
12
13
class ApplicationComponentFactory
14
{
15
    /**
16
     * @param $postValues
17
     *
18
     * @return \stdClass
19
     * @throws \Exception
20
     */
21
    public static function createApplicationComponentFromPostValues($postValues)
22
    {
23
        if (isset($postValues['title'], $postValues['component'])) {
24
            $applicationComponent = new \stdClass();
25
            $applicationComponent->title = $postValues['title'];
26
            $applicationComponent->slug = StringUtil::slugify($postValues['title']);
27
            $applicationComponent->component = $postValues['component'];
28
            $applicationComponent->parameters = new \stdClass();
29
            if (isset($postValues['parameterNames'], $postValues['parameterValues'])) {
30
                foreach ($postValues['parameterNames'] as $key => $value) {
31
                    $applicationComponent->parameters->$value = $postValues['parameterValues'][$key];
32
                }
33
            }
34
35
            return $applicationComponent;
36
        } else {
37
            throw new \Exception('Trying to create application component with invalid data.');
38
        }
39
    }
40
}