| Conditions | 4 |
| Paths | 4 |
| Total Lines | 131 |
| Code Lines | 88 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 87 | public static function getDefaultRules(): array |
||
| 88 | { |
||
| 89 | $defaultRTPFrom = PbxSettings::getValueByKey('RTPPortFrom'); |
||
| 90 | $defaultRTPTo = PbxSettings::getValueByKey('RTPPortTo'); |
||
| 91 | $defaultSIP = PbxSettings::getValueByKey('SIPPort'); |
||
| 92 | $defaultAMI = PbxSettings::getValueByKey('AMIPort'); |
||
| 93 | $defaultAJAM = PbxSettings::getValueByKey('AJAMPort'); |
||
| 94 | $defaultAJAMTLS = PbxSettings::getValueByKey('AJAMPortTLS'); |
||
| 95 | $defaultWeb = PbxSettings::getValueByKey('WEBPort'); |
||
| 96 | $defaultWebHttps = PbxSettings::getValueByKey('WEBHTTPSPort'); |
||
| 97 | $defaultSSH = PbxSettings::getValueByKey('SSHPort'); |
||
| 98 | |||
| 99 | |||
| 100 | $template = [ |
||
| 101 | 'SIP' => [ |
||
| 102 | 'rules' => [ |
||
| 103 | [ |
||
| 104 | 'portfrom' => $defaultSIP, |
||
| 105 | 'portto' => $defaultSIP, |
||
| 106 | 'protocol' => 'udp', |
||
| 107 | 'portFromKey' => 'SIPPort', |
||
| 108 | 'portToKey' => 'SIPPort', |
||
| 109 | ], |
||
| 110 | [ |
||
| 111 | 'portfrom' => $defaultSIP, |
||
| 112 | 'portto' => $defaultSIP, |
||
| 113 | 'protocol' => 'tcp', |
||
| 114 | 'portFromKey' => 'SIPPort', |
||
| 115 | 'portToKey' => 'SIPPort', |
||
| 116 | ], |
||
| 117 | [ |
||
| 118 | 'portfrom' => $defaultRTPFrom, |
||
| 119 | 'portto' => $defaultRTPTo, |
||
| 120 | 'protocol' => 'udp', |
||
| 121 | 'portFromKey' => 'RTPPortFrom', |
||
| 122 | 'portToKey' => 'RTPPortTo', |
||
| 123 | ], |
||
| 124 | ], |
||
| 125 | 'action' => 'allow', |
||
| 126 | 'shortName' => 'SIP & RTP', |
||
| 127 | ], |
||
| 128 | 'WEB' => [ |
||
| 129 | 'rules' => [ |
||
| 130 | [ |
||
| 131 | 'portfrom' => $defaultWeb, |
||
| 132 | 'portto' => $defaultWeb, |
||
| 133 | 'protocol' => 'tcp', |
||
| 134 | 'portFromKey' => 'WEBPort', |
||
| 135 | 'portToKey' => 'WEBPort', |
||
| 136 | ], |
||
| 137 | [ |
||
| 138 | 'portfrom' => $defaultWebHttps, |
||
| 139 | 'portto' => $defaultWebHttps, |
||
| 140 | 'protocol' => 'tcp', |
||
| 141 | 'portFromKey' => 'WEBHTTPSPort', |
||
| 142 | 'portToKey' => 'WEBHTTPSPort', |
||
| 143 | ], |
||
| 144 | ], |
||
| 145 | 'action' => 'allow', |
||
| 146 | 'shortName' => 'WEB', |
||
| 147 | |||
| 148 | ], |
||
| 149 | 'SSH' => [ |
||
| 150 | 'rules' => [ |
||
| 151 | [ |
||
| 152 | 'portfrom' => $defaultSSH, |
||
| 153 | 'portto' => $defaultSSH, |
||
| 154 | 'protocol' => 'tcp', |
||
| 155 | 'portFromKey' => 'SSHPort', |
||
| 156 | 'portToKey' => 'SSHPort', |
||
| 157 | ], |
||
| 158 | ], |
||
| 159 | 'action' => 'allow', |
||
| 160 | 'shortName' => 'SSH', |
||
| 161 | ], |
||
| 162 | 'AMI' => [ |
||
| 163 | 'rules' => [ |
||
| 164 | [ |
||
| 165 | 'portfrom' => $defaultAMI, |
||
| 166 | 'portto' => $defaultAMI, |
||
| 167 | 'protocol' => 'tcp', |
||
| 168 | 'portFromKey' => 'AMIPort', |
||
| 169 | 'portToKey' => 'AMIPort', |
||
| 170 | ], |
||
| 171 | ], |
||
| 172 | 'action' => 'allow', |
||
| 173 | 'shortName' => 'AMI', |
||
| 174 | ], |
||
| 175 | 'AJAM' => [ |
||
| 176 | 'rules' => [ |
||
| 177 | [ |
||
| 178 | 'portfrom' => $defaultAJAM, |
||
| 179 | 'portto' => $defaultAJAM, |
||
| 180 | 'protocol' => 'tcp', |
||
| 181 | 'portFromKey' => 'AJAMPort', |
||
| 182 | 'portToKey' => 'AJAMPort', |
||
| 183 | ], |
||
| 184 | [ |
||
| 185 | 'portfrom' => $defaultAJAMTLS, |
||
| 186 | 'portto' => $defaultAJAMTLS, |
||
| 187 | 'protocol' => 'tcp', |
||
| 188 | 'portFromKey' => 'AJAMPortTLS', |
||
| 189 | 'portToKey' => 'AJAMPortTLS', |
||
| 190 | ], |
||
| 191 | ], |
||
| 192 | 'action' => 'allow', |
||
| 193 | 'shortName' => 'AJAM', |
||
| 194 | ], |
||
| 195 | 'ICMP' => [ |
||
| 196 | 'rules' => [ |
||
| 197 | ['portfrom' => 0, 'portto' => 0, 'protocol' => 'icmp'], |
||
| 198 | ], |
||
| 199 | 'action' => 'allow', |
||
| 200 | 'shortName' => 'ICMP', |
||
| 201 | ], |
||
| 202 | ]; |
||
| 203 | |||
| 204 | |||
| 205 | //Add modules firewall rules |
||
| 206 | $configClassObj = new ConfigClass(); |
||
| 207 | $additionalRules = $configClassObj->hookModulesMethodWithArrayResult(ConfigClass::GET_DEFAULT_FIREWALL_RULES); |
||
| 208 | foreach ($additionalRules as $additionalRuleFromModule) { |
||
| 209 | if ($additionalRuleFromModule !== []) { |
||
| 210 | $additionalRuleFromModule = array_change_key_case($additionalRuleFromModule, CASE_UPPER); |
||
| 211 | foreach ($additionalRuleFromModule as $key => $rule) { |
||
| 212 | $template[$key] = $rule; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | return $template; |
||
| 218 | } |
||
| 264 |