Conditions | 10 |
Paths | 16 |
Total Lines | 96 |
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 |
||
58 | public function execute(InputInterface $input, OutputInterface $output): int |
||
59 | { |
||
60 | $helper = $this->getHelper('question'); |
||
61 | |||
62 | $providerName = $input->getArgument('providerName'); |
||
63 | if (null === $providerName) { |
||
64 | $providers = array_keys($this->getMediaPool()->getProviders()); |
||
65 | $question = new ChoiceQuestion('Please select the provider', $providers, 0); |
||
66 | $question->setErrorMessage('Provider %s is invalid.'); |
||
67 | |||
68 | $providerName = $helper->ask($input, $output, $question); |
||
69 | } |
||
70 | |||
71 | $context = $input->getArgument('context'); |
||
72 | if (null === $context) { |
||
73 | $contexts = array_keys($this->getMediaPool()->getContexts()); |
||
74 | $question = new ChoiceQuestion('Please select the context', $contexts, 0); |
||
75 | $question->setErrorMessage('Context %s is invalid.'); |
||
76 | |||
77 | $context = $helper->ask($input, $output, $question); |
||
78 | } |
||
79 | |||
80 | $this->quiet = $input->getOption('quiet'); |
||
81 | $this->output = $output; |
||
82 | |||
83 | $provider = $this->getMediaPool()->getProvider($providerName); |
||
84 | |||
85 | $filesystem = $provider->getFilesystem(); |
||
86 | $fsReflection = new \ReflectionClass($filesystem); |
||
87 | $fsRegister = $fsReflection->getProperty('fileRegister'); |
||
88 | $fsRegister->setAccessible(true); |
||
89 | |||
90 | $batchCounter = 0; |
||
91 | $batchSize = (int) $input->getOption('batchSize'); |
||
92 | $batchesLimit = (int) $input->getOption('batchesLimit'); |
||
93 | $startOffset = (int) $input->getOption('startOffset'); |
||
94 | $totalMediasCount = 0; |
||
95 | do { |
||
96 | ++$batchCounter; |
||
97 | |||
98 | try { |
||
99 | $batchOffset = $startOffset + ($batchCounter - 1) * $batchSize; |
||
100 | $medias = $this->getMediaManager()->findBy( |
||
101 | [ |
||
102 | 'providerName' => $providerName, |
||
103 | 'context' => $context, |
||
104 | ], |
||
105 | [ |
||
106 | 'id' => 'ASC', |
||
107 | ], |
||
108 | $batchSize, |
||
109 | $batchOffset |
||
110 | ); |
||
111 | } catch (\Exception $e) { |
||
112 | $this->log('Error: '.$e->getMessage()); |
||
113 | |||
114 | break; |
||
115 | } |
||
116 | |||
117 | $batchMediasCount = \count($medias); |
||
118 | if (0 === $batchMediasCount) { |
||
119 | break; |
||
120 | } |
||
121 | |||
122 | $totalMediasCount += $batchMediasCount; |
||
123 | $this->log( |
||
124 | sprintf( |
||
125 | 'Loaded %s medias (batch #%d, offset %d) for generating thumbs (provider: %s, context: %s)', |
||
126 | $batchMediasCount, |
||
127 | $batchCounter, |
||
128 | $batchOffset, |
||
129 | $providerName, |
||
130 | $context |
||
131 | ) |
||
132 | ); |
||
133 | |||
134 | foreach ($medias as $media) { |
||
135 | if (!$this->processMedia($media, $provider)) { |
||
136 | continue; |
||
137 | } |
||
138 | //clean filesystem registry for saving memory |
||
139 | $fsRegister->setValue($filesystem, []); |
||
140 | } |
||
141 | |||
142 | //clear entity manager for saving memory |
||
143 | $this->getMediaManager()->getObjectManager()->clear(); |
||
144 | |||
145 | if ($batchesLimit > 0 && $batchCounter === $batchesLimit) { |
||
146 | break; |
||
147 | } |
||
148 | } while (true); |
||
149 | |||
150 | $this->log("Done (total medias processed: {$totalMediasCount})."); |
||
151 | |||
152 | return 0; |
||
153 | } |
||
154 | |||
202 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.