| Conditions | 6 |
| Paths | 8 |
| Total Lines | 61 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 82 | public function testSignOperation(CertificateBundle $trustStore, PrivateKeyInfo $privateKey, Certificate $cert, CertificateBundle $certBundle) |
||
| 83 | { |
||
| 84 | $now = time(); |
||
| 85 | |||
| 86 | $details = new PaymentDetails(); |
||
| 87 | $details->setTime($now); |
||
| 88 | |||
| 89 | $requestSigner = new RequestSigner(); |
||
| 90 | // 10/12/2017 ish |
||
| 91 | $now = new \DateTimeImmutable(); |
||
| 92 | $now = $now->setTimestamp(1509692666); |
||
| 93 | |||
| 94 | $requestValidator = new RequestValidation(new PathValidationConfig($now, 10), $trustStore); |
||
| 95 | |||
| 96 | foreach ([PKIType::X509_SHA256, PKIType::X509_SHA1] as $pkiType) { |
||
| 97 | $request = $requestSigner->sign($details, $pkiType, $privateKey, $cert, $certBundle); |
||
| 98 | $this->assertTrue($request->hasSignature()); |
||
| 99 | $this->assertTrue($request->hasPkiData()); |
||
| 100 | $this->assertTrue($request->hasPkiType()); |
||
| 101 | |||
| 102 | $this->assertEquals($pkiType, $request->getPkiType()); |
||
| 103 | |||
| 104 | try { |
||
| 105 | $requestValidator->validateX509Signature($cert, $request); |
||
| 106 | } catch (\Exception $e) { |
||
| 107 | $this->fail("verification of own signature should always succeed"); |
||
| 108 | return; |
||
| 109 | } |
||
| 110 | |||
| 111 | $x509 = new X509Certificates(); |
||
| 112 | $x509->parse($request->getPkiData()); |
||
| 113 | |||
| 114 | $this->assertEquals(1 + count($certBundle), count($x509->getCertificateList())); |
||
| 115 | |||
| 116 | /** @var Certificate[] $allCerts */ |
||
| 117 | $allCerts = array_merge([$cert], $certBundle->all()); |
||
| 118 | foreach ($allCerts as $i => $certificate) { |
||
| 119 | $this->assertEquals($certificate->toDER(), $x509->getCertificate($i)); |
||
| 120 | } |
||
| 121 | |||
| 122 | try { |
||
| 123 | $qualifiedCert = $requestValidator->validateCertificateChain($x509); |
||
| 124 | } catch (\Exception $e) { |
||
| 125 | $this->fail("certificate chain validation shouldn't fail"); |
||
| 126 | return; |
||
| 127 | } |
||
| 128 | |||
| 129 | $this->assertTrue($cert->equals($qualifiedCert->getPath()->endEntityCertificate())); |
||
| 130 | |||
| 131 | try { |
||
| 132 | $result = $requestValidator->verifyX509Details($request); |
||
| 133 | $threw = false; |
||
| 134 | } catch (\Exception $e) { |
||
| 135 | $threw = true; |
||
| 136 | } |
||
| 137 | |||
| 138 | $this->assertFalse($threw, "verifying cert details shouldn't fail"); |
||
| 139 | |||
| 140 | $this->assertTrue($result->certificate()->equals($cert)); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |
||
| 144 |