| Conditions | 17 | 
| Paths | 224 | 
| Total Lines | 94 | 
| Code Lines | 58 | 
| 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  | 
            ||
| 115 | public function getFieldIntrospection($field)  | 
            ||
| 116 |     { | 
            ||
| 117 |         $fullfield = str_replace('.', '_', $field); | 
            ||
| 118 | $classes = $this->index->getClass();  | 
            ||
| 119 | |||
| 120 | $found = [];  | 
            ||
| 121 | |||
| 122 |         if (strpos($field, '.') !== false) { | 
            ||
| 123 |             $lookups = explode('.', $field); | 
            ||
| 124 | $field = array_pop($lookups);  | 
            ||
| 125 | |||
| 126 |             foreach ($lookups as $lookup) { | 
            ||
| 127 | $next = [];  | 
            ||
| 128 | |||
| 129 |                 foreach ($classes as $source) { | 
            ||
| 130 | list($class, $singleton, $next) = $this->getRelationIntrospection($source, $lookup, $next);  | 
            ||
| 131 | }  | 
            ||
| 132 | |||
| 133 |                 if (!$next) { | 
            ||
| 134 | return $next;  | 
            ||
| 135 | } // Early out to avoid excessive empty looping  | 
            ||
| 136 | $classes = $next;  | 
            ||
| 137 | }  | 
            ||
| 138 | }  | 
            ||
| 139 | |||
| 140 |         foreach ($classes as $class => $fieldoptions) { | 
            ||
| 141 |             if (is_int($class)) { | 
            ||
| 142 | $class = $fieldoptions;  | 
            ||
| 143 | $fieldoptions = [];  | 
            ||
| 144 | }  | 
            ||
| 145 | $class = $this->getSourceName($class);  | 
            ||
| 146 | $dataclasses = SearchIntrospection::hierarchy($class);  | 
            ||
| 147 | |||
| 148 |             while (count($dataclasses)) { | 
            ||
| 149 | $dataclass = array_shift($dataclasses);  | 
            ||
| 150 | $type = null;  | 
            ||
| 151 | |||
| 152 | $fields = DataObject::getSchema()->databaseFields($class);  | 
            ||
| 153 | |||
| 154 |                 if (isset($fields[$field])) { | 
            ||
| 155 | $type = $fields[$field];  | 
            ||
| 156 | $fieldoptions['lookup_chain'][] = [  | 
            ||
| 157 | 'call' => 'property',  | 
            ||
| 158 | 'property' => $field  | 
            ||
| 159 | ];  | 
            ||
| 160 |                 } else { | 
            ||
| 161 | $singleton = singleton($dataclass);  | 
            ||
| 162 | |||
| 163 |                     if ($singleton->hasMethod("get$field") || $singleton->hasField($field)) { | 
            ||
| 164 | $type = $singleton->castingClass($field);  | 
            ||
| 165 |                         if (!$type) { | 
            ||
| 166 | $type = 'String';  | 
            ||
| 167 | }  | 
            ||
| 168 | |||
| 169 |                         if ($singleton->hasMethod("get$field")) { | 
            ||
| 170 | $fieldoptions['lookup_chain'][] = [  | 
            ||
| 171 | 'call' => 'method',  | 
            ||
| 172 | 'method' => "get$field"  | 
            ||
| 173 | ];  | 
            ||
| 174 |                         } else { | 
            ||
| 175 | $fieldoptions['lookup_chain'][] = [  | 
            ||
| 176 | 'call' => 'property',  | 
            ||
| 177 | 'property' => $field  | 
            ||
| 178 | ];  | 
            ||
| 179 | }  | 
            ||
| 180 | }  | 
            ||
| 181 | }  | 
            ||
| 182 | |||
| 183 |                 if ($type) { | 
            ||
| 184 | // Don't search through child classes of a class we matched on. TODO: Should we?  | 
            ||
| 185 | $dataclasses = array_diff($dataclasses, array_values(ClassInfo::subclassesFor($dataclass)));  | 
            ||
| 186 | // Trim arguments off the type string  | 
            ||
| 187 |                     if (preg_match('/^(\w+)\(/', $type, $match)) { | 
            ||
| 188 | $type = $match[1];  | 
            ||
| 189 | }  | 
            ||
| 190 | // Get the origin  | 
            ||
| 191 | $origin = isset($fieldoptions['origin']) ? $fieldoptions['origin'] : $dataclass;  | 
            ||
| 192 | |||
| 193 | $origin = ClassInfo::shortName($origin);  | 
            ||
| 194 |                     $found["{$origin}_{$fullfield}"] = array( | 
            ||
| 195 |                         'name'         => "{$origin}_{$fullfield}", | 
            ||
| 196 | 'field' => $field,  | 
            ||
| 197 | 'fullfield' => $fullfield,  | 
            ||
| 198 | 'origin' => $origin,  | 
            ||
| 199 | 'class' => $dataclass,  | 
            ||
| 200 | 'lookup_chain' => $fieldoptions['lookup_chain'],  | 
            ||
| 201 | 'type' => $type,  | 
            ||
| 202 | 'multi_valued' => isset($fieldoptions['multi_valued']) ? true : false,  | 
            ||
| 203 | );  | 
            ||
| 204 | }  | 
            ||
| 205 | }  | 
            ||
| 206 | }  | 
            ||
| 207 | |||
| 208 | return $found;  | 
            ||
| 209 | }  | 
            ||
| 336 |