Conditions | 11 |
Paths | 30 |
Total Lines | 51 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
41 | protected function execute(InputInterface $input, OutputInterface $output) |
||
42 | { |
||
43 | /** @var JWKAnalyzerManager $analyzerManager */ |
||
44 | $analyzerManager = $this->getContainer()->get(JWKAnalyzerManager::class); |
||
45 | $jwkset = $this->getKeyset($input); |
||
46 | |||
47 | $privateKeys = 0; |
||
48 | $publicKeys = 0; |
||
49 | $sharedKeys = 0; |
||
50 | $mixedKeys = false; |
||
51 | |||
52 | foreach($jwkset as $kid => $jwk) { |
||
53 | $output->writeln(sprintf('Analysing key with index/kid "%s"', $kid)); |
||
54 | $messages = $analyzerManager->analyze($jwk); |
||
|
|||
55 | if (!empty($messages)) { |
||
56 | foreach ($messages as $message) { |
||
57 | $output->writeln(' '.$message); |
||
58 | } |
||
59 | } else { |
||
60 | $output->writeln(' No issue with this key'); |
||
61 | } |
||
62 | |||
63 | switch (true) { |
||
64 | case 'oct' === $jwk->get('kty'): |
||
65 | $sharedKeys++; |
||
66 | if (0 !== $privateKeys+$publicKeys) { |
||
67 | $mixedKeys = true; |
||
68 | } |
||
69 | break; |
||
70 | case in_array($jwk->get('kty'), ['RSA', 'EC', 'OKP']): |
||
71 | if ($jwk->has('d')) { |
||
72 | $privateKeys++; |
||
73 | if (0 !== $sharedKeys+$publicKeys) { |
||
74 | $mixedKeys = true; |
||
75 | } |
||
76 | } else { |
||
77 | $publicKeys++; |
||
78 | if (0 !== $privateKeys+$sharedKeys) { |
||
79 | $mixedKeys = true; |
||
80 | } |
||
81 | } |
||
82 | break; |
||
83 | default: |
||
84 | break; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if ($mixedKeys) { |
||
89 | $output->writeln('/!\\ This key set mixes share, public and private keys. You should create one key set per key type. /!\\'); |
||
90 | } |
||
91 | } |
||
92 | |||
114 |
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: