| Conditions | 8 |
| Paths | 8 |
| Total Lines | 78 |
| Code Lines | 53 |
| 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 |
||
| 105 | private function writeProcess($instanceId, $poolId, PoolConfig $poolConfig, array $processConfig) |
||
| 106 | { |
||
| 107 | $tlsDir = sprintf('/etc/openvpn/tls/%s/%s', $instanceId, $poolId); |
||
| 108 | |||
| 109 | $rangeIp = new IP($processConfig['range']); |
||
| 110 | $range6Ip = new IP($processConfig['range6']); |
||
| 111 | |||
| 112 | // static options |
||
| 113 | $serverConfig = [ |
||
| 114 | '# OpenVPN Server Configuration', |
||
| 115 | 'verb 3', |
||
| 116 | 'dev-type tun', |
||
| 117 | 'user openvpn', |
||
| 118 | 'group openvpn', |
||
| 119 | 'topology subnet', |
||
| 120 | 'persist-key', |
||
| 121 | 'persist-tun', |
||
| 122 | 'keepalive 10 60', |
||
| 123 | 'comp-lzo no', |
||
| 124 | 'remote-cert-tls client', |
||
| 125 | 'tls-version-min 1.2', |
||
| 126 | 'tls-cipher TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA', |
||
| 127 | 'auth SHA256', |
||
| 128 | 'cipher AES-256-CBC', |
||
| 129 | 'client-connect /usr/sbin/vpn-server-api-client-connect', |
||
| 130 | 'client-disconnect /usr/sbin/vpn-server-api-client-disconnect', |
||
| 131 | 'push "comp-lzo no"', |
||
| 132 | 'push "explicit-exit-notify 3"', |
||
| 133 | sprintf('ca %s/ca.crt', $tlsDir), |
||
| 134 | sprintf('cert %s/server.crt', $tlsDir), |
||
| 135 | sprintf('key %s/server.key', $tlsDir), |
||
| 136 | sprintf('dh %s/dh.pem', $tlsDir), |
||
| 137 | sprintf('tls-auth %s/ta.key 0', $tlsDir), |
||
| 138 | sprintf('server %s %s', $rangeIp->getNetwork(), $rangeIp->getNetmask()), |
||
| 139 | sprintf('server-ipv6 %s', $range6Ip->getAddressPrefix()), |
||
| 140 | sprintf('max-clients %d', $rangeIp->getNumberOfHosts() - 1), |
||
| 141 | sprintf('script-security %d', $poolConfig->v('twoFactor') ? 3 : 2), |
||
| 142 | sprintf('dev %s', $processConfig['dev']), |
||
| 143 | sprintf('port %d', $processConfig['port']), |
||
| 144 | sprintf('management %s %d', $processConfig['managementIp'], $processConfig['managementPort']), |
||
| 145 | sprintf('setenv INSTANCE_ID %s', $instanceId), |
||
| 146 | sprintf('setenv POOL_ID %s', $poolId), |
||
| 147 | sprintf('proto %s', 'tcp' === $processConfig['proto'] ? 'tcp-server' : 'udp'), |
||
| 148 | sprintf('local %s', 'tcp' === $processConfig['proto'] ? $processConfig['managementIp'] : $poolConfig->v('listen')), |
||
| 149 | |||
| 150 | // increase the renegotiation time to 8h from the default of 1h when |
||
| 151 | // using 2FA, otherwise the user would be asked for the 2FA key every |
||
| 152 | // hour |
||
| 153 | sprintf('reneg-sec %d', $poolConfig->v('twoFactor') ? 28800 : 3600), |
||
| 154 | ]; |
||
| 155 | |||
| 156 | if (!$poolConfig->v('enableLog')) { |
||
| 157 | $serverConfig[] = 'log /dev/null'; |
||
| 158 | } |
||
| 159 | |||
| 160 | if ('tcp' === $processConfig['proto']) { |
||
| 161 | $serverConfig[] = 'tcp-nodelay'; |
||
| 162 | } |
||
| 163 | |||
| 164 | if ($poolConfig->v('twoFactor')) { |
||
| 165 | $serverConfig[] = 'auth-user-pass-verify /usr/sbin/vpn-server-api-verify-otp via-env'; |
||
| 166 | } |
||
| 167 | |||
| 168 | // Routes |
||
| 169 | $serverConfig = array_merge($serverConfig, self::getRoutes($poolConfig)); |
||
| 170 | |||
| 171 | // DNS |
||
| 172 | $serverConfig = array_merge($serverConfig, self::getDns($poolConfig)); |
||
| 173 | |||
| 174 | // Client-to-client |
||
| 175 | $serverConfig = array_merge($serverConfig, self::getClientToClient($poolConfig)); |
||
| 176 | |||
| 177 | sort($serverConfig, SORT_STRING); |
||
| 178 | |||
| 179 | $configFile = sprintf('%s/%s', $this->vpnConfigDir, $processConfig['configName']); |
||
| 180 | |||
| 181 | FileIO::writeFile($configFile, implode(PHP_EOL, $serverConfig), 0600); |
||
| 182 | } |
||
| 183 | |||
| 256 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.