| Conditions | 4 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 28 |
| 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 |
||
| 68 | * |
||
| 69 | * @return string Converted table name |
||
| 70 | */ |
||
| 71 | public function getTable($table, $dbName = null, $table_extension = null) |
||
| 72 | { |
||
| 73 | // This is a workaround for a one-to-many mapping |
||
| 74 | // as required by Labs. We combine $table with |
||
| 75 | // $table_extension in order to generate the new table name |
||
| 76 | if ($this->isLabs() && $table_extension !== null) { |
||
| 77 | $table = $table . "_" . $table_extension; |
||
| 78 | } |
||
| 79 | |||
| 80 | // Use the table specified in the table mapping configuration, if present. |
||
| 81 | $mapped = false; |
||
|
|
|||
| 82 | View Code Duplication | if ($this->container->hasParameter("app.table.$table")) { |
|
| 83 | $mapped = true; |
||
| 84 | $table = $this->container->getParameter("app.table.$table"); |
||
| 85 | } |
||
| 86 | |||
| 87 | // Figure out database name. |
||
| 88 | // Use class variable for the database name if not set via function parameter. |
||
| 89 | $dbNameActual = $dbName ? $dbName : $this->dbName; |
||
| 90 | if ($this->isLabs() && substr($dbNameActual, -2) != '_p') { |
||
| 91 | // Append '_p' if this is labs. |
||
| 92 | $dbNameActual .= '_p'; |
||
| 93 | } |
||
| 94 | |||
| 95 | return $dbNameActual ? "$dbNameActual.$table" : $table; |
||
| 96 | } |
||
| 97 | |||
| 98 | // TODO: figure out how to use Doctrine to query host 'tools-db' |
||
| 99 | } |
||
| 100 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.