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

ApplicationComponentFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 17.86 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 5
loc 28
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createApplicationComponentFromPostValues() 5 19 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: 17:06
6
 */
7
8
namespace library\storage\factories;
9
10
11
use library\cc\StringUtil;
12
13
class ApplicationComponentFactory
14
{
15
	/**
16
	 * @param $postValues
17
	 *
18
	 * @return \stdClass
19
	 * @throws \Exception
20
	 */
21
	public static function createApplicationComponentFromPostValues($postValues)
22
	{
23
		if (isset($postValues['title'], $postValues['component'])) {
24
			$applicationComponent = new \stdClass();
25
			$applicationComponent->title = $postValues['title'];
26
			$applicationComponent->slug = StringUtil::slugify($postValues['title']);
27
			$applicationComponent->component = $postValues['component'];
28
			$applicationComponent->parameters = new \stdClass();
29 View Code Duplication
			if (isset($postValues['parameterNames'], $postValues['parameterValues'])) {
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...
30
				foreach ($postValues['parameterNames'] as $key => $value) {
31
					$applicationComponent->parameters->$value = $postValues['parameterValues'][$key];
32
				}
33
			}
34
35
			return $applicationComponent;
36
		} else {
37
			throw new \Exception('Trying to create application component with invalid data.');
38
		}
39
	}
40
}