sublime-php-getters-setters icon indicating copy to clipboard operation
sublime-php-getters-setters copied to clipboard

if-test functionality in user templates for using filter_var in setters

Open imhoffd opened this issue 11 years ago • 0 comments

For myself, I like to slap in this filter attempt in my setters:

    /**
     * @param integer $number
     *
     * @return self
     */
    public function setNumber($number)
    {
        if (false === $number = filter_var($number, FILTER_VALIDATE_INT)) {
            throw new \InvalidArgumentException(sprintf('Could not validate number as an integer: %s', $number));
        }

        $this->number = $number;

        return $this;
    }

But as you can see, depending on the variable type, I'd have to change some things (like variables of type string don't need this filter_var but instead I would always cast to string when setting, variables of type boolean would use FILTER_VALIDATE_BOOLEAN and then would need to return null if there was an error instead of false, etc.) and a simple variable replace does not work for my templates.

Can you incorporate a template engine or something so we can have full power over our templates?

imhoffd avatar Feb 12 '14 17:02 imhoffd