Mac   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A equals() 0 4 2
1
<?php
2
/**
3
 * Copyright 2016 Alexandru Guzinschi <[email protected]>.
4
 *
5
 * This software may be modified and distributed under the terms
6
 * of the MIT license. See the LICENSE file for details.
7
 */
8
namespace Gentle\Embeddable\Network;
9
10
use Gentle\Embeddable\Embeddable;
11
12
/**
13
 * @author Alexandru Guzinschi <[email protected]>
14
 */
15
final class Mac extends Embeddable
16
{
17
    /**
18
     * @param string $value
19
     *
20
     * @throws \InvalidArgumentException
21
     */
22 22
    public function __construct($value)
23
    {
24 22
        if (!is_string($value)) {
25 4
            throw new \InvalidArgumentException(sprintf('Expected string and got %s', gettype($value)));
26
        }
27
28 18
        if (false === filter_var($value, FILTER_VALIDATE_MAC)) {
29 12
            throw new \InvalidArgumentException('Invalid MAC address.');
30
        }
31
32 6
        $this->value = $value;
33 6
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function equals(Embeddable $object)
39
    {
40 3
        return get_class($object) === 'Gentle\Embeddable\Network\Mac' && $this->value === (string)$object;
41
    }
42
}
43