| Conditions | 13 |
| Paths | 400 |
| Total Lines | 46 |
| Code Lines | 27 |
| Lines | 15 |
| Ratio | 32.61 % |
| 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 |
||
| 96 | public function setHeaders(Swift_Mime_HeaderSet $headers) |
||
| 97 | { |
||
| 98 | $bodyLen = $this->_bodyLen; |
||
| 99 | if (is_bool($bodyLen)) { |
||
| 100 | $bodyLen = -1; |
||
| 101 | } |
||
| 102 | |||
| 103 | $hash = $this->_hashAlgorithm === 'rsa-sha1' ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256; |
||
| 104 | $bodyCanon = $this->_bodyCanon === 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; |
||
| 105 | $headerCanon = $this->_headerCanon === 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; |
||
| 106 | $this->_dkimHandler = new OpenDKIMSign($this->_privateKey, $this->_selector, $this->_domainName, $headerCanon, $bodyCanon, $hash, $bodyLen); |
||
| 107 | |||
| 108 | // Hardcode signature Margin for now |
||
| 109 | $this->_dkimHandler->setMargin(78); |
||
| 110 | |||
| 111 | if (!is_numeric($this->_signatureTimestamp)) { |
||
| 112 | OpenDKIM::setOption(OpenDKIM::OPTS_FIXEDTIME, time()); |
||
| 113 | } else { |
||
| 114 | if (!OpenDKIM::setOption(OpenDKIM::OPTS_FIXEDTIME, $this->_signatureTimestamp)) { |
||
| 115 | throw new Swift_SwiftException('Unable to force signature timestamp [' . openssl_error_string() . ']'); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | if (isset($this->_signerIdentity)) { |
||
| 120 | $this->_dkimHandler->setSigner($this->_signerIdentity); |
||
| 121 | } |
||
| 122 | |||
| 123 | $listHeaders = $headers->listAll(); |
||
| 124 | View Code Duplication | foreach ($listHeaders as $hName) { |
|
| 125 | // Check if we need to ignore Header |
||
| 126 | if (!isset($this->_ignoredHeaders[Swift::strtolowerWithStaticCache($hName)])) { |
||
| 127 | $tmp = $headers->getAll($hName); |
||
| 128 | if ($headers->has($hName)) { |
||
| 129 | foreach ($tmp as $header) { |
||
| 130 | if ($header->getFieldBody() != '') { |
||
| 131 | $htosign = $header->toString(); |
||
| 132 | $this->_dkimHandler->header($htosign); |
||
| 133 | $this->_signedHeaders[] = $header->getFieldName(); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | return $this; |
||
| 141 | } |
||
| 142 | |||
| 251 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.