Conditions | 24 |
Paths | 1288 |
Total Lines | 91 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 defined('SYSPATH') or die('No direct script access.'); |
||
80 | public function process() |
||
81 | { |
||
82 | $post_url = ($this->test_mode) |
||
83 | ? $this->fields['payment_url'].$this->fields['script'] // Test mode URL |
||
84 | : $this->fields['payment_url'].$this->fields['script']; // Live URL |
||
85 | |||
86 | $pay_to_email = ($this->test_mode) |
||
87 | ? $this->fields['test_pay_to_email'] // Test mode email |
||
88 | : $this->fields['pay_to_email']; // Live email |
||
89 | |||
90 | $password = ($this->test_mode) |
||
91 | ? $this->fields['test_password'] // Test mode password |
||
92 | : $this->fields['password']; // Live password |
||
93 | |||
94 | $this->fields['postdata']['action'] = $this->fields['action']; |
||
95 | |||
96 | $config = Kohana::config('payment.MoneyBookers'); |
||
97 | |||
98 | if ($this->fields['script'] == $config['refund_script'] && $this->fields['action'] == "prepare") { |
||
99 | $this->fields['postdata']['email'] = $pay_to_email; |
||
100 | $this->fields['postdata']['password'] = md5($password); |
||
101 | $this->fields['postdata']['trn_id'] = $this->fields['trn_id']; |
||
102 | } elseif ($this->fields['action'] == "prepare") { |
||
103 | $this->fields['postdata']['email'] = $pay_to_email; |
||
104 | $this->fields['postdata']['password'] = md5($password); |
||
105 | $this->fields['postdata']['amount'] = $this->fields['amount']; |
||
106 | $this->fields['postdata']['currency'] = $this->fields['currency']; |
||
107 | $this->fields['postdata']['frn_trn_id'] = $this->fields['trn_id']; |
||
108 | $this->fields['postdata']['rec_payment_id'] = $this->fields['rec_payment_id']; |
||
109 | } elseif ($this->fields['action'] == "refund") { |
||
110 | $this->fields['postdata']['sid'] = $this->fields['sid']; |
||
111 | } elseif ($this->fields['action'] == "request") { |
||
112 | $this->fields['postdata']['sid'] = $this->fields['sid']; |
||
113 | } elseif ($this->fields['action'] == "status_od") { |
||
114 | $this->fields['postdata']['email'] = $pay_to_email; |
||
115 | $this->fields['postdata']['password'] = md5($password); |
||
116 | $this->fields['postdata']['trn_id'] = $this->fields['trn_id']; |
||
117 | } elseif ($this->fields['action'] == "status_trn") { |
||
118 | $this->fields['postdata']['email'] = $pay_to_email; |
||
119 | $this->fields['postdata']['password'] = md5($password); |
||
120 | $this->fields['postdata']['mb_trn_id'] = $this->fields['trn_id']; |
||
121 | } |
||
122 | |||
123 | $ch = curl_init($post_url); |
||
124 | |||
125 | curl_setopt($ch, CURLOPT_FAILONERROR, true); |
||
126 | // the following disallows redirects |
||
127 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); |
||
128 | // next we return into a variable |
||
129 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
130 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); |
||
131 | curl_setopt($ch, CURLOPT_POST, 1); |
||
132 | |||
133 | // Set the curl POST fields |
||
134 | curl_setopt($ch, CURLOPT_POSTFIELDS, $this->fields['postdata']); |
||
135 | |||
136 | // Execute post and get results |
||
137 | $response = curl_exec($ch); |
||
138 | // Get error messages. |
||
139 | $info = curl_getinfo($ch); |
||
140 | |||
141 | curl_close($ch); |
||
142 | |||
143 | if (!$response) { |
||
144 | return false; |
||
145 | } |
||
146 | |||
147 | if ($this->fields['action'] != "status_od" && $this->fields['action'] != "status_trn") { |
||
148 | $xml = simplexml_load_string($response); |
||
149 | } |
||
150 | |||
151 | if ($this->fields['action'] == "prepare") { |
||
152 | return ($xml->{'sid'} != "") ? $xml : false; |
||
153 | } |
||
154 | |||
155 | if ($this->fields['action'] == "request") { |
||
156 | return ($xml->{'transaction'}->{'status_msg'} == "processed") ? $xml : false; |
||
157 | } |
||
158 | |||
159 | if ($this->fields['action'] == "status_od") { |
||
160 | return (strstr($response, "Status: 0")) ? true : false; |
||
161 | } |
||
162 | |||
163 | if ($this->fields['action'] == "status_trn") { |
||
164 | return (strstr($response, "OK")) ? $response : false; |
||
165 | } |
||
166 | |||
167 | if ($this->fields['action'] == "refund") { |
||
168 | return ($xml->{'status'} == 2) ? $xml : false; |
||
169 | } |
||
170 | } |
||
171 | } // End Payment_MoneyBookers_Driver Class |
||
172 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: