| Conditions | 11 |
| Paths | 11 |
| Total Lines | 41 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 106 | public static function fromUnencryptedElement( |
||
| 107 | AbstractXMLElement $element, |
||
| 108 | XMLSecurityKey $key |
||
| 109 | ): EncryptedElementInterface { |
||
| 110 | $xml = $element->toXML(); |
||
| 111 | |||
| 112 | Utils::getContainer()->debugMessage($xml, 'encrypt'); |
||
| 113 | |||
| 114 | $enc = new XMLSecEnc(); |
||
| 115 | $enc->setNode($xml); |
||
| 116 | $enc->type = XMLSecEnc::Element; |
||
| 117 | |||
| 118 | switch ($key->type) { |
||
| 119 | case XMLSecurityKey::TRIPLEDES_CBC: |
||
| 120 | case XMLSecurityKey::AES128_CBC: |
||
| 121 | case XMLSecurityKey::AES192_CBC: |
||
| 122 | case XMLSecurityKey::AES256_CBC: |
||
| 123 | $symmetricKey = $key; |
||
| 124 | break; |
||
| 125 | |||
| 126 | case XMLSecurityKey::RSA_1_5: |
||
| 127 | case XMLSecurityKey::RSA_SHA1: |
||
| 128 | case XMLSecurityKey::RSA_SHA256: |
||
| 129 | case XMLSecurityKey::RSA_SHA384: |
||
| 130 | case XMLSecurityKey::RSA_SHA512: |
||
| 131 | case XMLSecurityKey::RSA_OAEP_MGF1P: |
||
| 132 | $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC); |
||
| 133 | $symmetricKey->generateSessionKey(); |
||
| 134 | |||
| 135 | $enc->encryptKey($key, $symmetricKey); |
||
| 136 | |||
| 137 | break; |
||
| 138 | |||
| 139 | default: |
||
| 140 | throw new \Exception('Unknown key type for encryption: ' . $key->type); |
||
| 141 | } |
||
| 142 | |||
| 143 | $dom = $enc->encryptNode($symmetricKey); |
||
| 144 | /** @var \SAML2\XML\xenc\EncryptedData $encData */ |
||
| 145 | $encData = EncryptedData::fromXML($dom); |
||
| 146 | return new static($encData, []); |
||
|
1 ignored issue
–
show
|
|||
| 147 | } |
||
| 185 |