Conditions | 9 |
Paths | 36 |
Total Lines | 60 |
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 |
||
43 | public function connect($newPassword = false) |
||
44 | { |
||
45 | $proto = \parse_url($this->host, PHP_URL_SCHEME); |
||
46 | if ($this->ssl || $proto == 'https') { |
||
47 | $this->ssl = true; |
||
48 | } else { |
||
49 | $this->ssl = false; |
||
50 | } |
||
51 | |||
52 | $this->curl = curl_init($this->host); |
||
53 | |||
54 | if ($this->curl === false) { |
||
55 | throw new \Exception('Cannot initialize cURL extension'); |
||
56 | } |
||
57 | |||
58 | // set stream time out |
||
59 | curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout); |
||
60 | curl_setopt( |
||
61 | $this->curl, |
||
62 | CURLOPT_CONNECTTIMEOUT, |
||
63 | $this->connect_timeout |
||
64 | ); |
||
65 | |||
66 | // set necessary options |
||
67 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); |
||
68 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); |
||
69 | curl_setopt($this->curl, CURLOPT_HEADER, false); |
||
70 | |||
71 | // cookies |
||
72 | curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookiejar); |
||
73 | curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookiejar); |
||
74 | |||
75 | // certs |
||
76 | if ($this->ssl) { |
||
77 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, true); |
||
78 | curl_setopt($this->curl, CURLOPT_SSLKEYTYPE, 'PEM'); |
||
79 | |||
80 | if ($this->ca_cert) { |
||
81 | curl_setopt($this->curl, CURLOPT_CAINFO, $this->ca_cert); |
||
82 | } |
||
83 | if ($this->pk_cert) { |
||
84 | curl_setopt($this->curl, CURLOPT_SSLKEY, $this->pk_cert); |
||
85 | } |
||
86 | if ($this->local_cert) { |
||
87 | curl_setopt($this->curl, CURLOPT_SSLCERT, $this->local_cert); |
||
88 | } |
||
89 | if ($this->passphrase) { |
||
90 | curl_setopt($this->curl, CURLOPT_SSLCERTPASSWD, $this->passphrase); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | // get greeting |
||
95 | $greeting = $this->request(new \AfriCC\EPP\Frame\Hello()); |
||
96 | |||
97 | // login |
||
98 | $this->login($newPassword); |
||
99 | |||
100 | // return greeting |
||
101 | return $greeting; |
||
102 | } |
||
103 | |||
177 |