I am not amused

I am working on a codebase developed by an ex-employee, correcting code like:

1
2
3
4
5
6
7
8
9
10
$x = $y = 0;
while ($x < $interval + 1) {
    $looped_date = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $y, date('Y'));
    $formatted_looped_date = implode('/', array_reverse(explode('-', $looped_date)));
    $looped_date = implode('', array_reverse(explode('/', $formatted_looped_date)));
    $month = "$looped_date[4]$looped_date[5]";
    /* bunch of code */
    $x++;
    $y++;
}

Here are some snippets for the bunch of code above:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if ($range == 'daily') {
    if ($type == 'credit') {
        $container->cells[] = '&nbsp;';
        $container->cells[] = $value;
        $container->cells[] = '-';
    } else {
        $container->cells[] = $value;
        $container->cells[] = '&nbsp;';
        $container->cells[] = '-';
    }
}
 
if ($range == 'monthly') {
    if ($type == 'credit') {
        $container->cells[] = '&nbsp;';
        $container->cells[] = $value;
        $container->cells[] = '-';
    } else {
        $container->cells[] = $value;
        $container->cells[] = '&nbsp;';
        $container->cells[] = '-';
    }
}
 
// and more 7 if($range)

There’re also functions defined but called just once. Use of Ajax to load a page with an argument, where a function decides 3 other pages to be loaded depending on the argument value. By the way, this value comes straight from the $_GET, with zero validation or treatment. The 3 pages are on a different directory, with no index.*.

One of the Ajax used is activated by an onchange event, and updates a div with an input field, which is raw html returned by one of the 3 files.

Mothership cat is not amused

There was also this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function _get_account($id)
{
    $sql = "SELECT * FROM table WHERE id = $id";
    $res = mysql_query($sql);
    if ($id == '0') {
        return 'not available';
    }
    /* loop through $res. I don't know why, since the id column is a primary key, and return the result as an array*/
}
 
while ($x < $interval + 1) {
    // Inside the same loop above, after the many if($range)s
    $account = new ourOrmMapper($id);
    $container->cells[] = $account->name;
    $account_details = _get_account($id);
    $container->cells[] = $account_details['amount'];
}

And when I got home, my Windows XP blue-screened before the user login. I can’t reinstall the OS because my HD is SATA, and I don’t have a floppy disk.

I am fucking mad.

Post a Comment

Your email is never shared.