kkevindev/assert-return-value

This package is abandoned and no longer maintained. The author suggests using the webmozarts/assert package instead.

A library that uses webmozarts/assert to assert and return the asserted value.

Maintainers

Package info

github.com/kkevindev/assert-return-value

pkg:composer/kkevindev/assert-return-value

Statistics

Installs: 1 197

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.11.0.1 2026-01-04 00:30 UTC

This package is auto-updated.

Last update: 2026-01-04 00:32:35 UTC


README

Important

webmozarts/assert version 2.0 now finally supports return values! Use that package (again) instead. It should be a drop-in replacement (just update imports).








Assert Return Value (ARV)

Quality Assurance

This library uses webmozart/assert to assert values with the added benefit of returning the value.

Installation

Use Composer to install the package:

composer require kkevindev/assert-return-value

Versioning

This libary follows the versioning of webmozart/assert with the addition of a patch version used for patching this library on the same webmozart/assert version.

webmozart/assert kkevindev/assert-return-value Notes
1.11.0 1.11.0.0 Add support for webmozart/assert:1.11.0
1.11.0 1.11.0.1 Fixed a bug in this package. Still only supports webmozart/assert:1.11.0
1.11.0 1.11.0.2 Fixed a bug in this package. Still only supports webmozart/assert:1.11.0
1.11.1 1.11.1.0 Add support for webmozart/assert:1.11.1
1.12.0 1.12.0.0 Add support for webmozart/assert:1.12.0
1.12.0 1.12.0.1 Fixed a bug in this package. Still only supports webmozart/assert:1.12.0

Usage

Given the follwing code:

class User {
    public function __construct(
        public string $name,
        public string $email,
        public string $role,
    ) {
    }
}

class UserDto {
    public ?string $name = null;
    public ?string $email = null;
    public ?string $role = null;
}

This library allows you to write code like this:

use Webmozart\Assert\Assert as WebmozartAssert;
use Kkevindev\AssertReturnValue\Assert;

public function create(UserDto $userDto): User
{
    return new User(
       name: Assert::stringNotEmpty($userDto->name),
       email: Assert::stringNotEmpty($userDto->email),
       role: Assert::stringNotEmpty($userDto->role),
    );
}

Instead of:

use Webmozart\Assert\Assert as WebmozartAssert;
use Kkevindev\AssertReturnValue\Assert;

public function create(UserDto $userDto): User
{
    $name = $userDto->name;
    WebmozartAssert::stringNotEmpty($name);
    
    $email = $userDto->email;
    WebmozartAssert::stringNotEmpty($email);
    
    $role = $userDto->role;
    WebmozartAssert::stringNotEmpty($role);
    
    return new User(
        name: $name,
        email: $email,
        role: $role,
    );
}