Doctor Who
Doctor Who

Reputation: 97

Is there a design by contract framework for php?

Is there a framework or library for php that will help me implement design by contract in my applications?

In the best case it would use javadoc like annotations in the comments.

Upvotes: 5

Views: 1465

Answers (3)

lisachenko
lisachenko

Reputation: 6092

New DbC framework for PHP based on Aspect-Oriented Programming: https://github.com/lisachenko/php-deal

/**
 * Simple trade account contract
 */
interface AccountContract
{
    /**
     * Deposits fixed amount of money to the account
     *
     * @param float $amount
     *
     * @Contract\Verify("$amount>0 && is_numeric($amount)")
     * @Contract\Ensure("$this->balance == $__old->balance+$amount")
     */
    public function deposit($amount);

    /**
     * Returns current balance
     *
     * @Contract\Ensure("$__result == $this->balance")
     *
     * @return float
     */
    public function getBalance();
}

Upvotes: 1

user9903
user9903

Reputation:

I've started work on a design-by-contract project PHP-Contracts

There are a few blog posts about the subject as well:

Upvotes: 4

roirodriguez
roirodriguez

Reputation: 1740

Would it be something like http://code.google.com/p/addendum/?

Upvotes: 0

Related Questions