PHP code example of kkevindev / assert-return-value
1. Go to this page and download the library: Download kkevindev/assert-return-value library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kkevindev / assert-return-value example snippets
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;
}
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),
);
}
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,
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.