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

DocumentFolderFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createDocumentFolderFromPostValues() 0 14 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\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
}