| Conditions | 1 |
| Paths | 1 |
| Total Lines | 75 |
| Code Lines | 42 |
| 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 |
||
| 142 | public function testMarshallingElementOrdering(): void |
||
| 143 | { |
||
| 144 | $kaNonce = new KANonce('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); |
||
| 145 | |||
| 146 | $digestMethod = new DigestMethod( |
||
| 147 | C::DIGEST_SHA256, |
||
| 148 | [ |
||
| 149 | new Chunk(DOMDocumentFactory::fromString( |
||
| 150 | '<some:Chunk xmlns:some="urn:x-simplesamlphp:namespace">some</some:Chunk>', |
||
| 151 | )->documentElement), |
||
| 152 | ], |
||
| 153 | ); |
||
| 154 | |||
| 155 | $originatorKeyInfo = new OriginatorKeyInfo( |
||
| 156 | [ |
||
| 157 | new KeyName('testkey'), |
||
| 158 | new X509Data( |
||
| 159 | [ |
||
| 160 | new X509Certificate(self::$certificate), |
||
| 161 | new X509SubjectName(self::$certData['name']), |
||
| 162 | ], |
||
| 163 | ), |
||
| 164 | new Chunk(DOMDocumentFactory::fromString( |
||
| 165 | '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">originator</ssp:Chunk>', |
||
| 166 | )->documentElement), |
||
| 167 | ], |
||
| 168 | 'fed321', |
||
| 169 | ); |
||
| 170 | |||
| 171 | $recipientKeyInfo = new RecipientKeyInfo( |
||
| 172 | [ |
||
| 173 | new KeyName('testkey'), |
||
| 174 | new X509Data( |
||
| 175 | [ |
||
| 176 | new X509Certificate(self::$certificate), |
||
| 177 | new X509SubjectName(self::$certData['name']), |
||
| 178 | ], |
||
| 179 | ), |
||
| 180 | new Chunk(DOMDocumentFactory::fromString( |
||
| 181 | '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">recipient</ssp:Chunk>', |
||
| 182 | )->documentElement), |
||
| 183 | ], |
||
| 184 | 'fed654', |
||
| 185 | ); |
||
| 186 | |||
| 187 | $agreementMethod = new AgreementMethod( |
||
| 188 | C::XMLENC11_ECDH_ES, |
||
| 189 | $kaNonce, |
||
| 190 | $originatorKeyInfo, |
||
| 191 | $recipientKeyInfo, |
||
| 192 | [$digestMethod], |
||
| 193 | ); |
||
| 194 | |||
| 195 | // Marshall it to a \DOMElement |
||
| 196 | $agreementMethodElement = $agreementMethod->toXML(); |
||
| 197 | |||
| 198 | $xpCache = XPath::getXPath($agreementMethodElement); |
||
| 199 | |||
| 200 | // Test for an KA-Nonce |
||
| 201 | /** @var \DOMElement[] $kaNonceElements */ |
||
| 202 | $kaNonceElements = XPath::xpQuery($agreementMethodElement, './xenc:KA-Nonce', $xpCache); |
||
| 203 | $this->assertCount(1, $kaNonceElements); |
||
| 204 | |||
| 205 | // Test ordering of AgreementMethod contents |
||
| 206 | /** @var \DOMElement[] $agreementMethodElements */ |
||
| 207 | $agreementMethodElements = XPath::xpQuery( |
||
| 208 | $agreementMethodElement, |
||
| 209 | './xenc:KA-Nonce/following-sibling::*', |
||
| 210 | $xpCache, |
||
| 211 | ); |
||
| 212 | |||
| 213 | $this->assertCount(3, $agreementMethodElements); |
||
| 214 | $this->assertEquals('ds:DigestMethod', $agreementMethodElements[0]->tagName); |
||
| 215 | $this->assertEquals('xenc:OriginatorKeyInfo', $agreementMethodElements[1]->tagName); |
||
| 216 | $this->assertEquals('xenc:RecipientKeyInfo', $agreementMethodElements[2]->tagName); |
||
| 217 | } |
||
| 219 |