| Conditions | 10 | 
| Paths | 22 | 
| Total Lines | 45 | 
| Code Lines | 24 | 
| 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  | 
            ||
| 48 | public function requireDefaultRecords()  | 
            ||
| 49 |     { | 
            ||
| 50 |         if (!UserDefinedForm::config()->get('upgrade_on_build')) { | 
            ||
| 51 | return;  | 
            ||
| 52 | }  | 
            ||
| 53 | |||
| 54 | $updated = 0;  | 
            ||
| 55 |         foreach ($this->targets as $className => $fieldNames) { | 
            ||
| 56 |             foreach ($fieldNames as $fieldName) { | 
            ||
| 57 | /** @var DataList $list */  | 
            ||
| 58 | $list = $className::get();  | 
            ||
| 59 | |||
| 60 |                 foreach ($list as $entry) { | 
            ||
| 61 | /** @var DataObject $relationshipObject */  | 
            ||
| 62 | $relationshipObject = Injector::inst()->get($entry->$fieldName);  | 
            ||
| 63 |                     if (!$relationshipObject) { | 
            ||
| 64 | continue;  | 
            ||
| 65 | }  | 
            ||
| 66 | |||
| 67 | // If the defined data class doesn't have the UserForm trait applied, it's probably wrong. Re-map  | 
            ||
| 68 | // it to a default value that does  | 
            ||
| 69 | $classTraits = class_uses($relationshipObject);  | 
            ||
| 70 |                     if (in_array(UserForm::class, $classTraits)) { | 
            ||
| 71 | continue;  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 | $entry->$fieldName = $this->defaultReplacement;  | 
            ||
| 75 |                     try { | 
            ||
| 76 | $entry->write();  | 
            ||
| 77 | $updated++;  | 
            ||
| 78 |                     } catch (ValidationException $ex) { | 
            ||
| 79 | // no-op, allow the rest of dev/build to continue. There may be an error indicating that the  | 
            ||
| 80 |                         // object's class doesn't exist, which can be fixed by {@link DatabaseAdmin::doBuild} and this | 
            ||
| 81 | // logic will work the next time dev/build is run.  | 
            ||
| 82 | }  | 
            ||
| 83 | }  | 
            ||
| 84 | }  | 
            ||
| 85 | }  | 
            ||
| 86 | |||
| 87 |         if ($updated) { | 
            ||
| 88 |             $message = "Corrected {$updated} default polymorphic class names to {$this->defaultReplacement}"; | 
            ||
| 89 |             if (Director::is_cli()) { | 
            ||
| 90 |                 echo sprintf(" * %s\n", $message); | 
            ||
| 91 |             } else { | 
            ||
| 92 |                 echo sprintf("<li>%s</li>\n", $message); | 
            ||
| 93 | }  | 
            ||
| 97 |