DocumentFolderFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createDocumentFolderFromPostValues() 0 12 2
1
<?php
2
/**
3
 * User: jensk
4
 * Date: 13-3-2017
5
 * Time: 17:03
6
 */
7
8
namespace CloudControl\Cms\storage\factories;
9
10
11
use CloudControl\Cms\util\StringUtil;
12
use CloudControl\Cms\storage\entities\Document;
13
14
class DocumentFolderFactory
15
{
16
    /**
17
     * Create folder from post values
18
     *
19
     * @param $postValues
20
     *
21
     * @return Document
22
     * @throws \Exception
23
     */
24
    public static function createDocumentFolderFromPostValues($postValues)
25
    {
26
        if (isset($postValues['title'], $postValues['path'], $postValues['content'])) {
27
            $documentFolderObject = new Document();
28
            $documentFolderObject->title = $postValues['title'];
29
            $documentFolderObject->slug = StringUtil::slugify($postValues['title']);
30
            $documentFolderObject->type = 'folder';
31
            $documentFolderObject->content = json_decode($postValues['content']);
32
33
            return $documentFolderObject;
34
        } else {
35
            throw new \Exception('Trying to create document folder with invalid data.');
36
        }
37
    }
38
}