Completed
Pull Request — master (#27)
by Dominik
03:07
created

SiteAlias::create()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 8.8571
cc 5
eloc 11
nc 2
nop 2
1
<?php
2
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\SiteAlias as Struct;
6
7
class SiteAlias extends \PleskX\Api\Operator
8
{
9
    /**
10
     * @param array $properties
11
     * @param array $preferences
12
     * @return Struct\Info
13
     */
14
    public function create(array $properties, array $preferences = [])
15
    {
16
        $packet = $this->_client->getPacket();
17
        $info = $packet->addChild($this->_wrapperTag)->addChild('create');
18
19
        if (count($preferences) > 0) {
20
            $prefs = $info->addChild('pref');
21
22
            foreach ($preferences as $key => $value) {
23
                $prefs->addChild($key, is_bool($value) ? ($value ? 1 : 0) : $value);
24
            }
25
        }
26
27
        $info->addChild('site-id', $properties['site-id']);
28
        $info->addChild('name', $properties['name']);
29
30
        $response = $this->_client->request($packet);
31
        return new Struct\Info($response);
32
    }
33
}
34