| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 33 |
| 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 |
||
| 117 | public function testMarshallingElementOrder(): void |
||
| 118 | { |
||
| 119 | $alg = 'http://www.w3.org/2009/xmlenc11#ConcatKDF'; |
||
| 120 | $RSAKeyValue = new RSAKeyValue( |
||
| 121 | new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), |
||
| 122 | new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), |
||
| 123 | ); |
||
| 124 | |||
| 125 | $keyDerivationMethod = new KeyDerivationMethod($alg, [$RSAKeyValue]); |
||
| 126 | |||
| 127 | $transformData = new Transform( |
||
| 128 | C::XPATH10_URI, |
||
| 129 | new XPath('self::xenc:EncryptedData[@Id="example1"]'), |
||
| 130 | ); |
||
| 131 | $transformKey = new Transform( |
||
| 132 | C::XPATH10_URI, |
||
| 133 | new XPath('self::xenc:EncryptedKey[@Id="example1"]'), |
||
| 134 | ); |
||
| 135 | |||
| 136 | $referenceList = new ReferenceList( |
||
| 137 | [ |
||
| 138 | new DataReference('#Encrypted_DATA_ID', [new Transforms([$transformData])]), |
||
| 139 | ], |
||
| 140 | [ |
||
| 141 | new KeyReference('#Encrypted_KEY_ID', [new Transforms([$transformKey])]), |
||
| 142 | ], |
||
| 143 | ); |
||
| 144 | |||
| 145 | $derivedKeyName = new DerivedKeyName('phpunit'); |
||
| 146 | $masterKeyName = new MasterKeyName('phpunit'); |
||
| 147 | |||
| 148 | $derivedKey = new DerivedKey( |
||
| 149 | 'phpunit', |
||
| 150 | 'phpunit', |
||
| 151 | 'urn:x-simplesamlphp:type', |
||
| 152 | $keyDerivationMethod, |
||
| 153 | $referenceList, |
||
| 154 | $derivedKeyName, |
||
| 155 | $masterKeyName, |
||
| 156 | ); |
||
| 157 | |||
| 158 | $dkElement = $derivedKey->toXML(); |
||
| 159 | $xpCache = XPathUtils::getXPath($dkElement); |
||
| 160 | |||
| 161 | // Test for a KeyDerivationMethod |
||
| 162 | /** @var \DOMElement[] $keyDerivationMethodElements */ |
||
| 163 | $keyDerivationMethodElements = XPathUtils::xpQuery($dkElement, './xenc11:KeyDerivationMethod', $xpCache); |
||
| 164 | $this->assertCount(1, $keyDerivationMethodElements); |
||
| 165 | |||
| 166 | // Test ordering of DerivedKey contents |
||
| 167 | /** @var \DOMElement[] $dkElements */ |
||
| 168 | $dkElements = XPathUtils::xpQuery($dkElement, './xenc11:KeyDerivationMethod/following-sibling::*', $xpCache); |
||
| 169 | |||
| 170 | $this->assertCount(3, $dkElements); |
||
| 171 | $this->assertEquals('xenc:ReferenceList', $dkElements[0]->tagName); |
||
| 172 | $this->assertEquals('xenc11:DerivedKeyName', $dkElements[1]->tagName); |
||
| 173 | $this->assertEquals('xenc11:MasterKeyName', $dkElements[2]->tagName); |
||
| 174 | } |
||
| 191 |