public static function padNumber(int $val, int $len, bool $trim = false)
    {
        $result = sprintf("%0${len}d", $val);
        if (strlen($result) > $len) {
            if ($trim) {
                return substr($result, - $len);
            } else {
                throw new \LengthException('Value overflows maximum length');
            }
        }
        return $result;
    }
public static function padNumber(int $val, int $len, bool $trim = false)
    {
        $result = sprintf("%0${len}d", $val);
        if (strlen($result) > $len) {
            if ($trim) {
                return substr($result, - $len);
            } else {
                throw new \LengthException('Value overflows maximum length');
            }
        }
        return $result;
    }
public static function padNumber ( int $ val , int $ len , bool $ trim = false ) { $ result = sprintf ( "%0${len}d" , $ val ) ; if ( strlen ( $ result ) > $ len ) { if ( $ trim ) { return substr ( $ result , - $ len ) ; } else { throw new \ LengthException ( 'Value overflows maximum length' ) ; } } return $ result ; }
Adds leading zeroes to a value

@param string  $val  Value to be formatted
@param integer $len  Maximum digits length allowed
@param boolean $trim If left digits should be trimmed (disables throw)

@return string

@throws \LengthException If $val overflows
Adds leading zeroes to a value