ApplicationComponentFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A createApplicationComponentFromPostValues() 0 17 4
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
}