<br><br><div class="gmail_quote">On Sat, Mar 24, 2012 at 9:59 PM, Alex Marin <span dir="ltr"><<a href="mailto:alex.ukf@gmail.com" target="_blank">alex.ukf@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div><br><div class="gmail_quote">On Sat, Mar 24, 2012 at 6:20 PM, Alex Marin <span dir="ltr"><<a href="mailto:alex.ukf@gmail.com" target="_blank">alex.ukf@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="gmail_quote"><div>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><div> $type = '<abbr title="' . $type . '">'<br></div> . substr( $type, 0, $GLOBALS['cfg']['LimitChars'] )<br>
<div>
. '</abbr>';<br> }<br><br> unset( $field_charset );<br></div> $matches_type = ( substr($type, $start, 4) == 'char'<br><div> || 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>
</div>
);<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>
</blockquote></div><br></div></div>Without the 3 unnecessary newlines of course ( that were inserted <br>before my copy-pasted sections).<br>
<br>
--<br>
Alex<br>
<br>------------------------------------------------------------------------------<br>
This SF email is sponsosred by:<br>
Try Windows Azure free for 90 days Click Here<br>
<a href="http://p.sf.net/sfu/sfd2d-msazure" target="_blank">http://p.sf.net/sfu/sfd2d-msazure</a><br>_______________________________________________<br>
Phpmyadmin-devel mailing list<br>
<a href="mailto:Phpmyadmin-devel@lists.sourceforge.net" target="_blank">Phpmyadmin-devel@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/phpmyadmin-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/phpmyadmin-devel</a><br>
<br></blockquote></div><br>Hi Marc,<br><br>I have not learn yet the PHP code refactoring techniques. But I like to learn them. I tried to do some improvements on that code (tbl_structure.php : in current master, these start at line 263 of the script).<br>
<br>changes :<br>* Create an array for store data types ($dataTypesArray)<br>* Introduced a Boolean to check whether the string manipulating condition is true or false ($isTypeMatched)<br>
* Since there was a common pattern in conditions, create those condition check inside a loop using $isTypeMatched boolean<br>* Use meaningful non-common names to new variables<br>* Keep empty spaces between code snippets to increase the readability of the code<br>
<br> $start = 0;<br> if (strlen($type) > $GLOBALS['cfg']['LimitChars']) {<br> $start = 13;<br> $type = '<abbr title="' . $type . '">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';<br>
}<br> <br> unset($field_charset); <br> $dataTypesArray = array('char', 'varchar', 'text', 'tinytext', 'mediumtext', 'longtext', 'set', 'enum');<br>
$isTypeMatched = false;<br><br> foreach ($dataTypesArray as $dataType) {<br> if (substr($type, $start, strlen($dataType)) == $dataType) {<br> $isTypeMatched = true;<br> break;<br> }<br>
}<br> <br> if ($isTypeMatched && !$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> } else {<br> $field_charset = '';<br> }<br> } else {<br> $field_charset = '';<br>
} <br clear="all"><br>With this, though the number of data types need to increase, only needed change is adding new data types to $dataTypesArray. No need of adding more conditions.<br>Does the above mentioned changes are make the code better ?<br>
<br>Regards !<br>-- <br>____________________________________<br><br>Chanaka Indrajith<br>Bsc.Computer Engineering Undergraduate<br>Faculty of Engineering<br>University of Peradeniya<br>____________________________________<br>
<br>