| Conditions | 11 |
| Paths | 30 |
| Total Lines | 51 |
| Code Lines | 34 |
| 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 |
||
| 67 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 68 | { |
||
| 69 | $jwkset = $this->getKeyset($input); |
||
| 70 | |||
| 71 | $privateKeys = 0; |
||
| 72 | $publicKeys = 0; |
||
| 73 | $sharedKeys = 0; |
||
| 74 | $mixedKeys = false; |
||
| 75 | |||
| 76 | foreach ($jwkset as $kid => $jwk) { |
||
| 77 | $output->writeln(sprintf('Analysing key with index/kid "%s"', $kid)); |
||
| 78 | $messages = $this->analyzerManager->analyze($jwk); |
||
|
|
|||
| 79 | if (!empty($messages)) { |
||
| 80 | foreach ($messages as $message) { |
||
| 81 | $output->writeln(' '.$message); |
||
| 82 | } |
||
| 83 | } else { |
||
| 84 | $output->writeln(' No issue with this key'); |
||
| 85 | } |
||
| 86 | |||
| 87 | switch (true) { |
||
| 88 | case 'oct' === $jwk->get('kty'): |
||
| 89 | $sharedKeys++; |
||
| 90 | if (0 !== $privateKeys + $publicKeys) { |
||
| 91 | $mixedKeys = true; |
||
| 92 | } |
||
| 93 | |||
| 94 | break; |
||
| 95 | case in_array($jwk->get('kty'), ['RSA', 'EC', 'OKP']): |
||
| 96 | if ($jwk->has('d')) { |
||
| 97 | ++$privateKeys; |
||
| 98 | if (0 !== $sharedKeys + $publicKeys) { |
||
| 99 | $mixedKeys = true; |
||
| 100 | } |
||
| 101 | } else { |
||
| 102 | ++$publicKeys; |
||
| 103 | if (0 !== $privateKeys + $sharedKeys) { |
||
| 104 | $mixedKeys = true; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | break; |
||
| 109 | default: |
||
| 110 | break; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | if ($mixedKeys) { |
||
| 115 | $output->writeln('/!\\ This key set mixes share, public and private keys. You should create one key set per key type. /!\\'); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 135 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: