Montag, 4. März 2013

How not to code (Magento raeg #1/10.000)

A little poem from the original Magento codebase:
    public function getProduct($productId, $store, $identifierType = null) {
        $loadByIdOnFalse = false;
        if ($identifierType == null) {
            if (is_string($productId) && !preg_match("/^[+-]?[1-9][0-9]*$|^0$/", $productId)) {
                $identifierType = 'sku';
                $loadByIdOnFalse = true;
            } else {
                $identifierType = 'id';
            }
        }
 ... 

Okay. Once and for all: If you have to have parameters go through a regex to find out what type they are, you're definitely doing something wrong. Even with PHP, this is a smell. Not even a code smell. It's the smell of a public toilet that hasn't been cleaned in like 50 years or so. It's code puke.

1 Kommentar: