PeriodTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
set() 0 1 ?
A appendPeriod() 0 9 2
1
<?php
2
3
/**
4
 * This file is part of the php-epp2 library.
5
 *
6
 * (c) Gunter Grodotzki <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
namespace AfriCC\EPP;
13
14
use Exception;
15
16
/**
17
 * a IP address trait to give common functionality needed to for addr elements
18
 */
19
trait PeriodTrait
20
{
21
    /**
22
     * Set value to path
23
     *
24
     * @param string $path
25
     * @param mixed $value
26
     *
27
     * @return \DOMElement
28
     */
29
    abstract public function set($path = null, $value = null);
30
31
    protected function appendPeriod($path, $period)
32
    {
33
        $matches = [];
34
        if (preg_match('/^(\d+)([a-z])$/i', $period, $matches)) {
35
            $this->set(sprintf($path, $matches[2]), $matches[1]);
36
        } else {
37
            throw new Exception(sprintf('%s is not a valid period', $period));
38
        }
39
    }
40
}
41