PeriodTrait::appendPeriod()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 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