| Conditions | 17 |
| Paths | 112 |
| Total Lines | 77 |
| Lines | 6 |
| Ratio | 7.79 % |
| 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 |
||
| 74 | public function convert($database = null) |
||
| 75 | { |
||
| 76 | if (!is_null($database)) { |
||
| 77 | $this->database = $database; |
||
| 78 | $this->customDb = true; |
||
| 79 | } |
||
| 80 | |||
| 81 | // Get the tables for the database |
||
| 82 | $tables = $this->getTables(); |
||
| 83 | $result = []; |
||
| 84 | |||
| 85 | // Get tables to ignore |
||
| 86 | $config = config('db-exporter.seeds'); |
||
| 87 | $ignore_tables = collect([]); |
||
| 88 | View Code Duplication | if(!is_null($config) && isset($config['ignore_tables']) && !is_null($config['ignore_tables'])) { |
|
| 89 | $ignore_tables = collect($config['ignore_tables']); |
||
| 90 | } |
||
| 91 | |||
| 92 | $show_tables = collect([]); |
||
| 93 | View Code Duplication | if(!is_null($config) && isset($config['use_tables']) && !is_null($config['use_tables'])) { |
|
| 94 | $show_tables = collect($config['use_tables']); |
||
| 95 | } |
||
| 96 | |||
| 97 | // Loop over the tables |
||
| 98 | foreach ($tables as $key => $value) |
||
| 99 | { |
||
| 100 | if($show_tables->count() > 0 && !$show_tables->contains($value['table_name'])) { |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | |||
| 104 | if($ignore_tables->contains($value['table_name'])) { |
||
| 105 | continue; |
||
| 106 | } |
||
| 107 | |||
| 108 | // Do not export the ignored tables |
||
| 109 | if (in_array($value['table_name'], self::$ignore)) { |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | |||
| 113 | $tableName = $value['table_name']; |
||
| 114 | $tableData = $this->getTableData($value['table_name']); |
||
| 115 | $insertStub = ''; |
||
| 116 | |||
| 117 | foreach ($tableData as $obj) { |
||
| 118 | $insertStub .= " |
||
| 119 | [\n"; |
||
| 120 | foreach ($obj as $prop => $value) { |
||
| 121 | $insertStub .= $this->insertPropertyAndValue($prop, $value); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (count($tableData) > 1) { |
||
| 125 | $insertStub .= " ],\n"; |
||
| 126 | } else { |
||
| 127 | $insertStub .= " ]\n"; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $insertStub = " |
||
| 132 | \$data = [ |
||
| 133 | {$insertStub} |
||
| 134 | ];"; |
||
| 135 | |||
| 136 | if ($this->hasTableData($tableData)) { |
||
| 137 | $stub = $insertStub.' |
||
| 138 | |||
| 139 | foreach($data as $item) |
||
| 140 | { |
||
| 141 | $this->saveData("'.$tableName.'", $item); |
||
| 142 | }'; |
||
| 143 | $result[$tableName] = $stub; |
||
| 144 | } |
||
| 145 | }//end foreach |
||
| 146 | |||
| 147 | $this->seedingStub = $result; |
||
| 148 | |||
| 149 | return $this; |
||
| 150 | } |
||
| 151 | |||
| 204 |