| Conditions | 24 |
| Paths | > 20000 |
| Total Lines | 111 |
| Code Lines | 70 |
| Lines | 6 |
| Ratio | 5.41 % |
| 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 |
||
| 87 | protected function _interactive() { |
||
| 88 | $this->hr(); |
||
| 89 | $this->out(__d('cake_console', 'Database Configuration:')); |
||
| 90 | $this->hr(); |
||
| 91 | $done = false; |
||
| 92 | $dbConfigs = array(); |
||
| 93 | |||
| 94 | while (!$done) { |
||
| 95 | $name = ''; |
||
| 96 | |||
| 97 | while (!$name) { |
||
| 98 | $name = $this->in(__d('cake_console', "Name:"), null, 'default'); |
||
| 99 | if (preg_match('/[^a-z0-9_]/i', $name)) { |
||
| 100 | $name = ''; |
||
| 101 | $this->out(__d('cake_console', 'The name may only contain unaccented latin characters, numbers or underscores')); |
||
| 102 | } elseif (preg_match('/^[^a-z_]/i', $name)) { |
||
| 103 | $name = ''; |
||
| 104 | $this->out(__d('cake_console', 'The name must start with an unaccented latin character or an underscore')); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $datasource = $this->in(__d('cake_console', 'Datasource:'), array('Mysql', 'Postgres', 'Sqlite', 'Sqlserver'), 'Mysql'); |
||
| 109 | |||
| 110 | $persistent = $this->in(__d('cake_console', 'Persistent Connection?'), array('y', 'n'), 'n'); |
||
| 111 | if (strtolower($persistent) === 'n') { |
||
| 112 | $persistent = 'false'; |
||
| 113 | } else { |
||
| 114 | $persistent = 'true'; |
||
| 115 | } |
||
| 116 | |||
| 117 | $host = ''; |
||
| 118 | while (!$host) { |
||
| 119 | $host = $this->in(__d('cake_console', 'Database Host:'), null, 'localhost'); |
||
| 120 | } |
||
| 121 | |||
| 122 | $port = ''; |
||
| 123 | while (!$port) { |
||
| 124 | $port = $this->in(__d('cake_console', 'Port?'), null, 'n'); |
||
| 125 | } |
||
| 126 | |||
| 127 | if (strtolower($port) === 'n') { |
||
| 128 | $port = null; |
||
| 129 | } |
||
| 130 | |||
| 131 | $login = ''; |
||
| 132 | while (!$login) { |
||
| 133 | $login = $this->in(__d('cake_console', 'User:'), null, 'root'); |
||
| 134 | } |
||
| 135 | $password = ''; |
||
| 136 | $blankPassword = false; |
||
| 137 | |||
| 138 | while (!$password && !$blankPassword) { |
||
| 139 | $password = $this->in(__d('cake_console', 'Password:')); |
||
| 140 | |||
| 141 | View Code Duplication | if (!$password) { |
|
| 142 | $blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n'); |
||
| 143 | if ($blank === 'y') { |
||
| 144 | $blankPassword = true; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | $database = ''; |
||
| 150 | while (!$database) { |
||
| 151 | $database = $this->in(__d('cake_console', 'Database Name:'), null, 'cake'); |
||
| 152 | } |
||
| 153 | |||
| 154 | $prefix = ''; |
||
| 155 | while (!$prefix) { |
||
| 156 | $prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n'); |
||
| 157 | } |
||
| 158 | if (strtolower($prefix) === 'n') { |
||
| 159 | $prefix = null; |
||
| 160 | } |
||
| 161 | |||
| 162 | $encoding = ''; |
||
| 163 | while (!$encoding) { |
||
| 164 | $encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n'); |
||
| 165 | } |
||
| 166 | if (strtolower($encoding) === 'n') { |
||
| 167 | $encoding = null; |
||
| 168 | } |
||
| 169 | |||
| 170 | $schema = ''; |
||
| 171 | if ($datasource === 'postgres') { |
||
| 172 | while (!$schema) { |
||
| 173 | $schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n'); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | if (strtolower($schema) === 'n') { |
||
| 177 | $schema = null; |
||
| 178 | } |
||
| 179 | |||
| 180 | $config = compact('name', 'datasource', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema'); |
||
| 181 | |||
| 182 | while (!$this->_verify($config)) { |
||
| 183 | $this->_interactive(); |
||
| 184 | } |
||
| 185 | |||
| 186 | $dbConfigs[] = $config; |
||
| 187 | $doneYet = $this->in(__d('cake_console', 'Do you wish to add another database configuration?'), null, 'n'); |
||
| 188 | |||
| 189 | if (strtolower($doneYet === 'n')) { |
||
| 190 | $done = true; |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | $this->bake($dbConfigs); |
||
| 195 | config('database'); |
||
| 196 | return true; |
||
| 197 | } |
||
| 198 | |||
| 383 |