View on GitHub

RefactoringPHP

A PHP version of the refactors from Refactoring: Improving the Design of Existing Code (Second Edition) by Martin Fowler

Introduce Assertion (302)

Old Code

<?php
if ( $this->discountRate ) {
    $base = $base - ($this->discountRate * $base);
}

New Code

<?php
assert($this->discountRate > 0);
if ( $this->discountRate ) {
    $base = $base - ($this->discountRate * $base);
}