Conditions | 9 |
Paths | 36 |
Total Lines | 62 |
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 |
||
42 | public function connect($newPassword=false) |
||
43 | { |
||
44 | $proto = \parse_url($this->host, PHP_URL_SCHEME); |
||
45 | if ($this->ssl || $proto == 'https') { |
||
46 | $this->ssl = true; |
||
47 | |||
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 | |||
95 | // get greeting |
||
96 | $greeting = $this->request(new \AfriCC\EPP\Frame\Hello()); |
||
97 | |||
98 | // login |
||
99 | $this->login($newPassword); |
||
|
|||
100 | |||
101 | // return greeting |
||
102 | return $greeting; |
||
103 | } |
||
104 | |||
177 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.