On Sat, Mar 24, 2012 at 3:24 PM, Marc Delisle <span dir="ltr"><<a href="mailto:marc@infomarc.info">marc@infomarc.info</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
As refactoring ideas are numerous in the GSoC 2012 ideas list, I propose<br>
a challenge. The goal is to discuss on this list an existing code<br>
snippet from phpMyAdmin and to arrive at the best possible refactored<br>
version.<br>
<br>
At the same time, potential students can show their refactoring skills<br>
or learn what refactoring is about.<br>
<br>
Let's discuss these lines from tbl_structure.php (in current master,<br>
these start at line 263 of the script):<br>
<br>
$start = 0;<br>
if (strlen($type) > $GLOBALS['cfg']['LimitChars']) {<br>
$start = 13;<br>
$type = '<abbr title="' . $type . '">' . substr($type, 0,<br>
$GLOBALS['cfg']['LimitChars']) . '</abbr>';<br>
}<br>
<br>
unset($field_charset);<br>
if ((substr($type, $start, 4) == 'char'<br>
|| substr($type, $start, 7) == 'varchar'<br>
|| substr($type, $start, 4) == 'text'<br>
|| substr($type, $start, 8) == 'tinytext'<br>
|| substr($type, $start, 10) == 'mediumtext'<br>
|| substr($type, $start, 8) == 'longtext'<br>
|| substr($type, $start, 3) == 'set'<br>
|| substr($type, $start, 4) == 'enum')<br>
&& !$extracted_fieldspec['binary']<br>
) {<br>
if (strpos($type, ' character set ')) {<br>
$type = substr($type, 0, strpos($type, ' character set '));<br>
}<br>
if (!empty($row['Collation'])) {<br>
$field_charset = $row['Collation'];<br>
} else {<br>
$field_charset = '';<br>
}<br>
} else {<br>
$field_charset = '';<br>
}<span class="HOEnZb"><font color="#888888"><br>
</font></span></blockquote><div><br>Hello, <br></div></div> <br>I find these refactoring guidelines useful for everyone, so I'll have a go:<br><br> $start = 0;<br> if ( strlen( $type ) > $GLOBALS['cfg']['LimitChars'] ) {<br>
$start = 13; // strlen( '<abbr title="' );<br> $type = '<abbr title="' . $type . '">'<br> . substr( $type, 0, $GLOBALS['cfg']['LimitChars'] )<br>
. '</abbr>';<br> }<br><br> unset( $field_charset );<br> $matches_type = ( substr($type, $start, 4) == 'char'<br> || substr($type, $start, 7) == 'varchar'<br>
|| substr($type, $start, 4) == 'text'<br> || substr($type, $start, 8) == 'tinytext'<br> || substr($type, $start, 10) == 'mediumtext'<br>
|| substr($type, $start, 8) == 'longtext'<br> || substr($type, $start, 3) == 'set'<br> || substr($type, $start, 4) == 'enum'<br>
);<br> $field_charset = '';<br> if ( $matches_type && ! $extracted_fieldspec['binary'] ) {<br> if ( strpos( $type, ' character set ' ) ) {<br> $type = substr( $type, 0, strpos( $type, ' character set ' ) );<br>
}<br> if ( ! empty( $row['Collation'] ) ) {<br> $field_charset = $row['Collation'];<br> }<br> }<br><br><br>These are some refactoring modifications I would see fit, but I am sure<br>
there are others, so I would like to see different approaches.<br><br>--<br>Alex<br>