| Conditions | 9 |
| Paths | 10 |
| Total Lines | 68 |
| Code Lines | 36 |
| 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 |
||
| 81 | private function loadDatabase($databaseFile) |
||
| 82 | { |
||
| 83 | // add gettext domain |
||
| 84 | bindtextdomain( |
||
| 85 | $this->getISONumber(), |
||
| 86 | $this->getLocalMessagesPath() |
||
| 87 | ); |
||
| 88 | |||
| 89 | bind_textdomain_codeset( |
||
| 90 | $this->getISONumber(), |
||
| 91 | 'UTF-8' |
||
| 92 | ); |
||
| 93 | |||
| 94 | // load database from json file |
||
| 95 | $json = json_decode( |
||
| 96 | file_get_contents($databaseFile), |
||
| 97 | true |
||
| 98 | ); |
||
| 99 | |||
| 100 | // build index from database |
||
| 101 | $entryList = $json[$this->getISONumber()]; |
||
| 102 | |||
| 103 | // index database |
||
| 104 | $indexedFields = $this->getIndexDefinition(); |
||
| 105 | |||
| 106 | if (empty($indexedFields)) { |
||
| 107 | $this->clusterIndex = $entryList; |
||
| 108 | } else { |
||
| 109 | // init all defined indexes |
||
| 110 | foreach ($entryList as &$entry) { |
||
| 111 | foreach ($indexedFields as $indexName => $indexDefinition) { |
||
| 112 | if (is_array($indexDefinition)) { |
||
| 113 | $reference = &$this->index[$indexName]; |
||
| 114 | // compound index |
||
| 115 | foreach ($indexDefinition as $indexDefinitionPart) { |
||
| 116 | // limited length of field |
||
| 117 | if (is_array($indexDefinitionPart)) { |
||
| 118 | $indexDefinitionPartValue = substr( |
||
| 119 | $entry[$indexDefinitionPart[0]], |
||
| 120 | 0, |
||
| 121 | $indexDefinitionPart[1] |
||
| 122 | ); |
||
| 123 | } else { |
||
| 124 | $indexDefinitionPartValue = $entry[$indexDefinitionPart]; |
||
| 125 | } |
||
| 126 | if (!isset($reference[$indexDefinitionPartValue])) { |
||
| 127 | $reference[$indexDefinitionPartValue] = []; |
||
| 128 | } |
||
| 129 | $reference = &$reference[$indexDefinitionPartValue]; |
||
| 130 | } |
||
| 131 | |||
| 132 | $reference = $this->arrayToEntry($entry); |
||
| 133 | } else { |
||
| 134 | // single index |
||
| 135 | $indexName = $indexDefinition; |
||
| 136 | // skip empty field |
||
| 137 | if (empty($entry[$indexDefinition])) { |
||
| 138 | continue; |
||
| 139 | } |
||
| 140 | // add to index |
||
| 141 | $this->index[$indexName][$entry[$indexDefinition]] = $this->arrayToEntry($entry); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | // set cluster index as first index |
||
| 147 | $clusterIndexName = key($this->index); |
||
| 148 | $this->clusterIndex = &$this->index[$clusterIndexName]; |
||
| 149 | } |
||
| 219 |