Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.18.0

Request #15146 DRY - refactor common, duplicated code
Submitted: 2008-11-24 16:53 UTC Modified: 2008-11-24 22:55 UTC
From: doconnor Assigned:
Status: Open Package: Numbers_Words (version CVS)
PHP Version: 5.2.6 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2008-11-24 16:53 UTC] doconnor (Daniel O'Connor)
Description: ------------ Many of the drivers have common code in toWords() - ie, they do it the same as english. Consider implementing a utility class or refactoring into the parent class. Example duplicate code: if (strlen($num) > 3) { $maxp = strlen($num)-1; $curp = $maxp; for ($p = $maxp; $p > 0; --$p) { // power // check for highest power if (isset($this->_exponent[$p])) { // send substr from $curp to $p $snum = substr($num, $maxp - $curp, $curp - $p + 1); $snum = preg_replace('/^0+/','',$snum); if ($snum !== '') { $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1]; if ($powsuffix != '') { $cursuffix .= $this->_sep . $powsuffix; } $ret .= $this->toWords($snum, $p, $cursuffix); } $curp = $p - 1; continue; } } $num = substr($num, $maxp - $curp, $curp - $p + 1); if ($num == 0) { return $ret; } } elseif ($num == 0 || $num == '') { return $this->_sep . $this->_digits[0]; }

Comments

 [2008-11-24 22:55 UTC] doconnor (Daniel O'Connor)
After much review via Request #15145 1) A lot of languages simply copied and pasted from the English files. You can refactor much common content upwards 2) Some, like lang.fr.php and lang.fr_BE.php have no real differences aside from minor localised extra bits. Having one extend the other would make sense here.