Changes between Version 3 and Version 4 of リファクタリングガイドライン


Ignore:
Timestamp:
2011/01/30 01:34:06 (11 years ago)
Author:
Seasoft
Comment:

現行の標準規約から外れたサンプルコードを修正

Legend:

Unmodified
Added
Removed
Modified
  • リファクタリングガイドライン

    v3 v4  
    2525     */ 
    2626    $this->tpl_mainpage = 'index.tpl'; 
    27     $this->arrDISP = $masterData->getMasterData("mtb_disp"); 
     27    $this->arrDISP = $masterData->getMasterData('mtb_disp'); 
    2828} 
    2929}}} 
     
    7878        /** NG SQLを実行する処理を記述してはならない */ 
    7979        $objQuery =& SC_Query::getSingletonInstance(); 
    80         $arrResults = $objQuery->select("*", "table_name"); 
     80        $arrResults = $objQuery->select('*', 'table_name'); 
    8181 
    8282        $this->doDisp($this->arrForm); 
     
    8585    case 'complete': 
    8686        $this->registerProductClass($this->arrForm, $this->arrForm['product_id']); 
    87         SC_Response_Ex::sendRedirect("complete.php"); 
     87        SC_Response_Ex::sendRedirect('complete.php'); 
    8888        break; 
    8989 
     
    108108 
    109109case 'complete': 
    110     SC_Response_Ex::sendRedirect("complete.php"); 
     110    SC_Response_Ex::sendRedirect('complete.php'); 
    111111    break; 
    112112default: 
     
    117117    $this->doDisp($this->arrForm); 
    118118} elseif ($_POST['mode'] == 'complete') { 
    119     SC_Response_Ex::sendRedirect("complete.php"); 
     119    SC_Response_Ex::sendRedirect('complete.php'); 
    120120} 
    121121?> 
     
    154154 */ 
    155155function lfConvertLoginPass(){ 
    156     if(strlen($this->arrForm["login_pass"]) < 1 ) { 
     156    if(strlen($this->arrForm['login_pass']) < 1 ) { 
    157157        return; 
    158158    } 
    159     $this->arrForm["login_pass"] = trim($this->arrForm["login_pass"]); 
    160     $this->arrForm["login_pass1"] = $this->arrForm["login_pass"]; 
    161     $this->arrForm["login_pass2"] = $this->arrForm["login_pass"]; 
     159    $this->arrForm['login_pass'] = trim($this->arrForm['login_pass']); 
     160    $this->arrForm['login_pass1'] = $this->arrForm['login_pass']; 
     161    $this->arrForm['login_pass2'] = $this->arrForm['login_pass']; 
    162162} 
    163163 
     
    169169 
    170170function lfConvertLoginPass(&$arrForm){ 
    171     if(strlen($arrForm["login_pass"]) < 1 ) { 
     171    if(strlen($arrForm['login_pass']) < 1 ) { 
    172172        return; 
    173173    } 
    174     $arrForm["login_pass"] = trim($arrForm["login_pass"]); 
    175     $arrForm["login_pass1"] = $arrForm["login_pass"]; 
    176     $arrForm["login_pass2"] = $arrForm["login_pass"]; 
     174    $arrForm['login_pass'] = trim($arrForm['login_pass']); 
     175    $arrForm['login_pass1'] = $arrForm['login_pass']; 
     176    $arrForm['login_pass2'] = $arrForm['login_pass']; 
    177177    return $arrForm; 
    178178} 
     
    182182 */ 
    183183function testLfConvertLoginPass() { 
    184     $login_pass = "login_pass_value"; 
    185     $arrForm = array("login_pass" => $login_pass); 
    186  
    187     $expected = array("login_pass" => $login_pass, 
    188                       "login_pass1" => $login_pass, 
    189                       "login_pass2" => $login_pass); 
     184    $login_pass = 'login_pass_value'; 
     185    $arrForm = array('login_pass' => $login_pass); 
     186 
     187    $expected = array('login_pass' => $login_pass, 
     188                      'login_pass1' => $login_pass, 
     189                      'login_pass2' => $login_pass); 
    190190 
    191191    $actual = lfConvertLoginPass($arrForm); 
     
    257257 * NG 類似した SQL を散乱させてはいけない 
    258258 */ 
    259 $arrResults = $objQuery->select("id, name, foo, bar", "table_name"); 
    260 $arrResult2 = $objQuery->select("id, name, foo, bar, too", "table_name", "too = ?", $arrParams['too']); 
     259$arrResults = $objQuery->select('id, name, foo, bar', 'table_name'); 
     260$arrResult2 = $objQuery->select('id, name, foo, bar, too', 'table_name', 'too = ?', $arrParams['too']); 
    261261 
    262262/** 
     
    264264 */ 
    265265function getResults($arrParams = array()) { 
    266     $where = ""; 
     266    $where = ''; 
    267267    $arrValues = array(); 
    268268    if (isset($arrParams['too'])) { 
    269         $where .= "too = ?"; 
     269        $where .= 'too = ?'; 
    270270        $arrValues[] = $arrParams['too']; 
    271271 
    272272    } 
    273273    $objQuery =& SC_Query::getSingletonInstance(); 
    274     $arrResults = $objQuery->select("*", "table_name", $where, $arrValues); 
     274    $arrResults = $objQuery->select('*', 'table_name', $where, $arrValues); 
    275275} 
    276276$arrResults = getResults(); 
     
    288288/** NG SC_Query::query() は使用しない */ 
    289289$objQuery =& SC_Query::getSingletonInstance(); 
    290 $objQuery->query("INSERT INTO table_name (col1, col2) VALUES (?, ?)", arrary($col1, $col2)); 
     290$objQuery->query('INSERT INTO table_name (col1, col2) VALUES (?, ?)', arrary($col1, $col2)); 
    291291 
    292292/** OK SC_Query::insert(), SC_Query::update(),  SC_Query::delete() を使用する */ 
    293293$objQuery =& SC_Query::getSingletonInstance(); 
    294 $objQuery->insert("table_name", array("col1" => $col1, 
    295                                       "col2" => $col2)); 
     294$objQuery->insert('table_name', array('col1' => $col1, 
     295                                      'col2' => $col2)); 
    296296 
    297297?> 
     
    314314/** OK 必ず入力チェックを行う */ 
    315315$objFormParam = new SC_FormParam(); 
    316 $objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n  
    317 ", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); 
     316$objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); 
    318317$objFormParam->setParam($_POST); 
    319318$objFormParam->convParam();