定制 vancodx/php-data-assertion 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vancodx/php-data-assertion

最新稳定版本:1.0.2

Composer 安装命令:

composer require --dev vancodx/php-data-assertion

包简介

VanCodX PHP Data Assertion

README 文档

README

This library contains a set of static methods for assertion the type of variables and arguments of functions and methods. The main goal is to improve the quality of data validation and static analysis. Each assertion method has "@phpstan-assert" tag in its DocBlock comment to narrow the type of "value" argument.

This library also includes my PHP Data Validation library.

Installation

Install this package with the following command:

composer require vancodx/php-data-assertion

Usage

Example of assertion the type of a function argument:

<?php declare(strict_types=1);

use VanCodX\Data\Assertion\Assertion as A;

/**
 * @param list<int> $ids
 * @return void
 */
function printIds(array $ids): void
{
    A::argIsListLenOfIntId($ids);
    \PHPStan\dumpType($ids); // Reports: Dumped type: non-empty-list<int<1, max>>
    echo 'IDs: ', implode(', ', $ids), "\n";
}

Example of assertion the type of a variable:

<?php declare(strict_types=1);

use VanCodX\Data\Assertion\Assertion as A;

/**
 * @return void
 */
function printUsername(): void
{
    $username = getenv('USER');
    A::valIsStrLen($username);
    \PHPStan\dumpType($username); // Reports: Dumped type: non-empty-string
    echo 'Username: ', $username, "\n";
}

Running tests

Use the following command for running the tests inside a Docker container:

docker compose up --build tests

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固