Conditions | 11 |
Paths | 11 |
Total Lines | 41 |
Code Lines | 29 |
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 |
||
45 | public function encrypt(AbstractSamlModel $object, XMLSecurityKey $key) |
||
46 | { |
||
47 | $oldKey = $key; |
||
48 | $key = new XMLSecurityKey($this->keyTransportEncryption, ['type' => 'public']); |
||
49 | $key->loadKey($oldKey->key); |
||
50 | |||
51 | $serializationContext = new SerializationContext(); |
||
52 | $object->serialize($serializationContext->getDocument(), $serializationContext); |
||
53 | |||
54 | $enc = new XMLSecEnc(); |
||
55 | $enc->setNode($serializationContext->getDocument()->firstChild); |
||
56 | $enc->type = XMLSecEnc::Element; |
||
57 | |||
58 | switch ($key->type) { |
||
59 | case XMLSecurityKey::TRIPLEDES_CBC: |
||
60 | case XMLSecurityKey::AES128_CBC: |
||
61 | case XMLSecurityKey::AES192_CBC: |
||
62 | case XMLSecurityKey::AES256_CBC: |
||
63 | $symmetricKey = $key; |
||
64 | break; |
||
65 | |||
66 | case XMLSecurityKey::RSA_1_5: |
||
67 | case XMLSecurityKey::RSA_SHA1: |
||
68 | case XMLSecurityKey::RSA_SHA256: |
||
69 | case XMLSecurityKey::RSA_SHA384: |
||
70 | case XMLSecurityKey::RSA_SHA512: |
||
71 | case XMLSecurityKey::RSA_OAEP_MGF1P: |
||
72 | $symmetricKey = new XMLSecurityKey($this->blockEncryptionAlgorithm); |
||
73 | $symmetricKey->generateSessionKey(); |
||
74 | |||
75 | $enc->encryptKey($key, $symmetricKey); |
||
76 | |||
77 | break; |
||
78 | |||
79 | default: |
||
80 | throw new LightSamlException(sprintf('Unknown key type for encryption: "%s"', $key->type)); |
||
81 | } |
||
82 | |||
83 | $this->encryptedElement = $enc->encryptNode($symmetricKey); |
||
84 | |||
85 | return $serializationContext; |
||
86 | } |
||
112 |