Conditions | 13 |
Paths | 65 |
Total Lines | 61 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 declare(strict_types = 1); |
||
38 | public function getIndexes(): array |
||
39 | { |
||
40 | $indexes = []; |
||
41 | |||
42 | $indexesConfig = Config::inst()->get('Suilven\FreeTextSearch\Indexes', 'indexes') ; |
||
43 | |||
44 | // reset |
||
45 | $this->indexesByName = []; |
||
46 | |||
47 | foreach ($indexesConfig as $indexConfig) { |
||
48 | $index = new Index(); |
||
49 | $index->setClass($indexConfig['index']['class']); |
||
50 | $index->setName($indexConfig['index']['name']); |
||
51 | foreach ($indexConfig['index']['fields'] as $fieldname) { |
||
52 | $index->addField($fieldname); |
||
53 | } |
||
54 | |||
55 | if (isset($indexConfig['index']['tokens'])) { |
||
56 | foreach ($indexConfig['index']['tokens'] as $token) { |
||
57 | $index->addToken($token); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | // has one fields |
||
62 | if (isset($indexConfig['index']['has_one'])) { |
||
63 | foreach ($indexConfig['index']['has_one'] as $hasOneField) { |
||
64 | $index->addHasOneField($hasOneField); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | // has many fields |
||
69 | // NB many many may need to be treated as bipartisan has many |
||
70 | if (isset($indexConfig['index']['has_many'])) { |
||
71 | foreach ($indexConfig['index']['has_many'] as $hasManyField) { |
||
72 | $index->addHasManyField($hasManyField['name'], [ |
||
73 | 'relationship' => $hasManyField['relationship'], |
||
74 | 'field' => $hasManyField['field'], |
||
75 | ]); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | // fields that will be used for highlighting |
||
80 | if (isset($indexConfig['index']['highlighted_fields'])) { |
||
81 | foreach ($indexConfig['index']['highlighted_fields'] as $highlightedField) { |
||
82 | $index->addHighlightedField($highlightedField); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | // fields that will be used for storage, but not indexed |
||
87 | if (isset($indexConfig['index']['stored_fields'])) { |
||
88 | foreach ($indexConfig['index']['stored_fields'] as $storedField) { |
||
89 | $index->addStoredField($storedField); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | $indexes[] = $index; |
||
94 | |||
95 | $this->indexesByName[$index->getName()] = $index; |
||
96 | } |
||
97 | |||
98 | return $indexes; |
||
99 | } |
||
172 |