| Conditions | 10 |
| Paths | 180 |
| Total Lines | 70 |
| 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 |
||
| 69 | { |
||
| 70 | $pharPath = $io->getInput()->getArgument(self::PHAR_ARG); |
||
| 71 | |||
| 72 | Assertion::file($pharPath); |
||
|
|
|||
| 73 | |||
| 74 | $pharPath = false !== realpath($pharPath) ? realpath($pharPath) : $pharPath; |
||
| 75 | |||
| 76 | $io->newLine(); |
||
| 77 | $io->writeln( |
||
| 78 | sprintf( |
||
| 79 | '🔐️ Verifying the PHAR "<comment>%s</comment>"', |
||
| 80 | $pharPath |
||
| 81 | ) |
||
| 82 | ); |
||
| 83 | $io->newLine(); |
||
| 84 | |||
| 85 | $tmpPharPath = create_temporary_phar($pharPath); |
||
| 86 | |||
| 87 | if (file_exists($pharPubKey = $pharPath.'.pubkey')) { |
||
| 88 | copy($pharPubKey, $tmpPharPath.'.pubkey'); |
||
| 89 | } |
||
| 90 | |||
| 91 | $verified = false; |
||
| 92 | $signature = null; |
||
| 93 | $throwable = null; |
||
| 94 | |||
| 95 | try { |
||
| 96 | $phar = new Phar($tmpPharPath); |
||
| 97 | |||
| 98 | $verified = true; |
||
| 99 | $signature = $phar->getSignature(); |
||
| 100 | } catch (Throwable $throwable) { |
||
| 101 | // Continue |
||
| 102 | } finally { |
||
| 103 | remove($tmpPharPath); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (false === $verified || null === $signature) { |
||
| 107 | return $this->failVerification($throwable, $io); |
||
| 108 | } |
||
| 109 | |||
| 110 | $io->writeln('<info>The PHAR passed verification.</info>'); |
||
| 111 | |||
| 112 | $io->newLine(); |
||
| 113 | $io->writeln( |
||
| 114 | sprintf( |
||
| 115 | '%s signature: <info>%s</info>', |
||
| 116 | $signature['hash_type'], |
||
| 117 | $signature['hash'] |
||
| 118 | ) |
||
| 119 | ); |
||
| 120 | |||
| 121 | return 0; |
||
| 122 | } |
||
| 123 | |||
| 124 | private function failVerification(?Throwable $throwable, IO $io): int |
||
| 125 | { |
||
| 126 | $message = null !== $throwable && '' !== $throwable->getMessage() |
||
| 127 | ? $throwable->getMessage() |
||
| 128 | : 'Unknown reason.' |
||
| 129 | ; |
||
| 130 | |||
| 131 | $io->writeln( |
||
| 132 | sprintf( |
||
| 133 | '<error>The PHAR failed the verification: %s</error>', |
||
| 134 | $message |
||
| 135 | ) |
||
| 136 | ); |
||
| 137 | |||
| 138 | if (null !== $throwable && $io->isDebug()) { |
||
| 139 | throw $throwable; |
||
| 145 |