Passed
Push — develop ( 87f23a...408180 )
by Jens
02:57
created

BrickFactory::createBrickFromPostValues()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 7
Ratio 35 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 3
nop 1
dl 7
loc 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: jensk
4
 * Date: 13-3-2017
5
 * Time: 16:58
6
 */
7
8
namespace library\storage\factories;
9
10
11
class BrickFactory extends AbstractBricksFactory
12
{
13
	/**
14
	 * Create a brick from post values
15
	 *
16
	 * @param $postValues
17
	 *
18
	 * @return \stdClass
19
	 * @throws \Exception
20
	 */
21
	public static function createBrickFromPostValues($postValues)
22
	{
23
		if (isset($postValues['title'])) {
24
			$brickObject = new \stdClass();
25
			$brickObject->title = $postValues['title'];
26
			$brickObject->slug = slugify($postValues['title']);
27
			$brickObject->fields = array();
28 View Code Duplication
			if (isset($postValues['fieldTitles'], $postValues['fieldTypes'], $postValues['fieldRequired'], $postValues['fieldMultiple'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
				foreach ($postValues['fieldTitles'] as $key => $value) {
30
					$fieldObject = self::createFieldObject($postValues, $value, $key);
31
32
					$brickObject->fields[] = $fieldObject;
33
				}
34
			}
35
36
			return $brickObject;
37
		} else {
38
			throw new \Exception('Trying to create document type with invalid data.');
39
		}
40
	}
41
}