Completed
Push — master ( 04c3fa...9e32f0 )
by Thomas
09:51
created

UserValidator::getValidations()   C

Complexity

Conditions 7
Paths 32

Size

Total Lines 48
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 48
rs 6.7272
cc 7
eloc 28
nc 32
nop 0
1
<?php
2
namespace keeko\core\validator;
3
4
use keeko\framework\validator\ModelValidator;
5
use keeko\framework\preferences\SystemPreferences;
6
7
class UserValidator extends ModelValidator {
8
	
9
	protected function getValidations() {
10
		$prefs = $this->service->getPreferenceLoader()->getSystemPreferences();
11
		
12
		$validations = [];
13
		
14
		if ($prefs->getUserLogin() != SystemPreferences::LOGIN_EMAIL) {
15
			$validations[] = [
16
				'constraint' => 'notnull',
17
				'column' => 'user_name'
18
			];
19
		}
20
		
21
		if ($prefs->getUserEmail() || $prefs->getUserLogin() != SystemPreferences::LOGIN_USERNAME) {
22
			$validations[] = [
23
				'constraint' => 'email',
24
				'column' => 'email'
25
			];
26
		}
27
28
		if ($prefs->getUserNames()) {
29
			$validations[] = [
30
				'constraint' => 'notnull',
31
				'column' => 'given_name'
32
			];
33
			
34
			$validations[] = [
35
				'constraint' => 'notnull',
36
				'column' => 'family_name'
37
			];
38
		}
39
		
40
		if ($prefs->getUserBirth()) {
41
			$validations[] = [
42
				'constraint' => 'required',
43
				'column' => 'birth'
44
			];
45
		}
46
		
47
		if ($prefs->getUserSex()) {
48
			$validations[] = [
49
				'constraint' => 'choice',
50
				'column' => 'sex',
51
				'choices' => [0, 1]
52
			];
53
		}
54
		
55
		return $validations;
56
	}
57
}