Mapping a product its corresponding image file I'm writing this method that elaborates an image name..

I think my logic is not being the best one here but I'm not very savvy in programming yet.

Right now it looks like this:

if($this-&gt;isCustom($product)){
            $image_path = PRODUCT_IMAGE_PATH . $this-&gt;order['order_number'] . $index . '.jpg';
            $index++;
        }
        else{
            $image_path = PRODUCT_IMAGE_PATH . $product['sku'] . '.jpg';
        }

        if($this-&gt;checkRemoteImage($image_path)){
            return $image_path;
        }

        else{
            if (!$this-&gt;isCustom($product)){
                $this-&gt;notifyOnNonCustoms($image_path);
            }
            return "No Image";
        }


I believe something like this would be better:

if ($this-&gt;isCustom($product)){
            $image_path = PRODUCT_IMAGE_PATH . $this-&gt;order['order_number'] . $index . '.jpg';
            $index++;

            if (!$this-&gt;checkRemoteImage($image_path)){
                return "No Image";
            }
            return $image_path;
        }

        else{
            $image_path = PRODUCT_IMAGE_PATH . $product['sku'] . '.jpg';

            if (!$this-&gt;checkRemoteImage($image_path)){
                $this-&gt;notifyOnNonCustoms($image_path);
                return "No Image";
            }
            return $image_path;
        }
    }


The flow is meant to be like this:

If the product is custom, the image path should be the path + order number + ascending numbers ( using outer index here )

If not, it should be the image path + the product's sku

There should be a check if the image does exist in the server. If it doesn't it should return "No Image" and if it's not custom, call the method notifyOnNonCustoms I'm not sure on the best way to structure this.
I am going to shorten up some of your code a little bit,


if ($this-&gt;isCustom($product)){
            $image_path = PRODUCT_IMAGE_PATH . $this-&gt;order['order_number'] . $index . '.jpg';
            $index++;

            if (!$this-&gt;checkRemoteImage($image_path)){
                return "No Image";
            }
            return $image_path;
        }

        else{
            $image_path = PRODUCT_IMAGE_PATH . $product['sku'] . '.jpg';

            if (!$this-&gt;checkRemoteImage($image_path)){
                $this-&gt;notifyOnNonCustoms($image_path);
                return "No Image";
            }
            return $image_path;
        }
    }



you should allow your image path variable to live a little longer and use it to return once.  

this is kind of what I was thinking

if ($this-&gt;isCustom($product)){
    $image_path = PRODUCT_IMAGE_PATH . $this-&gt;order['order_number'] . $index . '.jpg';
    $index++;

    $image_path = $this-&gt;checkRemoteImage($image_path) ? "No Image" : $image_path;
}
else{
    $image_path = PRODUCT_IMAGE_PATH . $product['sku'] . '.jpg';

    if (!$this-&gt;checkRemoteImage($image_path)){
        $this-&gt;notifyOnNonCustoms($image_path);
        $image_path = "No Image";
    }
}   
return $image_path;


a little less indentation inside the if statement block.  I couldn't do much with the else statement block.



Your first set of code is nice in that it creates the path and checks it, but it evaluates 

$this-&gt;isCustom($product)


twice in some circumstances, and you don't want that because it adds more operations to your algorithm.

Your second set of code is much more precise, it still only creates the $image_path once, but does it differently depending on the value of the truthy statement.  also you have different operations that need to be done for custom and not custom if the image path doesn't exist. 

Your second block of code is better than the first.