Contact::__call()   B
last analyzed

Complexity

Conditions 6
Paths 13

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8977
c 0
b 0
f 0
cc 6
nc 13
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
 * TODO: This class can generate content not compliant with RFC 5733. I wonder if we should force it to be compliant and rely on extensions for non-compliant registrars.
12
 */
13
14
namespace AfriCC\EPP\Frame\Command\Update;
15
16
use AfriCC\EPP\ContactTrait;
17
use AfriCC\EPP\Frame\Command\Update as UpdateCommand;
18
19
/**
20
 * @see http://tools.ietf.org/html/rfc5733#section-3.2.5
21
 */
22
class Contact extends UpdateCommand
23
{
24
    use ContactTrait;
25
26
    public function setId($id)
27
    {
28
        $this->appendId('contact:id', $id);
29
    }
30
31
    private function setName($mode, $name)
32
    {
33
        $this->appendName(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:name', $mode), $name);
34
    }
35
36
    private function setOrganization($mode, $org)
37
    {
38
        $this->appendOrganization(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:org', $mode), $org);
39
    }
40
41
    private function addStreet($mode, $street)
42
    {
43
        $this->appendStreet(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:addr/contact:street[]', $mode), $street);
44
    }
45
46
    private function setCity($mode, $city)
47
    {
48
        $this->appendCity(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:addr/contact:city', $mode), $city);
49
    }
50
51
    private function setProvince($mode, $sp)
52
    {
53
        $this->appendProvince(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:addr/contact:sp', $mode), $sp);
54
    }
55
56
    private function setPostalCode($mode, $pc)
57
    {
58
        $this->appendPostalCode(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:addr/contact:pc', $mode), $pc);
59
    }
60
61
    private function setCountryCode($mode, $cc)
62
    {
63
        $this->appendCountryCode(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:addr/contact:cc', $mode), $cc);
64
    }
65
66
    private function setVoice($mode, $voice, $extension = null)
67
    {
68
        $this->appendVoice(sprintf('contact:%s/contact:voice', $mode), $voice, $extension);
69
    }
70
71
    private function setFax($mode, $fax, $extension = null)
72
    {
73
        $this->appendFax(sprintf('contact:%s/contact:fax', $mode), $fax, $extension);
74
    }
75
76
    private function setEmail($mode, $email)
77
    {
78
        $this->appendEmail(sprintf('contact:%s/contact:email', $mode), $email);
79
    }
80
81
    private function setAuthInfo($mode, $pw = null)
82
    {
83
        return $this->appendAuthInfo(sprintf('contact:%s/contact:authInfo/contact:pw', $mode), $pw);
84
    }
85
86
    private function addDisclose($mode, $value, $flag = 0)
87
    {
88
        $this->appendDisclose(sprintf('contact:%s/contact:disclose[@flag=\'%d\']/contact:%s', $mode, $flag, $value));
89
    }
90
91
    private function setStatus($mode, $status)
92
    {
93
        $this->set(sprintf('contact:%s/contact:status[@s=\'%s\']', $mode, $status));
94
    }
95
96
    public function __call($name, $arguments)
97
    {
98
        if (strpos($name, 'add') === 0) {
99
            array_unshift($arguments, 'add');
100
            $method_name = substr($name, 3);
101
        } elseif (strpos($name, 'remove') === 0) {
102
            array_unshift($arguments, 'rem');
103
            $method_name = substr($name, 6);
104
        } elseif (strpos($name, 'change') === 0) {
105
            array_unshift($arguments, 'chg');
106
            $method_name = substr($name, 6);
107
        } else {
108
            return;
109
        }
110
111
        if (strpos($method_name, 'Add') === 0) {
112
            $method_name = lcfirst($method_name);
113
        } else {
114
            $method_name = 'set' . $method_name;
115
        }
116
117
        if (is_callable([$this, $method_name])) {
118
            return call_user_func_array([$this, $method_name], $arguments);
119
        }
120
    }
121
}
122