Completed
Push — master ( 3fe2ca...5f8097 )
by Ronan
01:59
created

Mac::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace IsoCodes;
4
5
/**
6
 * Class Mac.
7
 *
8
 * @author Sullivan Senechal <[email protected]>
9
 */
10
class Mac implements IsoCodeInterface
11
{
12
    /**
13
     * MAC address validator.
14
     *
15
     * Could be separated by hyphens or colons.
16
     * Could be both lowercase or uppercase letters.
17
     * Mixed upper/lower cases and hyphens/colons are not allowed.
18
     *
19
     * @link http://en.wikipedia.org/wiki/MAC_address#Notational_conventions
20
     *
21
     * @param string $mac
22
     *
23
     * @return bool
24
     */
25
    public static function validate($mac)
26
    {
27
        $pattern = '/^(([a-f0-9]{2}-){5}[a-f0-9]{2}|([A-F0-9]{2}-){5}[A-Z0-9]{2}|([a-f0-9]{2}:){5}[a-z0-9]{2}|([A-F0-9]{2}:){5}[A-Z0-9]{2})$/';
28
29
        return (bool) preg_match($pattern, $mac);
30
    }
31
}
32