Conditions | 12 |
Paths | 746 |
Total Lines | 96 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 156 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
49 | public function send( |
||
50 | $url, |
||
51 | $operation = '', |
||
52 | $action = '', |
||
53 | $soapver = SOAP_1_2, |
||
54 | $parameters = [], |
||
55 | $namespaces = [], |
||
56 | $request = '', |
||
57 | $soapheader = null |
||
58 | ) { |
||
59 | //check or create key files |
||
60 | //before send request |
||
61 | $this->saveTemporarilyKeyFiles(); |
||
62 | $response = ''; |
||
63 | $envelope = $this->makeEnvelopeSoap( |
||
64 | $request, |
||
65 | $namespaces, |
||
66 | $soapver, |
||
67 | $soapheader |
||
68 | ); |
||
69 | $msgSize = strlen($envelope); |
||
70 | $parameters = [ |
||
71 | "Content-Type: application/soap+xml;charset=utf-8;", |
||
72 | "Content-length: $msgSize" |
||
73 | ]; |
||
74 | if (!empty($action)) { |
||
75 | $parameters[0] .= "action=$action"; |
||
76 | } |
||
77 | $this->requestHead = implode("\n", $parameters); |
||
78 | $this->requestBody = $envelope; |
||
79 | |||
80 | try { |
||
81 | $oCurl = curl_init(); |
||
82 | $this->setCurlProxy($oCurl); |
||
83 | curl_setopt($oCurl, CURLOPT_URL, $url); |
||
84 | curl_setopt($oCurl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
||
85 | //curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT_MS, 1); |
||
86 | //curl_setopt($oCurl, CURLOPT_TIMEOUT_MS, 1); |
||
87 | curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, $this->soaptimeout); |
||
88 | curl_setopt($oCurl, CURLOPT_TIMEOUT, $this->soaptimeout + 20); |
||
89 | curl_setopt($oCurl, CURLOPT_HEADER, 1); |
||
90 | curl_setopt($oCurl, CURLOPT_HTTP_VERSION, $this->httpver); |
||
91 | curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, 0); |
||
92 | curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, 0); |
||
93 | if (!$this->disablesec) { |
||
94 | curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, 2); |
||
95 | if (is_file($this->casefaz)) { |
||
96 | curl_setopt($oCurl, CURLOPT_CAINFO, $this->casefaz); |
||
97 | } |
||
98 | } |
||
99 | curl_setopt($oCurl, CURLOPT_SSLVERSION, $this->soapprotocol); |
||
100 | curl_setopt($oCurl, CURLOPT_SSLCERT, $this->tempdir . $this->certfile); |
||
101 | curl_setopt($oCurl, CURLOPT_SSLKEY, $this->tempdir . $this->prifile); |
||
102 | if (!empty($this->temppass)) { |
||
103 | curl_setopt($oCurl, CURLOPT_KEYPASSWD, $this->temppass); |
||
104 | } |
||
105 | curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); |
||
106 | if (!empty($envelope)) { |
||
107 | curl_setopt($oCurl, CURLOPT_POST, 1); |
||
108 | curl_setopt($oCurl, CURLOPT_POSTFIELDS, $envelope); |
||
109 | curl_setopt($oCurl, CURLOPT_HTTPHEADER, $parameters); |
||
110 | } |
||
111 | $response = curl_exec($oCurl); |
||
112 | $this->soaperror = curl_error($oCurl); |
||
113 | $this->soaperror_code = curl_errno($oCurl); |
||
114 | $ainfo = curl_getinfo($oCurl); |
||
115 | if (is_array($ainfo)) { |
||
116 | $this->soapinfo = $ainfo; |
||
117 | } |
||
118 | $headsize = curl_getinfo($oCurl, CURLINFO_HEADER_SIZE); |
||
119 | $httpcode = curl_getinfo($oCurl, CURLINFO_HTTP_CODE); |
||
120 | curl_close($oCurl); |
||
121 | $this->responseHead = trim(substr($response, 0, $headsize)); |
||
122 | $this->responseBody = trim(substr($response, $headsize)); |
||
123 | $this->saveDebugFiles( |
||
124 | $operation, |
||
125 | $this->requestHead . "\n" . $this->requestBody, |
||
126 | $this->responseHead . "\n" . $this->responseBody |
||
127 | ); |
||
128 | } catch (\Exception $e) { |
||
129 | throw SoapException::unableToLoadCurl($e->getMessage()); |
||
130 | } |
||
131 | if ($this->soaperror != '') { |
||
132 | if (intval($this->soaperror_code) == 0) { |
||
133 | $this->soaperror_code = 7; |
||
134 | } |
||
135 | throw SoapException::soapFault($this->soaperror . " [$url]", $this->soaperror_code); |
||
136 | } |
||
137 | if ($httpcode != 200) { |
||
138 | if (intval($httpcode) == 0) { |
||
139 | $httpcode = 52; |
||
140 | } |
||
141 | throw SoapException::soapFault(" [$url]" . $this->responseHead, $httpcode); |
||
142 | } |
||
143 | return $this->responseBody; |
||
144 | } |
||
145 | |||
230 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.