| Conditions | 11 |
| Paths | 17 |
| Total Lines | 47 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 72 | * @throws Exception |
||
| 73 | * @return array : attributes : address, address6, name |
||
| 74 | */ |
||
| 75 | public function getHostGroupByName($name) |
||
| 76 | { |
||
| 77 | return $this->standardQuery( |
||
| 78 | 'hostgroup', |
||
| 79 | 'match("*' . $name . '*",hostgroup.name)', |
||
| 80 | array('name','display_name') |
||
| 81 | |||
| 82 | ); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** Get services from host in API |
||
| 86 | * |
||
| 87 | * @throws Exception |
||
| 88 | * @param $id string host name |
||
| 89 | * @return array display_name (of service), service_object_id |
||
| 90 | */ |
||
| 91 | public function getServicesByHostid(string $id, bool $active = TRUE, bool $passive_svc = TRUE) |
||
| 92 | { |
||
| 93 | $filter = 'match("' . $id . '!*", service.__name)'; |
||
| 94 | if ($active === TRUE) |
||
| 95 | { |
||
| 96 | $filter .= ' && service.active==true'; |
||
| 97 | } |
||
| 98 | if ($passive_svc === TRUE) |
||
| 99 | { |
||
| 100 | $filter .= ' && service.enable_passive_checks==true'; |
||
| 101 | } |
||
| 102 | return $this->standardQuery( |
||
| 103 | 'service', |
||
| 104 | $filter, |
||
| 105 | array('__name','name','display_name','active') |
||
| 106 | ); |
||
| 107 | |||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * return array of host by IP (4 or 6) or name |
||
| 112 | * @param string $group Host group name |
||
| 113 | * @throws Exception |
||
| 114 | * @return array objects : array('name','display_name') |
||
| 115 | */ |
||
| 116 | public function getHostsByGroup(string $group) |
||
| 117 | { |
||
| 118 | return $this->standardQuery( |
||
| 119 | 'host', |
||
| 161 |