Passed
Push — master ( 3f6c85...9c6499 )
by Jens
02:40
created

BrickFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 22.58 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 7
loc 31
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createBrickFromPostValues() 7 20 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
use library\cc\StringUtil;
12
13
class BrickFactory extends AbstractBricksFactory
14
{
15
	/**
16
	 * Create a brick from post values
17
	 *
18
	 * @param $postValues
19
	 *
20
	 * @return \stdClass
21
	 * @throws \Exception
22
	 */
23
	public static function createBrickFromPostValues($postValues)
24
	{
25
		if (isset($postValues['title'])) {
26
			$brickObject = new \stdClass();
27
			$brickObject->title = $postValues['title'];
28
			$brickObject->slug = StringUtil::slugify($postValues['title']);
29
			$brickObject->fields = array();
30 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...
31
				foreach ($postValues['fieldTitles'] as $key => $value) {
32
					$fieldObject = self::createFieldObject($postValues, $value, $key);
33
34
					$brickObject->fields[] = $fieldObject;
35
				}
36
			}
37
38
			return $brickObject;
39
		} else {
40
			throw new \Exception('Trying to create document type with invalid data.');
41
		}
42
	}
43
}