Completed
Push — master ( 6aa3fc...c7d0c1 )
by Alexei
9s
created

Mail   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 19 3
A delete() 0 9 1
1
<?php
2
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\Mail as Struct;
6
7
class Mail extends \PleskX\Api\Operator
8
{
9
10
    /**
11
     * @param string $name
12
     * @param integer $siteId
13
     * @param boolean $mailbox
14
     * @param string $password
15
     * @return Struct\Info
16
     */
17
    public function create($name, $siteId, $mailbox = false, $password = '')
18
    {
19
        $packet = $this->_client->getPacket();
20
        $info = $packet->addChild($this->_wrapperTag)->addChild('create');
21
22
        $filter = $info->addChild('filter');
23
        $filter->addChild('site-id', $siteId);
24
        $mailname = $filter->addChild('mailname');
25
        $mailname->addChild('name', $name);
26
        if ($mailbox) {
27
            $mailname->addChild('mailbox')->addChild('enabled', 'true');
28
        }
29
        if (!empty($password)) {
30
            $mailname->addChild('password')->addChild('value', $password);
31
        }
32
33
        $response = $this->_client->request($packet);
34
        return new Struct\Info($response->mailname);
35
    }
36
37
    /**
38
     * @param string $field
39
     * @param integer|string $value
40
     * @param integer $siteId
41
     * @return bool
42
     */
43
    public function delete($field, $value, $siteId)
44
    {
45
        $packet = $this->_client->getPacket();
46
        $filter = $packet->addChild($this->_wrapperTag)->addChild('remove')->addChild('filter');
47
        $filter->addChild('site-id', $siteId);
48
        $filter->addChild($field, $value);
49
        $response = $this->_client->request($packet);
50
        return 'ok' === (string)$response->status;
51
    }
52
53
}
54