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 | |||
118 | $derivedKey = new DerivedKey( |
||
119 | StringValue::fromString('phpunit'), |
||
120 | IDValue::fromString('phpunit'), |
||
121 | AnyURIValue::fromString('urn:x-simplesamlphp:type'), |
||
122 | self::$keyDerivationMethod, |
||
123 | self::$referenceList, |
||
124 | $derivedKeyName, |
||
125 | $masterKeyName, |
||
126 | ); |
||
127 | |||
128 | $this->assertEquals( |
||
129 | self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
||
130 | strval($derivedKey), |
||
131 | ); |
||
132 | } |
||
133 | |||
134 | |||
135 | /** |
||
136 | */ |
||
137 | public function testMarshallingElementOrder(): void |
||
138 | { |
||
139 | $derivedKeyName = new DerivedKeyName( |
||
140 | StringValue::fromString('phpunit'), |
||
141 | ); |
||
142 | $masterKeyName = new MasterKeyName( |
||
143 | StringValue::fromString('phpunit'), |
||
144 | ); |
||
145 | |||
146 | $derivedKey = new DerivedKey( |
||
147 | StringValue::fromString('phpunit'), |
||
148 | IDValue::fromString('phpunit'), |
||
149 | AnyURIValue::fromString('urn:x-simplesamlphp:type'), |
||
150 | self::$keyDerivationMethod, |
||
151 | self::$referenceList, |
||
152 | $derivedKeyName, |
||
153 | $masterKeyName, |
||
154 | ); |
||
155 | |||
156 | $dkElement = $derivedKey->toXML(); |
||
157 | $xpCache = XPathUtils::getXPath($dkElement); |
||
158 | |||
159 | // Test for a KeyDerivationMethod |
||
160 | /** @var \DOMElement[] $keyDerivationMethodElements */ |
||
161 | $keyDerivationMethodElements = XPathUtils::xpQuery($dkElement, './xenc11:KeyDerivationMethod', $xpCache); |
||
162 | $this->assertCount(1, $keyDerivationMethodElements); |
||
163 | |||
164 | // Test ordering of DerivedKey contents |
||
165 | /** @var \DOMElement[] $dkElements */ |
||
166 | $dkElements = XPathUtils::xpQuery($dkElement, './xenc11:KeyDerivationMethod/following-sibling::*', $xpCache); |
||
167 | |||
168 | $this->assertCount(3, $dkElements); |
||
169 | $this->assertEquals('xenc:ReferenceList', $dkElements[0]->tagName); |
||
170 | $this->assertEquals('xenc11:DerivedKeyName', $dkElements[1]->tagName); |
||
171 | $this->assertEquals('xenc11:MasterKeyName', $dkElements[2]->tagName); |
||
172 | } |
||
173 | |||
174 | |||
189 |