Completed
Pull Request — master (#67)
by
unknown
01:19
created

Future   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setFuture() 0 8 2
A setPeriod() 0 4 1
A setRegistrant() 0 4 1
A setAuthInfo() 0 10 2
1
<?php
2
3
namespace AfriCC\EPP\Extension\NASK\Create;
4
5
use AfriCC\EPP\Frame\Command\Create as CreateCommand;
6
use AfriCC\EPP\PeriodTrait;
7
use AfriCC\EPP\Random;
8
use AfriCC\EPP\Validator;
9
use Exception;
10
11
class Future extends CreateCommand
12
{
13
    use PeriodTrait;
14
15
    /**
16
     * Set domain name for future (option)
17
     *
18
     * @param string $domain Domain Name
19
     *
20
     * @throws Exception on incorrect domain name
21
     */
22
    public function setFuture($domain)
23
    {
24
        if (!Validator::isHostname($domain)) {
25
            throw new Exception(sprintf('%s is not a valid domain name', $domain));
26
        }
27
28
        $this->set('future:name', $domain);
29
    }
30
31
    /**
32
     * Set future period
33
     *
34
     * Set period for which to create Future. Usually that will be 3y
35
     *
36
     * @param string $period Period ending with with y or m
37
     */
38
    public function setPeriod($period)
39
    {
40
        $this->appendPeriod('future:period[@unit=\'%s\']', $period);
41
    }
42
43
    /**
44
     * Set future registrant
45
     *
46
     * @param string $registrant registrant ContactID
47
     */
48
    public function setRegistrant($registrant)
49
    {
50
        $this->set('future:registrant', $registrant);
51
    }
52
53
    /**
54
     * Set future AuthInfo, generate if passed null
55
     *
56
     * @param string $pw AuthInfo code
57
     *
58
     * @return string  AuthInfo code
59
     */
60
    public function setAuthInfo($pw = null)
61
    {
62
        if ($pw === null) {
63
            $pw = Random::auth(12);
64
        }
65
66
        $this->set('future:authInfo/future:pw', $pw);
67
68
        return $pw;
69
    }
70
}
71