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

Gender::is_valid()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 4
nop 1
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