Completed
Push — master ( c08a3e...9d69b9 )
by Angus
02:46
created

MY_Form_validation::not_equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1); defined('BASEPATH') or exit('No direct script access allowed');
2
3
class MY_Form_validation extends CI_Form_validation {
4
	private $user_tables;
5
6 61
	public function __construct() {
7 61
		parent::__construct();
8 61
		log_message('debug', "MY_Form_validation Class Initialized");
9
10 61
		$this->CI =& get_instance();
11 61
		$this->CI->config->load('ion_auth', TRUE);
12 61
		$this->user_tables = $this->CI->config->item('tables', 'ion_auth');
13 61
	}
14
15
	/*** User Validation ***/
16
	/**
17
	 * @param string $username
18
	 * @return bool
19
	 */
20 4
	public function valid_username(string $username) : bool {
21 4
		if(!($isValid = (bool) preg_match('/^[a-zA-Z0-9_-]{4,15}$/', $username))) {
22 3
			$this->set_message('valid_username', 'Username is invalid format.');
23
		}
24 4
		return $isValid;
25
	}
26
	/**
27
	 * @param string $password
28
	 * @return bool
29
	 */
30 3
	public function valid_password(string $password) : bool {
31 3
		if(!($isValid = $this->min_length($password, $this->CI->config->item('min_password_length', 'ion_auth')))) {
32 1
			$this->set_message('valid_password', 'The password is too short!');
33
		}
34 2
		elseif(!($isValid = $this->max_length($password, $this->CI->config->item('max_password_length', 'ion_auth')))) {
35 1
			$this->set_message('valid_password', 'The password is too long!');
36
		}
37 3
		return $isValid;
38
	}
39
	/**
40
	 * @param string $username
41
	 * @return bool
42
	 */
43 2
	public function is_unique_username(string $username) : bool {
44 2 View Code Duplication
		if(!($isValid = $this->is_unique($username, "{$this->user_tables['users']}.username"))) {
45 1
			$this->set_message('is_unique_username', 'The username already exists in our database.');
46
		}
47 2
		return $isValid;
48
	}
49
	/**
50
	 * @param string $email
51
	 * @return bool
52
	 */
53 2
	public function is_unique_email(string $email) : bool {
54 2 View Code Duplication
		if(!($isValid = $this->is_unique($email, "{$this->user_tables['users']}.email"))) {
55 1
			$this->set_message('is_unique_email', 'The email already exists in our database.');
56
		}
57 2
		return $isValid;
58
	}
59
60 3
	public function is_valid_json(string $json_string) : bool {
61 3
		$isValid = FALSE;
62 3
		if(json_decode($json_string) && json_last_error() === JSON_ERROR_NONE) {
63 1
			$isValid = TRUE;
64
		}
65 3
		return $isValid;
66
	}
67
68 5
	public function is_valid_tag_string(string $tag_string) : bool {
69 5
		return (bool) preg_match('/^[a-z0-9\\-_,:]{0,255}$/', $tag_string) && (count(preg_grep('/^mal:(?:[0-9]+|none)$/', explode(',', $tag_string))) <= 1);
70
	}
71
72 2
	public function is_valid_category(string $category) : bool {
73 2
		return in_array($category, array_keys($this->CI->Tracker->enabledCategories));
74
	}
75
76 2
	public function not_contains(string $haystack, string $needle) {
77 2
		return strpos($haystack, $needle) === FALSE;
78
	}
79
80 2
	public function not_equals(string $originalString, string $matchingString) {
81 2
		return $originalString !== $matchingString;
82 1
	}
83
84 2
	public function is_valid_option_value(string $value, string $option) : bool {
85
		if(!($isValid = in_array($value, $this->CI->User_Options->options[$option]['valid_options']))) {
86
			$this->set_message('is_valid_option_value', 'The %s field has an invalid value.');
87
		}
88
		return $isValid;
89
	}
90
91
	/** MISC FUNCTIONS **/
92 3
	/**
93 3
	 * @param string $ruleName
94 3
	 * @return bool
95 2
	 */
96
	public function isRuleValid(string $ruleName) : bool {
97 3
		$isValid = FALSE;
98
		if(is_string($ruleName) && $this->has_rule($ruleName)){
99
			$isValid = !in_array($ruleName, array_keys($this->error_array()), TRUE);
100
		}
101
		return $isValid;
102
	}
103
}
104