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

UserFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B createUserFromPostValues() 0 25 5
1
<?php
2
/**
3
 * User: jensk
4
 * Date: 13-3-2017
5
 * Time: 17:01
6
 */
7
8
namespace library\storage\factories;
9
10
11
class UserFactory
12
{
13
	/**
14
	 * Create user from POST values
15
	 *
16
	 * @param $postValues
17
	 *
18
	 * @return \stdClass
19
	 * @throws \Exception
20
	 */
21
	public static function createUserFromPostValues($postValues)
22
	{
23
		if (isset($postValues['username'])) {
24
			$user = new \stdClass();
25
			$user->username = $postValues['username'];
26
			$user->slug = slugify($postValues['username']);
27
			$user->rights = array();
28
			if (isset($postValues['rights'])) {
29
				$user->rights = $postValues['rights'];
30
			}
31
32
			if (isset($postValues['password']) && empty($postValues['password']) === false) {
33
				$crypt = new Crypt();
34
				$user->password = $crypt->encrypt($postValues['password'], 16);
35
				$user->salt = $crypt->getLastSalt();
36
			} else {
37
				$user->password = $postValues['passHash'];
38
				$user->salt = $postValues['salt'];
39
			}
40
41
			return $user;
42
		} else {
43
			throw new \Exception('Trying to create user with invalid data.');
44
		}
45
	}
46
}