| Conditions | 9 |
| Paths | 99 |
| Total Lines | 63 |
| Code Lines | 41 |
| 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 |
||
| 87 | public function triggerNewOCSPStatement(SilverbulletCertificate $cert): string { |
||
| 88 | $certstatus = ""; |
||
| 89 | // get all relevant info from object properties |
||
| 90 | if ($cert->serial >= 0) { // let's start with the assumption that the cert is valid |
||
| 91 | if ($cert->revocationStatus == "REVOKED") { |
||
| 92 | // already revoked, simply return canned OCSP response |
||
| 93 | $certstatus = "R"; |
||
| 94 | } else { |
||
| 95 | $certstatus = "V"; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | $originalExpiry = date_create_from_format("Y-m-d H:i:s", $cert->expiry); |
||
| 100 | if ($originalExpiry === FALSE) { |
||
| 101 | throw new Exception("Unable to calculate original expiry date, input data bogus!"); |
||
| 102 | } |
||
| 103 | $validity = date_diff(/** @scrutinizer ignore-type */ date_create(), $originalExpiry); |
||
| 104 | if ($validity->invert == 1) { |
||
| 105 | // negative! Cert is already expired, no need to revoke. |
||
| 106 | // No need to return anything really, but do return the last known OCSP statement to prevent special case |
||
| 107 | $certstatus = "E"; |
||
| 108 | } |
||
| 109 | $profile = new ProfileSilverbullet($cert->profileId); |
||
| 110 | $inst = new IdP($profile->institution); |
||
| 111 | $federation = strtoupper($inst->federation); |
||
| 112 | // generate stub index.txt file |
||
| 113 | $tempdirArray = \core\common\Entity::createTemporaryDirectory("test"); |
||
| 114 | $tempdir = $tempdirArray['dir']; |
||
| 115 | $nowIndexTxt = (new \DateTime())->format("ymdHis") . "Z"; |
||
| 116 | $expiryIndexTxt = $originalExpiry->format("ymdHis") . "Z"; |
||
| 117 | $serialHex = strtoupper(dechex($cert->serial)); |
||
| 118 | if (strlen($serialHex) % 2 == 1) { |
||
| 119 | $serialHex = "0" . $serialHex; |
||
| 120 | } |
||
| 121 | |||
| 122 | $indexStatement = "$certstatus\t$expiryIndexTxt\t" . ($certstatus == "R" ? "$nowIndexTxt,unspecified" : "") . "\t$serialHex\tunknown\t/O=" . CONFIG_CONFASSISTANT['CONSORTIUM']['name'] . "/OU=$federation/CN=$cert->username\n"; |
||
| 123 | $this->loggerInstance->debug(4, "index.txt contents-to-be: $indexStatement"); |
||
| 124 | if (!file_put_contents($tempdir . "/index.txt", $indexStatement)) { |
||
| 125 | $this->loggerInstance->debug(1, "Unable to write openssl index.txt file for revocation handling!"); |
||
| 126 | } |
||
| 127 | // index.txt.attr is dull but needs to exist |
||
| 128 | file_put_contents($tempdir . "/index.txt.attr", "unique_subject = yes\n"); |
||
| 129 | // call "openssl ocsp" to manufacture our own OCSP statement |
||
| 130 | // adding "-rmd sha1" to the following command-line makes the |
||
| 131 | // choice of signature algorithm for the response explicit |
||
| 132 | // but it's only available from openssl-1.1.0 (which we do not |
||
| 133 | // want to require just for that one thing). |
||
| 134 | $execCmd = CONFIG['PATHS']['openssl'] . " ocsp -issuer " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA . " -sha1 -ndays 10 -no_nonce -serial 0x$serialHex -CA " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA . " -rsigner " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA . " -rkey " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY . " -index $tempdir/index.txt -no_cert_verify -respout $tempdir/$serialHex.response.der"; |
||
| 135 | $this->loggerInstance->debug(2, "Calling openssl ocsp with following cmdline: $execCmd\n"); |
||
| 136 | $output = []; |
||
| 137 | $return = 999; |
||
| 138 | exec($execCmd, $output, $return); |
||
| 139 | if ($return !== 0) { |
||
| 140 | throw new Exception("Non-zero return value from openssl ocsp!"); |
||
| 141 | } |
||
| 142 | $ocsp = file_get_contents($tempdir . "/$serialHex.response.der"); |
||
| 143 | // remove the temp dir! |
||
| 144 | unlink($tempdir . "/$serialHex.response.der"); |
||
| 145 | unlink($tempdir . "/index.txt.attr"); |
||
| 146 | unlink($tempdir . "/index.txt"); |
||
| 147 | rmdir($tempdir); |
||
| 148 | $this->databaseHandle->exec("UPDATE silverbullet_certificate SET OCSP = ?, OCSP_timestamp = NOW() WHERE serial_number = ?", "si", $ocsp, $cert->serial); |
||
| 149 | return $ocsp; |
||
| 150 | } |
||
| 222 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths