These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | // Copyright 1999-2016. Parallels IP Holdings GmbH. |
||
3 | |||
4 | namespace PleskX\Api\Operator; |
||
5 | use PleskX\Api\Struct\ServicePlan as Struct; |
||
6 | |||
7 | |||
8 | class ServicePlan extends \PleskX\Api\Operator |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @param string $field |
||
13 | * @param integer|string $value |
||
14 | * @return Struct\Info |
||
15 | */ |
||
16 | public function get($field, $value) |
||
17 | { |
||
18 | $items = $this->_get($field, $value); |
||
19 | return reset($items); |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @return Struct\Info[] |
||
24 | */ |
||
25 | public function getAll() |
||
26 | { |
||
27 | return $this->_get(); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @param string|null $field |
||
32 | * @param integer|string|null $value |
||
33 | * @return Struct\Info|Struct\Info[] |
||
34 | */ |
||
35 | View Code Duplication | private function _get($field = null, $value = null) |
|
0 ignored issues
–
show
|
|||
36 | { |
||
37 | $packet = $this->_client->getPacket(); |
||
38 | $getTag = $packet->addChild($this->_wrapperTag)->addChild('get'); |
||
39 | |||
40 | $filterTag = $getTag->addChild('filter'); |
||
41 | if (!is_null($field)) { |
||
42 | $filterTag->addChild($field, $value); |
||
43 | } |
||
44 | |||
45 | $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
||
46 | |||
47 | $items = []; |
||
48 | foreach ($response->xpath('//result') as $xmlResult) { |
||
49 | $items[] = new Struct\Info($xmlResult); |
||
50 | } |
||
51 | |||
52 | return $items; |
||
53 | } |
||
54 | |||
55 | } |
||
56 |
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.