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 |
||
112 | public static function fromUnencryptedElement( |
||
113 | AbstractXMLElement $element, |
||
114 | XMLSecurityKey $key |
||
115 | ): EncryptedElementInterface { |
||
116 | $xml = $element->toXML(); |
||
117 | |||
118 | Utils::getContainer()->debugMessage($xml, 'encrypt'); |
||
119 | |||
120 | $enc = new XMLSecEnc(); |
||
121 | $enc->setNode($xml); |
||
122 | $enc->type = XMLSecEnc::Element; |
||
123 | |||
124 | switch ($key->type) { |
||
125 | case XMLSecurityKey::TRIPLEDES_CBC: |
||
126 | case XMLSecurityKey::AES128_CBC: |
||
127 | case XMLSecurityKey::AES192_CBC: |
||
128 | case XMLSecurityKey::AES256_CBC: |
||
129 | $symmetricKey = $key; |
||
130 | break; |
||
131 | |||
132 | case XMLSecurityKey::RSA_1_5: |
||
133 | case XMLSecurityKey::RSA_SHA1: |
||
134 | case XMLSecurityKey::RSA_SHA256: |
||
135 | case XMLSecurityKey::RSA_SHA384: |
||
136 | case XMLSecurityKey::RSA_SHA512: |
||
137 | case XMLSecurityKey::RSA_OAEP_MGF1P: |
||
138 | $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC); |
||
139 | $symmetricKey->generateSessionKey(); |
||
140 | |||
141 | $enc->encryptKey($key, $symmetricKey); |
||
142 | |||
143 | break; |
||
144 | |||
145 | default: |
||
146 | throw new \Exception('Unknown key type for encryption: ' . $key->type); |
||
147 | } |
||
148 | |||
149 | $dom = $enc->encryptNode($symmetricKey); |
||
150 | /** @var \SAML2\XML\xenc\EncryptedData $encData */ |
||
151 | $encData = EncryptedData::fromXML($dom); |
||
152 | return new static($encData, []); |
||
153 | } |
||
191 |