Conditions | 6 |
Paths | 10 |
Total Lines | 54 |
Code Lines | 23 |
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 declare(strict_types=1); |
||
72 | public function backupData($exclude=[]) |
||
73 | { |
||
74 | $tables = $this->getDriver()->getTables(); |
||
75 | |||
76 | // Filter out the tables you don't want |
||
77 | if( ! empty($exclude)) |
||
78 | { |
||
79 | $tables = array_diff($tables, $exclude); |
||
80 | } |
||
81 | |||
82 | $outputSql = ''; |
||
83 | |||
84 | // Select the rows from each Table |
||
85 | foreach($tables as $t) |
||
86 | { |
||
87 | $sql = "SELECT * FROM `{$t}`"; |
||
88 | $res = $this->getDriver()->query($sql); |
||
|
|||
89 | $rows = $res->fetchAll(PDO::FETCH_ASSOC); |
||
90 | |||
91 | // Skip empty tables |
||
92 | if (count($rows) < 1) |
||
93 | { |
||
94 | continue; |
||
95 | } |
||
96 | |||
97 | // Nab the column names by getting the keys of the first row |
||
98 | $columns = @array_keys($rows[0]); |
||
99 | |||
100 | $insertRows = []; |
||
101 | |||
102 | // Create the insert statements |
||
103 | foreach($rows as $row) |
||
104 | { |
||
105 | $row = array_values($row); |
||
106 | |||
107 | // Workaround for Quercus |
||
108 | foreach($row as &$r) |
||
109 | { |
||
110 | $r = $this->getDriver()->quote($r); |
||
111 | } |
||
112 | $row = array_map('trim', $row); |
||
113 | |||
114 | $rowString = 'INSERT INTO `'.trim($t).'` (`'.implode('`,`', $columns).'`) VALUES ('.implode(',', $row).');'; |
||
115 | |||
116 | $row = NULL; |
||
117 | |||
118 | $insertRows[] = $rowString; |
||
119 | } |
||
120 | |||
121 | $outputSql .= "\n\n".implode("\n", $insertRows)."\n"; |
||
122 | } |
||
123 | |||
124 | return $outputSql; |
||
125 | } |
||
126 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.