| Conditions | 8 |
| Paths | 49 |
| Total Lines | 74 |
| Code Lines | 48 |
| 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 |
||
| 56 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 57 | { |
||
| 58 | $dryRyn = $input->getOption('dry-run'); |
||
| 59 | $io = new SymfonyStyle($input, $output); |
||
| 60 | |||
| 61 | $io->title('Convert Public Subject Identifiers to Pairwise'); |
||
| 62 | |||
| 63 | $fp = $this->checkAndOpenFile($io, $input); |
||
| 64 | if ($fp === false) { |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | |||
| 68 | $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
| 69 | $client = $this->getClient($input->getArgument('client')); |
||
| 70 | |||
| 71 | $count = $this->checkCount($io, $client); |
||
| 72 | if ($count === null) { |
||
| 73 | fclose($fp); |
||
| 74 | |||
| 75 | return; |
||
| 76 | } |
||
| 77 | |||
| 78 | $publicSubs = $this->getPublicSubQuery($client) |
||
| 79 | ->getQuery()->iterate(); |
||
| 80 | |||
| 81 | $io->section("Generating Sector Identifiers..."); |
||
| 82 | |||
| 83 | /** @var SubjectIdentifierService $subIdService */ |
||
| 84 | $subIdService = $this->getContainer()->get('oidc.subject_identifier.service'); |
||
| 85 | |||
| 86 | $metadata = $this->getClientMetadata($client); |
||
| 87 | $metadata->setSubjectType('pairwise'); |
||
| 88 | |||
| 89 | $io->progressStart($count); |
||
| 90 | $this->em->beginTransaction(); |
||
| 91 | $done = 0; |
||
| 92 | try { |
||
| 93 | foreach ($publicSubs as $row) { |
||
| 94 | /** @var Authorization $auth */ |
||
| 95 | $auth = $row[0]; |
||
| 96 | $person = $auth->getPerson(); |
||
| 97 | |||
| 98 | $sub = $subIdService->convertSubjectIdentifier($person, $metadata); |
||
| 99 | |||
| 100 | $row = [$person->getId(), $sub->getSubjectIdentifier()]; |
||
| 101 | if (false === fputcsv($fp, $row)) { |
||
| 102 | throw new \RuntimeException('Error writing CSV to file! Aborting!'); |
||
| 103 | } |
||
| 104 | |||
| 105 | $this->em->persist($sub); |
||
| 106 | if ($done++ % 50 === 0) { |
||
| 107 | $this->em->flush(); |
||
| 108 | $this->em->clear(); |
||
| 109 | } |
||
| 110 | $io->progressAdvance(); |
||
| 111 | } |
||
| 112 | $io->progressFinish(); |
||
| 113 | |||
| 114 | if ($dryRyn) { |
||
| 115 | $this->em->rollback(); |
||
| 116 | $io->note("Dry Run: no changes were persisted."); |
||
| 117 | } else { |
||
| 118 | $this->em->commit(); |
||
| 119 | } |
||
| 120 | $this->em->flush(); |
||
| 121 | $this->em->clear(); |
||
| 122 | |||
| 123 | $io->success("Done! {$done} Authorizations updated!"); |
||
| 124 | } catch (\Exception $e) { |
||
| 125 | $io->error($e->getMessage()); |
||
| 126 | $this->em->rollback(); |
||
| 127 | $this->em->clear(); |
||
| 128 | } |
||
| 129 | fclose($fp); |
||
| 130 | } |
||
| 248 |