Completed
Push — master ( 65a7d4...0d1ee8 )
by Jacques
14:58
created

Gender   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B is_valid() 0 16 5
1
<?php
2
/**
3
 * Identification Validation
4
 *
5
 * @author    Jacques Marneweck <[email protected]>
6
 * @copyright 2015-2017 Jacques Marneweck.  All rights strictly reserved.
7
 * @license   MIT
8
 */
9
10
namespace Jacques\Validators;
11
12
use Carbon\Carbon;
13
14
class Gender
15
{
16
    /**
17
     * Checks that the users gender matches either f or m.
18
     *
19
     * gender is either:
20
     *   - f - female
21
     *   - m - gender
22
     *
23
     * @param string  $gender
24
     *
25
     * @throws \InvalidArgumentException
26
     *
27
     * @return bool   true if is valid else false
28
     */
29
    public static function is_valid($gender = null)
30
    {
31
        if (is_null($gender)) {
32
            throw new \InvalidArgumentException('Please enter a valid gender.');
33
        }
34
35
        if (empty($gender) || strlen($gender) > 1) {
36
            return false;
37
        }
38
39
        if (is_numeric($gender)) {
40
            return false;
41
        }
42
43
        return in_array($gender, ['f', 'm']);
44
    }
45
}
46