Passed
Push — develop ( 87f23a...408180 )
by Jens
02:57
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 library\storage\factories;
9
10
11
class DocumentFolderFactory
12
{
13
	/**
14
	 * Create folder from post values
15
	 *
16
	 * @param $postValues
17
	 *
18
	 * @return \stdClass
19
	 * @throws \Exception
20
	 */
21
	public static function createDocumentFolderFromPostValues($postValues)
22
	{
23
		if (isset($postValues['title'], $postValues['path'], $postValues['content'])) {
24
			$documentFolderObject = new Document();
25
			$documentFolderObject->title = $postValues['title'];
26
			$documentFolderObject->slug = slugify($postValues['title']);
27
			$documentFolderObject->type = 'folder';
28
			$documentFolderObject->content = json_decode($postValues['content']);
29
30
			return $documentFolderObject;
31
		} else {
32
			throw new \Exception('Trying to create document folder with invalid data.');
33
		}
34
	}
35
}