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 |
||
70 | protected function execute(InputInterface $input, OutputInterface $output) |
||
71 | { |
||
72 | $jwkset = $this->getKeyset($input); |
||
73 | |||
74 | $privateKeys = 0; |
||
75 | $publicKeys = 0; |
||
76 | $sharedKeys = 0; |
||
77 | $mixedKeys = false; |
||
78 | |||
79 | foreach ($jwkset as $kid => $jwk) { |
||
80 | $output->writeln(sprintf('Analysing key with index/kid "%s"', $kid)); |
||
81 | $messages = $this->analyzerManager->analyze($jwk); |
||
|
|||
82 | if (!empty($messages)) { |
||
83 | foreach ($messages as $message) { |
||
84 | $output->writeln(' '.$message); |
||
85 | } |
||
86 | } else { |
||
87 | $output->writeln(' No issue with this key'); |
||
88 | } |
||
89 | |||
90 | switch (true) { |
||
91 | case 'oct' === $jwk->get('kty'): |
||
92 | $sharedKeys++; |
||
93 | if (0 !== $privateKeys + $publicKeys) { |
||
94 | $mixedKeys = true; |
||
95 | } |
||
96 | |||
97 | break; |
||
98 | case in_array($jwk->get('kty'), ['RSA', 'EC', 'OKP']): |
||
99 | if ($jwk->has('d')) { |
||
100 | ++$privateKeys; |
||
101 | if (0 !== $sharedKeys + $publicKeys) { |
||
102 | $mixedKeys = true; |
||
103 | } |
||
104 | } else { |
||
105 | ++$publicKeys; |
||
106 | if (0 !== $privateKeys + $sharedKeys) { |
||
107 | $mixedKeys = true; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | break; |
||
112 | default: |
||
113 | break; |
||
114 | } |
||
115 | } |
||
116 | |||
117 | if ($mixedKeys) { |
||
118 | $output->writeln('/!\\ This key set mixes share, public and private keys. You should create one key set per key type. /!\\'); |
||
119 | } |
||
120 | } |
||
121 | |||
138 |
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: