| Conditions | 13 |
| Paths | 28 |
| Total Lines | 61 |
| Code Lines | 37 |
| 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 |
||
| 101 | public function processSignature($refNode) |
||
| 102 | {
|
||
| 103 | $objXMLSecDSig = new XMLSecurityDSig(); |
||
| 104 | $objXMLSecDSig->idKeys[] = 'wswsu:Id'; |
||
| 105 | $objXMLSecDSig->idNS['wswsu'] = self::WSUNS; |
||
| 106 | $objXMLSecDSig->sigNode = $refNode; |
||
| 107 | |||
| 108 | /* Canonicalize the signed info */ |
||
| 109 | $objXMLSecDSig->canonicalizeSignedInfo(); |
||
| 110 | $retVal = $objXMLSecDSig->validateReference(); |
||
| 111 | |||
| 112 | if (! $retVal) {
|
||
| 113 | throw new Exception("Validation Failed");
|
||
| 114 | } |
||
| 115 | |||
| 116 | $key = NULL; |
||
| 117 | $objKey = $objXMLSecDSig->locateKey(); |
||
| 118 | |||
| 119 | if ($objKey) {
|
||
| 120 | if ($objKeyInfo = XMLSecEnc::staticLocateKeyInfo($objKey, $refNode)) {
|
||
|
|
|||
| 121 | /* Handle any additional key processing such as encrypted keys here */ |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | if (empty($objKey)) {
|
||
| 126 | throw new Exception("Error loading key to handle Signature");
|
||
| 127 | } |
||
| 128 | do {
|
||
| 129 | if (empty($objKey->key)) {
|
||
| 130 | $this->SOAPXPath->registerNamespace('xmlsecdsig', XMLSecurityDSig::XMLDSIGNS);
|
||
| 131 | $query = "./xmlsecdsig:KeyInfo/wswsse:SecurityTokenReference/wswsse:Reference"; |
||
| 132 | $nodeset = $this->SOAPXPath->query($query, $refNode); |
||
| 133 | if ($encmeth = $nodeset->item(0)) {
|
||
| 134 | if ($uri = $encmeth->getAttribute("URI")) {
|
||
| 135 | |||
| 136 | $arUrl = parse_url($uri); |
||
| 137 | |||
| 138 | if (empty($arUrl['path']) && ($identifier = $arUrl['fragment'])) {
|
||
| 139 | $query = '//wswsse:BinarySecurityToken[@wswsu:Id="'.$identifier.'"]'; |
||
| 140 | $nodeset = $this->SOAPXPath->query($query); |
||
| 141 | if ($encmeth = $nodeset->item(0)) {
|
||
| 142 | $x509cert = $encmeth->textContent; |
||
| 143 | $x509cert = str_replace(array("\r", "\n"), "", $x509cert);
|
||
| 144 | $x509cert = "-----BEGIN CERTIFICATE-----\n".chunk_split($x509cert, 64, "\n")."-----END CERTIFICATE-----\n"; |
||
| 145 | |||
| 146 | $objKey->loadKey($x509cert); |
||
| 147 | break; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 | throw new Exception("Error loading key to handle Signature");
|
||
| 153 | } |
||
| 154 | } while(0); |
||
| 155 | |||
| 156 | if (! $objXMLSecDSig->verify($objKey)) {
|
||
| 157 | throw new Exception("Unable to validate Signature");
|
||
| 158 | } |
||
| 159 | |||
| 160 | return true; |
||
| 161 | } |
||
| 162 | |||
| 201 |
This check looks for the bodies of
ifstatements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
ifbodies can be removed. If you have an empty if but statements in theelsebranch, consider inverting the condition.could be turned into
This is much more concise to read.