| Conditions | 11 | 
| Paths | 594 | 
| Total Lines | 51 | 
| Code Lines | 26 | 
| 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  | 
            ||
| 79 | public function run(LoggerInterface $logger = null)  | 
            ||
| 80 |     { | 
            ||
| 81 | $hasChanges = false;  | 
            ||
| 82 |         foreach ($this->tables as $table) { | 
            ||
| 83 |             if ($table->getComparator()->hasChanges()) { | 
            ||
| 84 | $hasChanges = true;  | 
            ||
| 85 | break;  | 
            ||
| 86 | }  | 
            ||
| 87 | }  | 
            ||
| 88 | |||
| 89 |         if (!$hasChanges) { | 
            ||
| 90 | //Nothing to do  | 
            ||
| 91 | return;  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 94 | $this->beginTransaction();  | 
            ||
| 95 | |||
| 96 |         try { | 
            ||
| 97 | //Drop not-needed foreign keys and alter everything else  | 
            ||
| 98 |             foreach ($this->sortedTables() as $table) { | 
            ||
| 99 |                 if ($table->exists()) { | 
            ||
| 100 | $table->save(Behaviour::DROP_FOREIGNS, $logger, false);  | 
            ||
| 101 | }  | 
            ||
| 102 | }  | 
            ||
| 103 | |||
| 104 | //Drop not-needed indexes  | 
            ||
| 105 |             foreach ($this->sortedTables() as $table) { | 
            ||
| 106 |                 if ($table->exists()) { | 
            ||
| 107 | $table->save(Behaviour::DROP_INDEXES, $logger, false);  | 
            ||
| 108 | }  | 
            ||
| 109 | }  | 
            ||
| 110 | |||
| 111 | //Other changes [NEW TABLES WILL BE CREATED HERE!]  | 
            ||
| 112 |             foreach ($this->sortedTables() as $table) { | 
            ||
| 113 | $table->save(  | 
            ||
| 114 | Behaviour::DO_ALL ^ Behaviour::DROP_FOREIGNS ^ Behaviour::DROP_INDEXES ^ Behaviour::CREATE_FOREIGNS,  | 
            ||
| 115 | $logger  | 
            ||
| 116 | );  | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 | //Finishing with new foreign keys  | 
            ||
| 120 |             foreach ($this->sortedTables() as $table) { | 
            ||
| 121 | $table->save(Behaviour::CREATE_FOREIGNS, $logger, true);  | 
            ||
| 122 | }  | 
            ||
| 123 |         } catch (\Throwable $e) { | 
            ||
| 124 | $this->rollbackTransaction();  | 
            ||
| 125 | throw $e;  | 
            ||
| 126 | }  | 
            ||
| 127 | |||
| 128 | $this->commitTransaction();  | 
            ||
| 129 | }  | 
            ||
| 130 | |||
| 173 |