Conditions | 12 |
Paths | 12 |
Total Lines | 56 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
78 | protected function execute(InputInterface $input, OutputInterface $output) |
||
79 | { |
||
80 | // Check mongo db version |
||
81 | $mongoVersion = $this->getMongoDBVersion('Graviton\\CoreBundle\\Document\\App'); |
||
82 | if ((float) $mongoVersion < 2.6) { |
||
83 | $output->writeln("MongoDB Version =< 2.6 installed: " . $mongoVersion); |
||
84 | exit(); |
||
85 | } |
||
86 | |||
87 | $metadatas = $this->documentManager->getMetadataFactory()->getAllMetadata(); |
||
88 | /** @var ClassMetadata $metadata */ |
||
89 | foreach ($metadatas as $metadata) { |
||
90 | $indexes = $metadata->getIndexes(); |
||
91 | $searchName = 'search'.$metadata->getCollection().'Index'; |
||
92 | foreach ($indexes as $index) { |
||
93 | if (array_key_exists('keys', $index) && array_key_exists($searchName, $index['keys'])) { |
||
94 | if (array_key_exists('options', $index) && !empty($index['options'])) { |
||
95 | $collection = $this->documentManager->getDocumentCollection($metadata->getName()); |
||
96 | if (!$collection) { |
||
97 | continue; |
||
98 | } |
||
99 | $newIndex = []; |
||
100 | foreach ($index['options'] as $optionName => $optionsValue) { |
||
101 | $optionName = str_replace('search.', '', $optionName); |
||
102 | $newIndex[$optionName] = 'text'; |
||
103 | $index['options'][$optionName] = floatval($optionsValue); |
||
104 | } |
||
105 | foreach ($collection->getIndexInfo() as $indexInfo) { |
||
106 | // When using doctrine name may have a _1 |
||
107 | if (strpos($indexInfo['name'], $searchName) !== false) { |
||
108 | $output->writeln("Deleting Custom Text index {$searchName}"); |
||
109 | $this->documentManager->getDocumentDatabase($metadata->getName())->command( |
||
110 | [ |
||
111 | "deleteIndexes" => $collection->getName(), |
||
112 | "index" => $indexInfo['name'] |
||
113 | ] |
||
114 | ); |
||
115 | break; |
||
116 | } |
||
117 | } |
||
118 | $output->writeln($metadata->getName().": created custom Text index {$searchName}"); |
||
119 | $collection->ensureIndex( |
||
120 | $newIndex, |
||
121 | [ |
||
122 | 'weights' => $index['options'], |
||
123 | 'name' => $searchName, |
||
124 | 'default_language' => 'de', |
||
125 | 'language_override' => 'language' |
||
126 | ] |
||
127 | ); |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | |||
133 | } |
||
134 | |||
150 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.