Passed
Push — master ( 9c6499...c22bc5 )
by Jens
04:52 queued 02:21
created

createDocumentFolderFromPostValues()   A

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.4285
c 0
b 0
f 0
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\cc\StringUtil;
12
use CloudControl\Cms\storage\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
}