Completed
Push — master ( 40d438...b00d7c )
by Alexei
02:06
created

SecretKey::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\SecretKey as Struct;
6
7
class SecretKey extends \PleskX\Api\Operator
8
{
9
10
    protected $_wrapperTag = 'secret_key';
11
12
    /**
13
     * @param string $ipAddress
14
     * @return string
15
     */
16
    public function create($ipAddress)
17
    {
18
        $packet = $this->_client->getPacket();
19
        $packet->addChild($this->_wrapperTag)->addChild('create')->addChild('ip_address', $ipAddress);
20
        $response = $this->_client->request($packet);
21
        return (string)$response->key;
22
    }
23
24
    /**
25
     * @param string $keyId
26
     * @return bool
27
     */
28
    public function delete($keyId)
29
    {
30
        return $this->_delete('key', $keyId, 'delete');
31
    }
32
33
    /**
34
     * @param string $keyId
35
     * @return Struct\Info
36
     */
37
    public function get($keyId)
38
    {
39
        $items = $this->_get($keyId);
40
        return reset($items);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression reset($items); of type PleskX\Api\Struct\SecretKey\Info|false adds false to the return on line 40 which is incompatible with the return type documented by PleskX\Api\Operator\SecretKey::get of type PleskX\Api\Struct\SecretKey\Info. It seems like you forgot to handle an error condition.
Loading history...
41
    }
42
43
    /**
44
     * @return Struct\Info[]
45
     */
46
    public function getAll()
47
    {
48
        return $this->_get();
49
    }
50
51
    /**
52
     * @param string $field
0 ignored issues
show
Bug introduced by
There is no parameter named $field. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
53
     * @param integer|string $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
     * @return Struct\Info[]
55
     */
56 View Code Duplication
    public function _get($keyId = 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...
57
    {
58
        $packet = $this->_client->getPacket();
59
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get_info');
60
61
        $filterTag = $getTag->addChild('filter');
62
        if (!is_null($keyId)) {
63
            $filterTag->addChild('key', $keyId);
64
        }
65
66
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
67
68
        $items = [];
69
        foreach ($response->xpath('//result') as $xmlResult) {
70
            $items[] = new Struct\Info($xmlResult->key_info);
71
        }
72
73
        return $items;
74
    }
75
76
}
77