Conditions | 9 |
Paths | 19 |
Total Lines | 86 |
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 |
||
66 | protected function execute(InputInterface $input, OutputInterface $output) |
||
67 | { |
||
68 | $io = new SymfonyStyle($input, $output); |
||
69 | $index = $this->getIndex($input->getOption(parent::INDEX_OPTION)); |
||
70 | $indexName = $aliasName = $index->getIndexName(); |
||
71 | |||
72 | if ($input->getOption('dump')) { |
||
73 | $io->note("Index mappings:"); |
||
74 | $io->text( |
||
75 | json_encode( |
||
76 | $index->getIndexSettings()->getIndexMetadata(), |
||
|
|||
77 | JSON_PRETTY_PRINT |
||
78 | ) |
||
79 | ); |
||
80 | |||
81 | return 0; |
||
82 | } |
||
83 | |||
84 | if ($input->getOption('time')) { |
||
85 | /** @var IndexSuffixFinder $finder */ |
||
86 | $finder = $this->getContainer()->get(IndexSuffixFinder::class); |
||
87 | $indexName = $finder->getNextFreeIndex($index); |
||
88 | } |
||
89 | |||
90 | if ($input->getOption('if-not-exists') && $index->indexExists()) { |
||
91 | $io->note( |
||
92 | sprintf( |
||
93 | 'Index `%s` already exists.', |
||
94 | $index->getIndexName() |
||
95 | ) |
||
96 | ); |
||
97 | |||
98 | return 0; |
||
99 | } |
||
100 | |||
101 | $indexesToRemoveAliases = null; |
||
102 | if ($input->getOption('alias') && $index->getClient()->indices()->existsAlias(['name' => $aliasName])) { |
||
103 | $indexesToRemoveAliases = $index->getClient()->indices()->getAlias( |
||
104 | [ |
||
105 | 'name' => $aliasName, |
||
106 | ] |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | $index->createIndex($input->getOption('no-mapping'), array_filter([ |
||
111 | 'index' => $indexName, |
||
112 | ])); |
||
113 | |||
114 | $io->text( |
||
115 | sprintf( |
||
116 | 'Created `<comment>%s</comment>` index.', |
||
117 | $index->getIndexName() |
||
118 | ) |
||
119 | ); |
||
120 | |||
121 | if ($input->getOption('alias')) { |
||
122 | $index->getClient()->indices()->putAlias([ |
||
123 | 'index' => $indexName, |
||
124 | 'name' => $aliasName, |
||
125 | ]); |
||
126 | $io->text( |
||
127 | sprintf( |
||
128 | 'Created an alias `<comment>%s</comment>` for the `<comment>%s</comment>` index.', |
||
129 | $aliasName, |
||
130 | $indexName |
||
131 | ) |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | if ($indexesToRemoveAliases) { |
||
136 | $indexesToRemoveAliases = implode(',', array_keys($indexesToRemoveAliases)); |
||
137 | $index->getClient()->indices()->deleteAlias([ |
||
138 | 'index' => $indexesToRemoveAliases, |
||
139 | 'name' => $aliasName, |
||
140 | ]); |
||
141 | $io->text( |
||
142 | sprintf( |
||
143 | 'Removed `<comment>%s</comment>` alias from `<comment>%s</comment>`.', |
||
144 | $aliasName, |
||
145 | $indexesToRemoveAliases |
||
146 | ) |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | return 0; |
||
151 | } |
||
152 | } |
||
153 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.