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

Mac   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 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