Completed
Push — master ( 0af60a...7c7995 )
by Alexei
01:21
created

SiteAlias::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
// Copyright 1999-2021. Plesk International GmbH.
3
4
namespace PleskX\Api\Operator;
5
6
use PleskX\Api\Struct\SiteAlias as Struct;
7
8
class SiteAlias extends \PleskX\Api\Operator
9
{
10
    /**
11
     * @param array $properties
12
     * @param array $preferences
13
     *
14
     * @return Struct\Info
15
     */
16
    public function create(array $properties, array $preferences = [])
17
    {
18
        $packet = $this->_client->getPacket();
19
        $info = $packet->addChild($this->_wrapperTag)->addChild('create');
20
21
        if (count($preferences) > 0) {
22
            $prefs = $info->addChild('pref');
23
24
            foreach ($preferences as $key => $value) {
25
                $prefs->addChild($key, is_bool($value) ? ($value ? 1 : 0) : $value);
26
            }
27
        }
28
29
        $info->addChild('site-id', $properties['site-id']);
30
        $info->addChild('name', $properties['name']);
31
32
        $response = $this->_client->request($packet);
33
34
        return new Struct\Info($response);
35
    }
36
37
    /**
38
     * @param string $field
39
     * @param int|string $value
40
     *
41
     * @return bool
42
     */
43
    public function delete($field, $value)
44
    {
45
        return $this->_delete($field, $value, 'delete');
46
    }
47
48
    /**
49
     * @param string $field
50
     * @param int|string $value
51
     *
52
     * @return Struct\GeneralInfo
53
     */
54
    public function get($field, $value)
55
    {
56
        $items = $this->getAll($field, $value);
57
58
        return reset($items);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression reset($items); of type PleskX\Api\Struct\SiteAlias\GeneralInfo|false adds false to the return on line 58 which is incompatible with the return type documented by PleskX\Api\Operator\SiteAlias::get of type PleskX\Api\Struct\SiteAlias\GeneralInfo. It seems like you forgot to handle an error condition.
Loading history...
59
    }
60
61
    /**
62
     * @param string $field
63
     * @param int|string $value
64
     *
65
     * @return Struct\GeneralInfo[]
66
     */
67 View Code Duplication
    public function getAll($field = null, $value = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $packet = $this->_client->getPacket();
70
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
71
72
        $filterTag = $getTag->addChild('filter');
73
        if (!is_null($field)) {
74
            $filterTag->addChild($field, $value);
75
        }
76
77
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
78
        $items = [];
79
        foreach ($response->xpath('//result') as $xmlResult) {
80
            $item = new Struct\GeneralInfo($xmlResult->info);
81
            $items[] = $item;
82
        }
83
84
        return $items;
85
    }
86
}
87