LoginSignup
5
2

More than 5 years have passed since last update.

今日のクソコード

Last updated at Posted at 2016-03-31

仕様書も何もないので直接プログラムをみて、ある機能の修正しなければいけない
そこで遭遇した今日のクソコード

$this->searchForm['search']['month'] は「201603」などの検索月がはいるのだが。。。

$target_month = $this->searchForm['search']['month'];

$tt = explode(',', date('t,j,Y-m-,t,Y-m-,w', strtotime("${target_month}01")));

このあと$ttを使っているのだが。。。
$ttで検索してもらいたい

~~~~
if($target_month != date('Ym')){
    //過去日の場合
    $tt[1] = $tt[0];
    unset($tt[2]);
}else{
    $tt[1] = date('j') - 1;
    $tt[2] .= $tt[1];
}

$rday = 0;
if($tt[2]){
    $i = 1;$j = 0;
    while(($dd = $tt[1] + $i++) <= $tt[0]){
        $__w = ($dd - 1 + $tt[5]) % 7;
        if($this->ckDeliveryDate($delivery_schedule, $__w, $dd))$rday++;
    }
}

$line['budget_rate'] = $this->divide($re['cost'], $r['budget_operation']);
if(!$isDevice && $tt[2] && isset($re['daily_cost'])){ //if(isset($re['avg'])){
    $i = 0;$j = 0;
    $_avg = 0;
    while(($dd = $tt[1] - $i++) > 0){
        $d = sprintf("%s%02d", $tt[4], $dd);
        $__w = ($dd - 1 + $tt[5]) % 7;
        $flg = $this->ckDeliveryDate($delivery_schedule, $__w, $dd);
        if(!$flg && (!isset($daily_map) || !isset($daily_map[$dd])))continue;
        $_avg += $re['daily_cost'][$d]['cost'];
        if(++$j >= 7)break;
    }
    $line['forecast'] = $line['actual'] + $this->divide($_avg * $rday, $j, 1, 0);   //$re['avg']['cost']
}else{
    $line['forecast'] = $this->divide($re['cost'] * $tt[0], $tt[1], 1, 0);
}

~~~~

$tt[0]ってなんの日付!? $tt[1] ってなんの日付!?
怖くてリファクタできません。。

あとで気づいたんだけど"${target_month}01"←これって動くんだ

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2