ImageSetFactory::createImageSetFromPostValues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: jensk
4
 * Date: 13-3-2017
5
 * Time: 17:05
6
 */
7
8
namespace CloudControl\Cms\storage\factories;
9
10
11
use CloudControl\Cms\util\StringUtil;
12
13
class ImageSetFactory
14
{
15
    /**
16
     * Ceate image set from post values
17
     *
18
     * @param $postValues
19
     *
20
     * @return \stdClass
21
     * @throws \Exception
22
     */
23
    public static function createImageSetFromPostValues($postValues)
24
    {
25
        if (isset($postValues['title'], $postValues['width'], $postValues['height'], $postValues['method'])) {
26
            $imageSetObject = new \stdClass();
27
28
            $imageSetObject->title = $postValues['title'];
29
            $imageSetObject->slug = StringUtil::slugify($postValues['title']);
30
            $imageSetObject->width = $postValues['width'];
31
            $imageSetObject->height = $postValues['height'];
32
            $imageSetObject->method = $postValues['method'];
33
34
            return $imageSetObject;
35
        } else {
36
            throw new \Exception('Trying to create image set with invalid data.');
37
        }
38
    }
39
}