Conditions | 9 |
Paths | 16 |
Total Lines | 76 |
Code Lines | 39 |
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 |
||
30 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
31 | { |
||
32 | // List all loggable classes |
||
33 | $loggableContextCollection = iterator_to_array($this->loggableContextCollectionFactory->create()->getIterator()); |
||
34 | |||
35 | $loggableClasses = array_keys($loggableContextCollection); |
||
36 | $loggableClasses[] = 'ALL'; |
||
37 | |||
38 | // aks for the class |
||
39 | $helper = $this->getHelper('question'); |
||
40 | $question = new ChoiceQuestion( |
||
41 | 'Choose loggable class to repopulate current data:', |
||
42 | $loggableClasses, |
||
43 | 0 |
||
44 | ); |
||
45 | $question->setErrorMessage('Loggable class %s is invalid.'); |
||
46 | |||
47 | $loggableClass = $helper->ask($input, $output, $question); |
||
|
|||
48 | |||
49 | // ask for the limit |
||
50 | $question = new Question( |
||
51 | 'Limit number of latest objects to be populated (leave empty for no limit):', |
||
52 | 0 |
||
53 | ); |
||
54 | |||
55 | $limit = $helper->ask($input, $output, $question); |
||
56 | |||
57 | $io = new SymfonyStyle($input, $output); |
||
58 | |||
59 | $io->title('Creating current data log trackers ...'); |
||
60 | |||
61 | if ('ALL' !== $loggableClass) { |
||
62 | $loggableClasses = [$loggableClass]; |
||
63 | } |
||
64 | |||
65 | foreach ($loggableClasses as $loggableClass) { |
||
66 | if ('ALL' === $loggableClass) { |
||
67 | continue; |
||
68 | } |
||
69 | |||
70 | try { |
||
71 | $this->elasticsearchIndexFactory->recreateCurrentDataTrackerLogIndex($loggableClass); |
||
72 | } catch (\Exception $e) { |
||
73 | $io->error($e->getMessage()); |
||
74 | |||
75 | return Command::FAILURE; |
||
76 | } |
||
77 | |||
78 | // get repository for current loggable class and pull all data from DB |
||
79 | $manager = $this->managerRegistry->getManagerForClass($loggableClass); |
||
80 | |||
81 | // loggable class not mapped to the db, skip |
||
82 | if (!$manager) { |
||
83 | continue; |
||
84 | } |
||
85 | |||
86 | $io->title('Processing '.$loggableClass); |
||
87 | $repository = $manager->getRepository($loggableClass); |
||
88 | |||
89 | $batchSize = 250; |
||
90 | $messagesCount = 0; |
||
91 | $count = $repository->count([]); |
||
92 | |||
93 | if (0 === $limit || (int) $limit > $count) { |
||
94 | $limit = $count; |
||
95 | } |
||
96 | |||
97 | for ($offset = 0; $offset < $limit; $offset += $batchSize) { |
||
98 | $this->bus->dispatch(new PopulateCurrentDataTrackersMessage($offset, $batchSize, $loggableClass, $loggableContextCollection[$loggableClass])); |
||
99 | ++$messagesCount; |
||
100 | } |
||
101 | |||
102 | $io->success('Dispatched '.$messagesCount.' messages for populating '.$loggableClass.' data trackers'); |
||
103 | } |
||
104 | |||
105 | return Command::SUCCESS; |
||
106 | } |
||
108 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.