├── LICENSE ├── README.md ├── composer.json └── src ├── Assert.php ├── Assertion.php ├── Assertor.php ├── Chain ├── AssociativeFullChain.php ├── AssociativeSimpleChain.php ├── FullChain.php ├── RegularFullChain.php ├── RegularSimpleChain.php └── SimpleChain.php ├── Creator.php ├── Creator ├── CompositeCreator.php ├── KeyCreator.php ├── NotCreator.php ├── NullOrCreator.php ├── PrefixedCreator.php ├── PropertyCreator.php └── StandardCreator.php ├── Exception ├── CannotCreateAssertionException.php └── Exception.php ├── Mixin ├── Chain │ ├── AllMixin.php │ ├── KeyMixin.php │ ├── LengthMixin.php │ ├── MaxMixin.php │ ├── MinMixin.php │ ├── Mixin.php │ ├── NullOrMixin.php │ └── PropertyMixin.php └── Static │ ├── AllMixin.php │ ├── KeyMixin.php │ ├── LengthMixin.php │ ├── MaxMixin.php │ ├── MinMixin.php │ ├── Mixin.php │ ├── NullOrMixin.php │ └── PropertyMixin.php └── Rule ├── All.php ├── Envelope.php ├── Length.php ├── Max.php ├── Min.php └── Rule.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Henrique Moody 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Respect\Assertion 2 | 3 | [![Build Status](https://img.shields.io/github/actions/workflow/status/Respect/Assertion/continuous-integration.yml?branch=master&style=flat-square)](https://github.com/Respect/Assertion/actions/workflows/continuous-integration.yml) 4 | [![Code Coverage](https://img.shields.io/codecov/c/github/Respect/Assertion?style=flat-square)](https://codecov.io/gh/Respect/Assertion) 5 | [![Latest Stable Version](https://img.shields.io/packagist/v/respect/assertion.svg?style=flat-square)](https://packagist.org/packages/respect/assertion) 6 | [![Total Downloads](https://img.shields.io/packagist/dt/respect/assertion.svg?style=flat-square)](https://packagist.org/packages/respect/assertion) 7 | [![License](https://img.shields.io/packagist/l/respect/assertion.svg?style=flat-square)](https://packagist.org/packages/respect/assertion) 8 | 9 | The power of [Validation][] into an assertion library. 10 | 11 | * More than 1.5k assertions 12 | * Support for custom messages 13 | * Support for custom exceptions 14 | 15 | For a complete list of assertions, check all the [mixin interfaces][], and read 16 | [Validation][] to understand how each rule/assertion works. 17 | 18 | ## Installation 19 | 20 | This package is available on [Packagist][], and you can install it using 21 | [Composer][]. 22 | 23 | ```shell 24 | composer require respect/assertion 25 | ``` 26 | 27 | Works on PHP 8.1 or above. 28 | 29 | ## Another assertion library 30 | 31 | There are PHP assertion libraries that a lot of people in the PHP the community 32 | use: 33 | 34 | - [beberlei/assert][] 35 | - [webmozart/assert][] 36 | 37 | They are both straightforward to use and have a lot of assertions, so there 38 | would be no reason to create yet another one. On the other hand, they have fewer 39 | assertions than [Validation][] does. 40 | 41 | The main idea of [Validation][] is to make it easy to create chain of 42 | validations, but when it can get verbose when you want to make a simple 43 | assertion. 44 | 45 | This library offers a more straightforward assertion API for [Validation][], 46 | which means that you can use all [Validation][]'s rules plus your own rules. 47 | 48 | ## Usage 49 | 50 | The examples in the document will assume that this library is available in the 51 | autoload and that the class `Respect\Assertion\Assert` is imported. 52 | 53 | The `Assert` class can use any rule from [Validation][] with the input as its 54 | first argument: 55 | 56 | ```php 57 | // will throw an exception => 1 must be equals 5 58 | Assert::equals(1, 5); 59 | 60 | // will throw an exception => "string" must be of type integer 61 | Assert::intType('string'); 62 | 63 | // will not throw an exception 64 | Assert::odd(5); 65 | ``` 66 | 67 | By default, it throws exceptions that are instances of [ValidationException][], 68 | which means you can catch [InvalidArgumentException][] (or [LogicException][]). 69 | 70 | ### Custom messages 71 | 72 | The exceptions that `Assert` throws are the same that [Validation][] throws. 73 | That allows you to customize the error messages using templates: 74 | 75 | ```php 76 | // will throw an exception => I was expecting 5, but you gave be 1 77 | Assert::equals(1, 5, 'I was expecting {{compareTo}}, but you gave be {{input}}'); 78 | ``` 79 | 80 | ### Custom exceptions 81 | 82 | Instead of throwing [Validation][] exceptions, you can use your exceptions: 83 | 84 | ```php 85 | // will throw the defined DomainException 86 | Assert::between(42, 1, 10, new DomainException('Something is not right')); 87 | ``` 88 | 89 | That can be very useful if you want to throw specific exceptions for your 90 | application. That was a great idea from [Malukenho][]! 91 | 92 | ### Chained assertions (`that()`) 93 | 94 | You can chain assertions using `Assert::that($input)`, which allows you to 95 | perform multiple assertions to the same input with less duplication. 96 | 97 | ```php 98 | // will throw an exception => I expected a positive number 99 | Assert::that(-1) 100 | ->intVal('The number {{input}} must be an integer') 101 | ->positive('The number must be positive') 102 | ->lessThan(4); 103 | ``` 104 | 105 | In the example above, as soon as any assertion fails, it will throw an 106 | exception. If you wish to chain validations and only check them all 107 | simultaneously, we suggest you use the API from [Validation][]. 108 | 109 | You can also customize a message or exception for the whole chain. 110 | 111 | ```php 112 | // will throw an exception => The number must be valid 113 | Assert::that(0, new DomainException('The number must be valid')) 114 | ->positive() 115 | ->greaterThan(5); 116 | 117 | // will throw an exception => But it is not greater than 5, though 118 | Assert::that(3, 'The number must be valid') 119 | ->positive() 120 | ->greaterThan(5, 'But it is not greater than 5, though'); 121 | ``` 122 | 123 | Note that the customization on a specific assertion will overwrite the 124 | customization on the whole chain. 125 | 126 | You can also apply the effect of the prefixes listed below to the whole chain. 127 | 128 | ```php 129 | // will throw an exception => 3 (the length of the input) must equal 4 130 | Assert::that(['names' => ['Respect', 'Assertion'], 'options' => [1, 2, 3]]) 131 | ->all()->arrayType() 132 | ->key('names')->allStringType() 133 | ->key('options')->lengthEquals(4); 134 | ``` 135 | 136 | There are also some special methods that allow you to create a chain of 137 | assertions. 138 | 139 | * `thatAll()`: assert all elements in the input with the subsequent assertions. 140 | * `thatNot()`: assert the input inverting the subsequent assertions. 141 | * `thatNullOr()`: assert the input if it is not `null` with the subsequent assertions. 142 | * `thatKey()`: assert a key from the input with the subsequent assertions. 143 | * `thatProperty()`: assert a property from the input with the subsequent assertions. 144 | 145 | ## Prefixes 146 | 147 | With Assertion, you can use any [Validation][] rule, but it also allows 148 | you to use them with prefixes that simplify some operations. 149 | 150 | ### `all*()`: asserting all elements in an input 151 | 152 | Assertions can be executed with the `all` prefix which will assert all elements 153 | in the input with the prefixed assertion: 154 | 155 | ```php 156 | // will throw an exception => "3" (like all items of the input) must be of type integer 157 | Assert::allIntType([1, 2, '3']); 158 | ``` 159 | 160 | In some cases, you might want to perform multiple assertions to all elements. You 161 | can use `thatAll()` chain of assertions that will assert all elements in the input 162 | with the subsequent assertions: 163 | 164 | ```php 165 | // will throw an exception => 3 (like all items of the input) must be between 1 and 2 166 | Assert::thatAll([1, 2, 2, 1, 3]) 167 | ->intVal() 168 | ->between(1, 2); 169 | ``` 170 | 171 | If you want to perform multiple assertions to all elements, but you also want to 172 | perform other assertions to the input, you can `that()->all()`: 173 | 174 | ```php 175 | // will throw an exception => 5 (the length of the input) must be less than 4 176 | Assert::that([1, 2, 2, 1, 3]) 177 | ->arrayType() 178 | ->notEmpty() 179 | ->lengthGreaterThan(3) 180 | ->all()->intVal()->between(1, 2); 181 | ``` 182 | 183 | ### `nullOr*()`: asserting the value of an input or null 184 | 185 | Assertions can be executed with the `nullOr` prefix which will assert only if 186 | the value of the input it not null. 187 | 188 | ```php 189 | // will throw an exception => 42 must be negative 190 | Assert::nullOrNegative(42); 191 | 192 | // will not throw an exception 193 | Assert::nullOrNegative(null); 194 | 195 | // will throw an exception => 5 must be between 1 and 4 196 | Assert::nullOrBetween(5, 1, 4); 197 | 198 | // will not throw an exception 199 | Assert::nullOrBetween(null, 1, 4); 200 | ``` 201 | 202 | In some cases, you might want to perform multiple assertions to a value in case 203 | it is not null. In this case, you can use `thatNullOr()`: 204 | 205 | ```php 206 | // will throw an exception => 6 must be a valid prime number 207 | Assert::thatNullOr(6) 208 | ->positive() 209 | ->between(1, 10) 210 | ->primeNumber(); 211 | 212 | // will not throw an exception 213 | Assert::thatNullOr(null) 214 | ->positive() 215 | ->between(1, 10) 216 | ->primeNumber(); 217 | ``` 218 | 219 | For convenience, you might also use the `that()->nullOr()`: 220 | 221 | ```php 222 | Assert::that(6) 223 | ->nullOr()->positive()->between(1, 10)->primeNumber(); 224 | ``` 225 | 226 | ### `not*()`: inverting assertions 227 | 228 | You can execute assertions with the `not` prefix, which will assert the opposite 229 | of the prefixed assertion: 230 | 231 | ```php 232 | // will throw an exception => 2 must not be an even number 233 | Assert::notEven(2); 234 | 235 | // will throw an exception => 3 must not be in `{ 1, 2, 3, 4 }` 236 | Assert::notIn(3, [1, 2, 3, 4]); 237 | ``` 238 | 239 | If you need to invert more than a few rules, it might be easier to use `thatNot()` 240 | and `that()->not()`: 241 | 242 | ```php 243 | // will throw an exception => "1" must not be positive 244 | Assert::thatNot('1') 245 | ->intType() 246 | ->positive() 247 | ->between(1, 3); 248 | 249 | 250 | // will throw an exception => "1" must not be positive 251 | Assert::that('1') 252 | ->not()->intType()->positive()->between(1, 3); 253 | ``` 254 | 255 | ### `key*()`: asserting a key in an array 256 | 257 | You can use `keyPresent` to check whether a key is present in an array. 258 | 259 | ```php 260 | // will throw an exception => bar must be present 261 | Assert::keyPresent(['foo' => true], 'bar'); 262 | ``` 263 | 264 | You can use `keyNotPresent` to check whether a key is present in an array. 265 | 266 | ```php 267 | // will throw an exception => bar must not be present 268 | Assert::keyNotPresent(['bar' => 2], 'bar'); 269 | ``` 270 | 271 | Also, with the `key` prefix it will assert the value of the array that contains 272 | the specified key. 273 | 274 | ```php 275 | // will throw an exception => foo must equal 3 276 | Assert::keyEquals(['foo' => 2], 'foo', 3); 277 | 278 | // will throw an exception => bar must be negative 279 | Assert::keyNegative(['bar' => 2], 'bar'); 280 | 281 | // will throw an exception => bar must not be of type integer 282 | Assert::keyNotIntType(['bar' => 2], 'bar'); 283 | 284 | // will throw an exception => baz must be present 285 | Assert::keyNegative(['foo' => 2], 'baz'); 286 | 287 | // will throw an exception => foo must exist 288 | Assert::keyExists(['foo' => '/path/to/file.txt'], 'foo'); 289 | ``` 290 | 291 | Not that `keyExists` assertion, will assert whether the value of key `foo` exists 292 | in the Filesystem. 293 | 294 | If you want to perform multiple assertions to the key of an input, you can use 295 | `thatKey()`: 296 | 297 | ```php 298 | // will throw an exception => 9 (the length of the input) must be less than 4 299 | Assert::thatKey(['foo' => 'my-string'], 'foo') 300 | ->stringType() 301 | ->startsWith('my-') 302 | ->lengthLessThan(4); 303 | ``` 304 | 305 | If you want to perform multiple key assertions to the same input, you can use 306 | `that()->key()`: 307 | 308 | ```php 309 | // will throw an exception => bar must be less than 40 310 | Assert::that(['foo' => 'my-string', 'bar' => 42]) 311 | ->arrayType() 312 | ->key('foo')->stringType()->startsWith('my-') 313 | ->key('bar')->intType()->positive()->lessThan(40); 314 | ``` 315 | 316 | ### `property*()`: asserting a property in an object 317 | 318 | We'll use the object below as input in the examples that follow. 319 | 320 | ```php 321 | $input = new stdClass(); 322 | $input->foo = 1; 323 | ``` 324 | 325 | You can use `propertyPresent` to check whether a property is present in an object. 326 | 327 | ```php 328 | // will throw an exception => Attribute bar must be present 329 | Assert::propertyPresent($input, 'bar'); 330 | ``` 331 | 332 | You can use `propertyNotPresent` to check whether a property is *not* present in 333 | an object. 334 | 335 | ```php 336 | // will throw an exception => Attribute foo must not be present 337 | Assert::propertyNotPresent($input, 'foo'); 338 | ``` 339 | 340 | With the `property` prefix, you can make assertions with the value of a specific 341 | object's property. 342 | 343 | ```php 344 | // will throw an exception => foo must equal 3 345 | Assert::propertyEquals($input, 'foo', 3); 346 | 347 | // will throw an exception => foo must be negative 348 | Assert::propertyNegative($input, 'foo'); 349 | 350 | // will throw an exception => foo must not be of type integer 351 | Assert::propertyNotIntType($input, 'foo'); 352 | 353 | // will throw an exception => Attribute baz must be present 354 | Assert::propertyNegative($input, 'baz'); 355 | 356 | // will throw an exception => foo must exists 357 | Assert::propertyExists($input, 'foo'); 358 | ``` 359 | 360 | Note that the `propertyExists` assertion will assert whether the value of 361 | property `foo` exists in the FileSystem. 362 | 363 | If you want to perform multiple assertions to a property of an object, you can 364 | use `thatProperty()`: 365 | 366 | ```php 367 | // will throw an exception => foo must be greater than 5 368 | Assert::thatProperty($input, 'foo') 369 | ->intType() 370 | ->positive() 371 | ->greaterThan(5); 372 | ``` 373 | 374 | If you want to perform multiple key assertions to the same input, you can use 375 | `that()->property()`: 376 | 377 | ```php 378 | // will throw an exception => foo must be greater than 5 379 | Assert::that($input) 380 | ->instance(stdClass::class) 381 | ->property('foo')->intType()->positive()->greaterThan(5); 382 | ``` 383 | 384 | ### `length*()`: asserting the length of an input 385 | 386 | Assertions can be executed with the `length` prefix which will assert the length 387 | of the input with the prefixed assertion: 388 | 389 | ```php 390 | // will throw an exception => 6 (the length of the input) must be between 10 and 15 391 | Assert::lengthBetween('string', 10, 15); 392 | ``` 393 | 394 | The `length` prefix can also be used with arrays and instances of [Countable][]: 395 | 396 | ```php 397 | // will throw an exception => 4 (the length of the input) must be an odd number 398 | Assert::lengthOdd([1, 2, 3, 4]); 399 | 400 | // will throw an exception => 3 (the length of the input) must be an even number 401 | Assert::lengthEven(new ArrayObject([1, 2, 3])); 402 | ``` 403 | 404 | This library also allows you to use the `not` prefix after the `length` prefix: 405 | 406 | ```php 407 | // will throw an exception => 2 (the length of the input) must not be multiple of 2 408 | Assert::lengthNotMultiple([1, 2], 2); 409 | ``` 410 | 411 | ### `max*()`: asserting the maximum of an input 412 | 413 | Assertions can be executed with the `max` prefix which will assert the maximum 414 | value of the input with the prefixed assertion: 415 | 416 | ```php 417 | // will throw an exception => 3 (the maximum of the input) must be between 5 and 10 418 | Assert::maxBetween([1, 2, 3], 5, 10); 419 | ``` 420 | 421 | The `max` prefix can be used with any [iterable][] value: 422 | 423 | ```php 424 | // will throw an exception => 3 (the maximum of the input) must be an even number 425 | Assert::maxEven([1, 2, 3]); 426 | 427 | // will throw an exception => 60 (the maximum of the input) must be a valid perfect square 428 | Assert::maxPerfectSquare(new ArrayObject([45, 60, 20])); 429 | ``` 430 | 431 | This library also allows you to use the `not` prefix after the `max` prefix: 432 | 433 | ```php 434 | // will throw an exception => 23 (the maximum of the input) must not be positive 435 | Assert::maxNotPositive([23, 7, 20]); 436 | ``` 437 | 438 | ### `min*()`: asserting the minimum of an input 439 | 440 | Assertions can be executed with the `min` prefix which will assert the minimum 441 | value of the input with the prefixed assertion: 442 | 443 | ```php 444 | // will throw an exception => 1 (the minimum of the input) must be between 5 and 10 445 | Assert::minBetween([1, 2, 3], 5, 10); 446 | ``` 447 | 448 | The `min` prefix can be used with any [iterable][] value: 449 | 450 | ```php 451 | // will throw an exception => 1 (the minimum of the input) must be an even number 452 | Assert::minEven([1, 2, 3]); 453 | 454 | // will throw an exception => 20 (the minimum of the input) must be a valid perfect square 455 | Assert::minPerfectSquare(new ArrayObject([45, 60, 20])); 456 | ``` 457 | 458 | This library also allows you to use the `not` prefix after the `min` prefix: 459 | 460 | ```php 461 | // will throw an exception => 7 (the minimum of the input) must not be positive 462 | Assert::minNotPositive([23, 7, 20]); 463 | ``` 464 | 465 | [beberlei/assert]: https://github.com/beberlei/assert 466 | [Composer]: http://getcomposer.org 467 | [Countable]: http://php.net/countable 468 | [InvalidArgumentException]: https://www.php.net/InvalidArgumentException 469 | [iterable]: http://php.net/types.iterable 470 | [LogicException]: https://www.php.net/LogicException 471 | [Malukenho]: https://github.com/malukenho 472 | [mixin interfaces]: src/Mixin/Static 473 | [Packagist]: http://packagist.org/packages/respect/assertion 474 | [Validation]: https://github.com/Respect/Validation 475 | [ValidationException]: https://github.com/Respect/Validation/blob/master/library/Exceptions/ValidationException.php 476 | [webmozart/assert]: https://github.com/webmozart/assert 477 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "respect/assertion", 3 | "description": "The power of Respect\\Validation into an assertion library", 4 | "keywords": ["respect", "assertion", "assert"], 5 | "type": "library", 6 | "license": "MIT", 7 | "autoload": { 8 | "psr-4": { 9 | "Respect\\Assertion\\": "src/" 10 | } 11 | }, 12 | "autoload-dev": { 13 | "psr-4": { 14 | "Respect\\Test\\Integration\\Assertion\\": "tests/integration", 15 | "Respect\\Test\\Unit\\Assertion\\": "tests/unit" 16 | }, 17 | "files": [ 18 | "tests/documentation/lib/helpers.php" 19 | ] 20 | }, 21 | "require": { 22 | "php": "^8.1", 23 | "respect/stringifier": "^0.2.0", 24 | "respect/validation": "^2.2.4", 25 | "symfony/polyfill-mbstring": "^v1.27.0" 26 | }, 27 | "require-dev": { 28 | "malukenho/docheader": "^0.1.8", 29 | "phpstan/phpstan": "^1.10.7", 30 | "phpstan/phpstan-deprecation-rules": "^1.1.3", 31 | "phpstan/phpstan-phpunit": "^1.3.10", 32 | "phpunit/phpunit": "^10.0.17", 33 | "respect/coding-standard": "^4.0.0", 34 | "squizlabs/php_codesniffer": "^3.7.2" 35 | }, 36 | "suggest": { 37 | "ext-mbstring": "Multibyte String Functions" 38 | }, 39 | "authors": [ 40 | { 41 | "name": "Henrique Moody", 42 | "email": "henriquemoody@gmail.com" 43 | } 44 | ], 45 | "config": { 46 | "sort-packages": true, 47 | "allow-plugins": { 48 | "dealerdirect/phpcodesniffer-composer-installer": true 49 | } 50 | }, 51 | "scripts": { 52 | "docheader": "vendor/bin/docheader check src/ tests/", 53 | "phpcs": "vendor/bin/phpcs", 54 | "phpstan": "vendor/bin/phpstan analyze", 55 | "phpunit": "vendor/bin/phpunit", 56 | "phpunit-integration": "vendor/bin/phpunit --testsuite=integration", 57 | "phpunit-unit": "vendor/bin/phpunit --testsuite=unit", 58 | "qa": [ 59 | "@docheader", 60 | "@phpcs", 61 | "@phpstan", 62 | "@phpunit" 63 | ] 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Assert.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion; 15 | 16 | use Exception; 17 | use Respect\Assertion\Chain\AssociativeSimpleChain; 18 | use Respect\Assertion\Chain\RegularFullChain; 19 | use Respect\Assertion\Chain\RegularSimpleChain; 20 | use Respect\Assertion\Creator\CompositeCreator; 21 | use Respect\Assertion\Exception\CannotCreateAssertionException; 22 | use Respect\Assertion\Mixin\Static\Mixin; 23 | use Throwable; 24 | 25 | use function array_shift; 26 | 27 | /** 28 | * @mixin Mixin 29 | */ 30 | final class Assert 31 | { 32 | private static ?Creator $creator = null; 33 | 34 | public static function that(mixed $input, null|string|Throwable $description = null): RegularFullChain 35 | { 36 | return new RegularFullChain(self::getCreator(), $input, $description, ''); 37 | } 38 | 39 | public static function thatAll(mixed $input, null|string|Throwable $description = null): RegularSimpleChain 40 | { 41 | return new RegularSimpleChain(self::getCreator(), $input, $description, 'all'); 42 | } 43 | 44 | public static function thatNot(mixed $input, null|string|Throwable $description = null): RegularSimpleChain 45 | { 46 | return new RegularSimpleChain(self::getCreator(), $input, $description, 'not'); 47 | } 48 | 49 | public static function thatNullOr(mixed $input, null|string|Throwable $description = null): RegularSimpleChain 50 | { 51 | return new RegularSimpleChain(self::getCreator(), $input, $description, 'nullOr'); 52 | } 53 | 54 | public static function thatKey( 55 | mixed $input, 56 | int|string $key, 57 | null|string|Throwable $description = null 58 | ): AssociativeSimpleChain { 59 | return new AssociativeSimpleChain(self::getCreator(), $key, $input, $description, 'key'); 60 | } 61 | 62 | public static function thatProperty( 63 | mixed $input, 64 | string $property, 65 | null|string|Throwable $description = null 66 | ): AssociativeSimpleChain { 67 | return new AssociativeSimpleChain(self::getCreator(), $property, $input, $description, 'property'); 68 | } 69 | 70 | private static function getCreator(): Creator 71 | { 72 | if (!self::$creator instanceof Creator) { 73 | self::$creator = CompositeCreator::createDefault(); 74 | } 75 | 76 | return self::$creator; 77 | } 78 | 79 | /** 80 | * @param mixed[] $parameters 81 | * 82 | * @throws CannotCreateAssertionException 83 | * @throws Exception 84 | */ 85 | public static function __callStatic(string $name, array $parameters): void 86 | { 87 | $input = array_shift($parameters); 88 | 89 | $assertion = self::getCreator()->create($name, $parameters); 90 | $assertion->assert($input); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Assertion.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion; 15 | 16 | use Respect\Validation\Exceptions\ValidationException; 17 | use Respect\Validation\Validatable; 18 | use Throwable; 19 | 20 | use function is_string; 21 | 22 | final class Assertion 23 | { 24 | public function __construct( 25 | private readonly Validatable $rule, 26 | private readonly null|string|Throwable $description = null 27 | ) { 28 | } 29 | 30 | public function getRule(): Validatable 31 | { 32 | return $this->rule; 33 | } 34 | 35 | public function getDescription(): null|string|Throwable 36 | { 37 | return $this->description; 38 | } 39 | 40 | public function assert(mixed $input): void 41 | { 42 | try { 43 | $this->rule->check($input); 44 | } catch (ValidationException $exception) { 45 | if ($this->description instanceof Throwable) { 46 | throw $this->description; 47 | } 48 | 49 | if (is_string($this->description)) { 50 | $exception->updateTemplate($this->description); 51 | } 52 | 53 | throw $exception; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Assertor.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion; 15 | 16 | use Exception; 17 | 18 | interface Assertor 19 | { 20 | /** 21 | * @throws Exception 22 | */ 23 | public function execute(Assertion $assertion, mixed $input): void; 24 | } 25 | -------------------------------------------------------------------------------- /src/Chain/AssociativeFullChain.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Chain; 15 | 16 | use Respect\Assertion\Creator; 17 | use Respect\Assertion\Mixin\Chain\Mixin; 18 | use Throwable; 19 | 20 | /** 21 | * @mixin Mixin 22 | */ 23 | final class AssociativeFullChain extends FullChain 24 | { 25 | public function __construct( 26 | Creator $creator, 27 | int|string $reference, 28 | mixed $input, 29 | null|string|Throwable $description, 30 | string $prefix = '' 31 | ) { 32 | parent::__construct($creator, $input, $description, $prefix, $reference); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Chain/AssociativeSimpleChain.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Chain; 15 | 16 | use Respect\Assertion\Creator; 17 | use Respect\Assertion\Mixin\Chain\Mixin; 18 | use Throwable; 19 | 20 | /** 21 | * @mixin Mixin 22 | */ 23 | final class AssociativeSimpleChain extends SimpleChain 24 | { 25 | public function __construct( 26 | Creator $creator, 27 | int|string $reference, 28 | mixed $input, 29 | null|string|Throwable $description, 30 | string $prefix 31 | ) { 32 | parent::__construct($creator, $input, $description, $prefix, $reference); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Chain/FullChain.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Chain; 15 | 16 | use Throwable; 17 | 18 | abstract class FullChain extends SimpleChain 19 | { 20 | public function all(null|string|Throwable $description = null): RegularFullChain 21 | { 22 | return new RegularFullChain($this->creator, $this->input, $description, 'all'); 23 | } 24 | 25 | public function not(null|string|Throwable $description = null): RegularFullChain 26 | { 27 | return new RegularFullChain($this->creator, $this->input, $description, 'not'); 28 | } 29 | 30 | public function nullOr(null|string|Throwable $description = null): RegularFullChain 31 | { 32 | return new RegularFullChain($this->creator, $this->input, $description, 'nullOr'); 33 | } 34 | 35 | public function key(string $key, null|string|Throwable $description = null): AssociativeFullChain 36 | { 37 | return new AssociativeFullChain($this->creator, $key, $this->input, $description, 'key'); 38 | } 39 | 40 | public function property(string $key, null|string|Throwable $description = null): AssociativeFullChain 41 | { 42 | return new AssociativeFullChain($this->creator, $key, $this->input, $description, 'property'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Chain/RegularFullChain.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Chain; 15 | 16 | use Respect\Assertion\Creator; 17 | use Respect\Assertion\Mixin\Chain\Mixin; 18 | use Throwable; 19 | 20 | /** 21 | * @mixin Mixin 22 | */ 23 | final class RegularFullChain extends FullChain 24 | { 25 | public function __construct(Creator $creator, mixed $input, null|string|Throwable $description, string $prefix = '') 26 | { 27 | parent::__construct($creator, $input, $description, $prefix); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Chain/RegularSimpleChain.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Chain; 15 | 16 | use Respect\Assertion\Creator; 17 | use Respect\Assertion\Mixin\Chain\Mixin; 18 | use Throwable; 19 | 20 | /** 21 | * @mixin Mixin 22 | */ 23 | final class RegularSimpleChain extends SimpleChain 24 | { 25 | public function __construct(Creator $creator, mixed $input, null|string|Throwable $description, string $prefix) 26 | { 27 | parent::__construct($creator, $input, $description, $prefix); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Chain/SimpleChain.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Chain; 15 | 16 | use Respect\Assertion\Assertion; 17 | use Respect\Assertion\Creator; 18 | use Respect\Assertion\Mixin\Chain\Mixin; 19 | use Throwable; 20 | 21 | use function array_unshift; 22 | use function ucfirst; 23 | 24 | /** 25 | * @mixin Mixin 26 | */ 27 | abstract class SimpleChain 28 | { 29 | public function __construct( 30 | protected readonly Creator $creator, 31 | protected readonly mixed $input, 32 | private readonly null|string|Throwable $description, 33 | private readonly string $prefix = '', 34 | private readonly null|int|string $reference = null 35 | ) { 36 | } 37 | 38 | /** 39 | * @param array $parameters 40 | */ 41 | private function create(string $name, array $parameters): Assertion 42 | { 43 | if ($this->reference !== null) { 44 | array_unshift($parameters, $this->reference); 45 | } 46 | 47 | if ($this->description !== null) { 48 | $parameters[] = $this->description; 49 | } 50 | 51 | if ($this->prefix !== '') { 52 | $name = $this->prefix . ucfirst($name); 53 | } 54 | 55 | return $this->creator->create($name, $parameters); 56 | } 57 | 58 | /** 59 | * @param array $arguments 60 | */ 61 | public function __call(string $name, array $arguments): self 62 | { 63 | $assertion = $this->create($name, $arguments); 64 | $assertion->assert($this->input); 65 | 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Creator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion; 15 | 16 | use Respect\Assertion\Exception\CannotCreateAssertionException; 17 | 18 | interface Creator 19 | { 20 | /** 21 | * @param mixed[] $parameters 22 | * 23 | * @throws CannotCreateAssertionException 24 | */ 25 | public function create(string $name, array $parameters): Assertion; 26 | } 27 | -------------------------------------------------------------------------------- /src/Creator/CompositeCreator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Creator; 15 | 16 | use Respect\Assertion\Assertion; 17 | use Respect\Assertion\Creator; 18 | use Respect\Assertion\Exception\CannotCreateAssertionException; 19 | use Respect\Assertion\Rule\All; 20 | use Respect\Assertion\Rule\Length; 21 | use Respect\Assertion\Rule\Max; 22 | use Respect\Assertion\Rule\Min; 23 | 24 | final class CompositeCreator implements Creator 25 | { 26 | /** 27 | * @var Creator[] $creators 28 | */ 29 | private array $creators; 30 | 31 | public function __construct(Creator ...$creators) 32 | { 33 | $this->creators = $creators; 34 | } 35 | 36 | public static function createDefault(): self 37 | { 38 | $creator = new self(); 39 | $creator->creators = [ 40 | new PrefixedCreator('all', All::class, $creator), 41 | new PrefixedCreator('length', Length::class, $creator), 42 | new PrefixedCreator('max', Max::class, $creator), 43 | new PrefixedCreator('min', Min::class, $creator), 44 | new PropertyCreator($creator), 45 | new KeyCreator($creator), 46 | new NotCreator($creator), 47 | new NullOrCreator($creator), 48 | new StandardCreator(), 49 | ]; 50 | 51 | return $creator; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | public function create(string $name, array $parameters): Assertion 58 | { 59 | foreach ($this->creators as $creator) { 60 | try { 61 | return $creator->create($name, $parameters); 62 | } catch (CannotCreateAssertionException) { 63 | continue; 64 | } 65 | } 66 | 67 | throw CannotCreateAssertionException::fromAssertionName($name); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Creator/KeyCreator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Creator; 15 | 16 | use Respect\Assertion\Assertion; 17 | use Respect\Assertion\Creator; 18 | use Respect\Assertion\Exception\CannotCreateAssertionException; 19 | use Respect\Validation\Rules\Key; 20 | use Respect\Validation\Rules\Not; 21 | use Throwable; 22 | 23 | use function array_shift; 24 | use function is_int; 25 | use function is_null; 26 | use function is_string; 27 | use function lcfirst; 28 | use function Respect\Stringifier\stringify; 29 | use function sprintf; 30 | use function str_starts_with; 31 | use function substr; 32 | 33 | final class KeyCreator implements Creator 34 | { 35 | public function __construct( 36 | private readonly Creator $creator 37 | ) { 38 | } 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | public function create(string $name, array $parameters): Assertion 44 | { 45 | if (!str_starts_with($name, 'key')) { 46 | throw CannotCreateAssertionException::fromAssertionName($name); 47 | } 48 | 49 | $key = array_shift($parameters); 50 | if (!is_string($key) && !is_int($key)) { 51 | throw new CannotCreateAssertionException(sprintf('%s is an invalid array key', stringify($key))); 52 | } 53 | 54 | if ($name === 'keyPresent') { 55 | return new Assertion(new Key($key), $this->getDescription($name, $parameters)); 56 | } 57 | 58 | if ($name === 'keyNotPresent') { 59 | return new Assertion(new Not(new Key($key)), $this->getDescription($name, $parameters)); 60 | } 61 | 62 | $assertion = $this->creator->create(lcfirst(substr($name, 3)), $parameters); 63 | 64 | return new Assertion(new Key($key, $assertion->getRule()), $assertion->getDescription()); 65 | } 66 | 67 | /** 68 | * @param mixed[] $parameters 69 | */ 70 | private function getDescription(string $name, array $parameters): null|string|Throwable 71 | { 72 | $description = array_shift($parameters) ?? null; 73 | if (is_null($description) || is_string($description) || $description instanceof Throwable) { 74 | return $description; 75 | } 76 | 77 | throw new CannotCreateAssertionException(sprintf('"%s" assertion has an invalid error description', $name)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Creator/NotCreator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Creator; 15 | 16 | use Respect\Assertion\Assertion; 17 | use Respect\Assertion\Creator; 18 | use Respect\Assertion\Exception\CannotCreateAssertionException; 19 | use Respect\Validation\Rules\Not; 20 | 21 | use function in_array; 22 | use function lcfirst; 23 | use function str_starts_with; 24 | use function strtolower; 25 | use function substr; 26 | 27 | final class NotCreator implements Creator 28 | { 29 | private const IGNORED_RULES = [ 30 | 'notemoji', 31 | 'notempty', 32 | 'notblank', 33 | 'notoptional', 34 | ]; 35 | 36 | public function __construct( 37 | private readonly Creator $creator 38 | ) { 39 | } 40 | 41 | /** 42 | * {@inheritdoc} 43 | */ 44 | public function create(string $name, array $parameters): Assertion 45 | { 46 | if (!str_starts_with(strtolower($name), 'not') || in_array(strtolower($name), self::IGNORED_RULES)) { 47 | throw CannotCreateAssertionException::fromAssertionName($name); 48 | } 49 | 50 | $assertion = $this->creator->create(lcfirst(substr($name, 3)), $parameters); 51 | 52 | return new Assertion(new Not($assertion->getRule()), $assertion->getDescription()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Creator/NullOrCreator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Creator; 15 | 16 | use Respect\Assertion\Assertion; 17 | use Respect\Assertion\Creator; 18 | use Respect\Assertion\Exception\CannotCreateAssertionException; 19 | use Respect\Validation\Rules\Nullable; 20 | 21 | use function lcfirst; 22 | use function str_starts_with; 23 | use function substr; 24 | 25 | final class NullOrCreator implements Creator 26 | { 27 | public function __construct( 28 | private readonly Creator $creator 29 | ) { 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function create(string $name, array $parameters): Assertion 36 | { 37 | if (!str_starts_with($name, 'nullOr')) { 38 | throw CannotCreateAssertionException::fromAssertionName($name); 39 | } 40 | 41 | $assertion = $this->creator->create(lcfirst(substr($name, 6)), $parameters); 42 | 43 | return new Assertion(new Nullable($assertion->getRule()), $assertion->getDescription()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Creator/PrefixedCreator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Creator; 15 | 16 | use ReflectionClass; 17 | use Respect\Assertion\Assertion; 18 | use Respect\Assertion\Creator; 19 | use Respect\Assertion\Exception\CannotCreateAssertionException; 20 | use Respect\Validation\Validatable; 21 | 22 | use function lcfirst; 23 | use function str_starts_with; 24 | use function strlen; 25 | use function substr; 26 | 27 | final class PrefixedCreator implements Creator 28 | { 29 | /** 30 | * @param class-string $className 31 | */ 32 | public function __construct( 33 | private readonly string $prefix, 34 | private readonly string $className, 35 | private readonly Creator $creator 36 | ) { 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | public function create(string $name, array $parameters): Assertion 43 | { 44 | if (!str_starts_with($name, $this->prefix)) { 45 | throw CannotCreateAssertionException::fromAssertionName($name); 46 | } 47 | 48 | $assertion = $this->creator->create(lcfirst(substr($name, strlen($this->prefix))), $parameters); 49 | $reflection = new ReflectionClass($this->className); 50 | 51 | return new Assertion($reflection->newInstance($assertion->getRule()), $assertion->getDescription()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Creator/PropertyCreator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Creator; 15 | 16 | use Respect\Assertion\Assertion; 17 | use Respect\Assertion\Creator; 18 | use Respect\Assertion\Exception\CannotCreateAssertionException; 19 | use Respect\Validation\Rules\Attribute; 20 | use Respect\Validation\Rules\Not; 21 | use Throwable; 22 | 23 | use function array_shift; 24 | use function is_null; 25 | use function is_string; 26 | use function lcfirst; 27 | use function Respect\Stringifier\stringify; 28 | use function sprintf; 29 | use function str_starts_with; 30 | use function substr; 31 | 32 | final class PropertyCreator implements Creator 33 | { 34 | public function __construct( 35 | private readonly Creator $creator 36 | ) { 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | public function create(string $name, array $parameters): Assertion 43 | { 44 | if (!str_starts_with($name, 'property')) { 45 | throw CannotCreateAssertionException::fromAssertionName($name); 46 | } 47 | 48 | $property = array_shift($parameters); 49 | if (!is_string($property)) { 50 | throw new CannotCreateAssertionException(sprintf('%s is an invalid property name', stringify($property))); 51 | } 52 | 53 | if ($name === 'propertyPresent') { 54 | return new Assertion(new Attribute($property), $this->getDescription($name, $parameters)); 55 | } 56 | 57 | if ($name === 'propertyNotPresent') { 58 | return new Assertion(new Not(new Attribute($property)), $this->getDescription($name, $parameters)); 59 | } 60 | 61 | $assertion = $this->creator->create(lcfirst(substr($name, 8)), $parameters); 62 | 63 | return new Assertion(new Attribute($property, $assertion->getRule()), $assertion->getDescription()); 64 | } 65 | 66 | /** 67 | * @param mixed[] $parameters 68 | */ 69 | private function getDescription(string $name, array $parameters): null|string|Throwable 70 | { 71 | $description = array_shift($parameters) ?? null; 72 | if (is_null($description) || is_string($description) || $description instanceof Throwable) { 73 | return $description; 74 | } 75 | 76 | throw new CannotCreateAssertionException(sprintf('"%s" assertion has an invalid error description', $name)); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Creator/StandardCreator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Creator; 15 | 16 | use ReflectionClass; 17 | use Respect\Assertion\Assertion; 18 | use Respect\Assertion\Creator; 19 | use Respect\Assertion\Exception\CannotCreateAssertionException; 20 | use Respect\Validation\Validatable; 21 | use Throwable; 22 | 23 | use function array_slice; 24 | use function class_exists; 25 | use function count; 26 | use function current; 27 | use function is_null; 28 | use function is_string; 29 | use function sprintf; 30 | use function ucfirst; 31 | 32 | final class StandardCreator implements Creator 33 | { 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public function create(string $name, array $parameters): Assertion 38 | { 39 | $reflection = $this->ruleReflection($name); 40 | $constructor = $reflection->getConstructor(); 41 | 42 | $constructorParameters = array_slice( 43 | $parameters, 44 | 0, 45 | $constructor === null ? 0 : count($constructor->getParameters()) 46 | ); 47 | 48 | /** @var Validatable $rule */ 49 | $rule = $reflection->newInstanceArgs($constructorParameters); 50 | 51 | return new Assertion($rule, $this->description($name, $parameters, $constructorParameters)); 52 | } 53 | 54 | /** 55 | * @return ReflectionClass 56 | */ 57 | private function ruleReflection(string $name): ReflectionClass 58 | { 59 | $class = sprintf('Respect\\Validation\\Rules\\%s', ucfirst($name)); 60 | 61 | if (!class_exists($class)) { 62 | throw new CannotCreateAssertionException(sprintf('"%s" is not a valid assertion', $name)); 63 | } 64 | 65 | $reflection = new ReflectionClass($class); 66 | if (!$reflection->isInstantiable()) { 67 | throw new CannotCreateAssertionException(sprintf('Cannot create an instance of "%s"', $class)); 68 | } 69 | 70 | if (!$reflection->isSubclassOf(Validatable::class)) { 71 | throw new CannotCreateAssertionException(sprintf('Cannot create an instance of "%s"', $class)); 72 | } 73 | 74 | return $reflection; 75 | } 76 | 77 | /** 78 | * @param mixed[] $parameters 79 | * @param mixed[] $constructorParameters 80 | */ 81 | private function description(string $name, array $parameters, array $constructorParameters): null|string|Throwable 82 | { 83 | if ($constructorParameters === $parameters) { 84 | return null; 85 | } 86 | 87 | $description = current(array_slice($parameters, count($constructorParameters), 1)) ?? null; 88 | if (is_null($description) || is_string($description) || $description instanceof Throwable) { 89 | return $description; 90 | } 91 | 92 | throw new CannotCreateAssertionException(sprintf('"%s" assertion has an invalid error description', $name)); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Exception/CannotCreateAssertionException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Exception; 15 | 16 | use RuntimeException; 17 | 18 | use function sprintf; 19 | 20 | final class CannotCreateAssertionException extends RuntimeException implements Exception 21 | { 22 | public static function fromAssertionName(string $name): self 23 | { 24 | return new self(sprintf('Cannot create assertion for "%s"', $name)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Exception/Exception.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Exception; 15 | 16 | use Throwable; 17 | 18 | interface Exception extends Throwable 19 | { 20 | } 21 | -------------------------------------------------------------------------------- /src/Mixin/Chain/AllMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Chain; 15 | 16 | use finfo; 17 | use Throwable; 18 | 19 | // phpcs:disable Generic.Files.LineLength.TooLong 20 | interface AllMixin 21 | { 22 | public function allAlnum(string $additionalChars = '', null|string|Throwable $description = null): static; 23 | 24 | public function allAlpha(string $additionalChars = '', null|string|Throwable $description = null): static; 25 | 26 | public function allArrayType(null|string|Throwable $description = null): static; 27 | 28 | public function allArrayVal(null|string|Throwable $description = null): static; 29 | 30 | public function allBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 31 | 32 | public function allBase64(null|string|Throwable $description = null): static; 33 | 34 | public function allBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 35 | 36 | public function allBic(string $countryCode, null|string|Throwable $description = null): static; 37 | 38 | public function allBoolType(null|string|Throwable $description = null): static; 39 | 40 | public function allBoolVal(null|string|Throwable $description = null): static; 41 | 42 | public function allBsn(null|string|Throwable $description = null): static; 43 | 44 | public function allCallableType(null|string|Throwable $description = null): static; 45 | 46 | public function allCallback(callable $callback, null|string|Throwable $description = null): static; 47 | 48 | public function allCharset(string $charset = '', null|string|Throwable $description = null): static; 49 | 50 | public function allCnh(null|string|Throwable $description = null): static; 51 | 52 | public function allCnpj(null|string|Throwable $description = null): static; 53 | 54 | public function allControl(string $additionalChars = '', null|string|Throwable $description = null): static; 55 | 56 | public function allConsonant(string $additionalChars = '', null|string|Throwable $description = null): static; 57 | 58 | public function allContains(mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): static; 59 | 60 | /** 61 | * @param mixed[] $needles 62 | */ 63 | public function allContainsAny(array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): static; 64 | 65 | public function allCountable(null|string|Throwable $description = null): static; 66 | 67 | public function allCountryCode(?string $set = null, null|string|Throwable $description = null): static; 68 | 69 | public function allCurrencyCode(null|string|Throwable $description = null): static; 70 | 71 | public function allCpf(null|string|Throwable $description = null): static; 72 | 73 | public function allCreditCard(?string $brand = null, null|string|Throwable $description = null): static; 74 | 75 | public function allDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 76 | 77 | public function allDateTime(?string $format = null, null|string|Throwable $description = null): static; 78 | 79 | public function allDecimal(int $decimals, null|string|Throwable $description = null): static; 80 | 81 | public function allDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 82 | 83 | public function allDirectory(null|string|Throwable $description = null): static; 84 | 85 | public function allDomain(bool $tldCheck = true, null|string|Throwable $description = null): static; 86 | 87 | public function allEmail(null|string|Throwable $description = null): static; 88 | 89 | public function allEndsWith(mixed $endValue, bool $identical = false, null|string|Throwable $description = null): static; 90 | 91 | public function allEquals(mixed $compareTo, null|string|Throwable $description = null): static; 92 | 93 | public function allEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 94 | 95 | public function allEven(null|string|Throwable $description = null): static; 96 | 97 | public function allExecutable(null|string|Throwable $description = null): static; 98 | 99 | public function allExists(null|string|Throwable $description = null): static; 100 | 101 | public function allExtension(string $extension, null|string|Throwable $description = null): static; 102 | 103 | public function allFactor(int $dividend, null|string|Throwable $description = null): static; 104 | 105 | public function allFalseVal(null|string|Throwable $description = null): static; 106 | 107 | public function allFibonacci(null|string|Throwable $description = null): static; 108 | 109 | public function allFile(null|string|Throwable $description = null): static; 110 | 111 | /** 112 | * @param mixed[]|int $options 113 | */ 114 | public function allFilterVar(int $filter, array|int|null $options = null, null|string|Throwable $description = null): static; 115 | 116 | public function allFinite(null|string|Throwable $description = null): static; 117 | 118 | public function allFloatVal(null|string|Throwable $description = null): static; 119 | 120 | public function allFloatType(null|string|Throwable $description = null): static; 121 | 122 | public function allGraph(string $additionalChars = '', null|string|Throwable $description = null): static; 123 | 124 | public function allGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 125 | 126 | public function allHexRgbColor(null|string|Throwable $description = null): static; 127 | 128 | public function allIban(null|string|Throwable $description = null): static; 129 | 130 | public function allIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 131 | 132 | public function allImage(?finfo $fileInfo = null, null|string|Throwable $description = null): static; 133 | 134 | public function allImei(null|string|Throwable $description = null): static; 135 | 136 | public function allIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 137 | 138 | public function allInfinite(null|string|Throwable $description = null): static; 139 | 140 | public function allInstance(string $instanceName, null|string|Throwable $description = null): static; 141 | 142 | public function allIntVal(null|string|Throwable $description = null): static; 143 | 144 | public function allIntType(null|string|Throwable $description = null): static; 145 | 146 | public function allIp(string $range = '*', ?int $options = null, null|string|Throwable $description = null): static; 147 | 148 | public function allIsbn(null|string|Throwable $description = null): static; 149 | 150 | public function allIterableType(null|string|Throwable $description = null): static; 151 | 152 | public function allJson(null|string|Throwable $description = null): static; 153 | 154 | public function allLanguageCode(?string $set = null, null|string|Throwable $description = null): static; 155 | 156 | public function allLeapDate(string $format, null|string|Throwable $description = null): static; 157 | 158 | public function allLeapYear(null|string|Throwable $description = null): static; 159 | 160 | public function allLowercase(null|string|Throwable $description = null): static; 161 | 162 | public function allLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 163 | 164 | public function allLuhn(null|string|Throwable $description = null): static; 165 | 166 | public function allMacAddress(null|string|Throwable $description = null): static; 167 | 168 | public function allMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 169 | 170 | public function allMimetype(string $mimetype, null|string|Throwable $description = null): static; 171 | 172 | public function allMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 173 | 174 | public function allMultiple(int $multipleOf, null|string|Throwable $description = null): static; 175 | 176 | public function allNegative(null|string|Throwable $description = null): static; 177 | 178 | public function allNfeAccessKey(null|string|Throwable $description = null): static; 179 | 180 | public function allNif(null|string|Throwable $description = null): static; 181 | 182 | public function allNip(null|string|Throwable $description = null): static; 183 | 184 | public function allNo(bool $useLocale = false, null|string|Throwable $description = null): static; 185 | 186 | public function allNotBlank(null|string|Throwable $description = null): static; 187 | 188 | public function allNotEmoji(null|string|Throwable $description = null): static; 189 | 190 | public function allNotEmpty(null|string|Throwable $description = null): static; 191 | 192 | public function allNotOptional(null|string|Throwable $description = null): static; 193 | 194 | public function allNoWhitespace(null|string|Throwable $description = null): static; 195 | 196 | public function allNullType(null|string|Throwable $description = null): static; 197 | 198 | public function allNumber(null|string|Throwable $description = null): static; 199 | 200 | public function allNumericVal(null|string|Throwable $description = null): static; 201 | 202 | public function allObjectType(null|string|Throwable $description = null): static; 203 | 204 | public function allOdd(null|string|Throwable $description = null): static; 205 | 206 | public function allPerfectSquare(null|string|Throwable $description = null): static; 207 | 208 | public function allPesel(null|string|Throwable $description = null): static; 209 | 210 | public function allPhone(null|string|Throwable $description = null): static; 211 | 212 | public function allPhpLabel(null|string|Throwable $description = null): static; 213 | 214 | public function allPis(null|string|Throwable $description = null): static; 215 | 216 | public function allPolishIdCard(null|string|Throwable $description = null): static; 217 | 218 | public function allPositive(null|string|Throwable $description = null): static; 219 | 220 | public function allPostalCode(string $countryCode, null|string|Throwable $description = null): static; 221 | 222 | public function allPrimeNumber(null|string|Throwable $description = null): static; 223 | 224 | public function allPrintable(string $additionalChars = '', null|string|Throwable $description = null): static; 225 | 226 | public function allPunct(string $additionalChars = '', null|string|Throwable $description = null): static; 227 | 228 | public function allReadable(null|string|Throwable $description = null): static; 229 | 230 | public function allRegex(string $regex, null|string|Throwable $description = null): static; 231 | 232 | public function allResourceType(null|string|Throwable $description = null): static; 233 | 234 | public function allRoman(null|string|Throwable $description = null): static; 235 | 236 | public function allScalarVal(null|string|Throwable $description = null): static; 237 | 238 | public function allSize(?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): static; 239 | 240 | public function allSlug(null|string|Throwable $description = null): static; 241 | 242 | public function allSorted(string $direction, null|string|Throwable $description = null): static; 243 | 244 | public function allSpace(string $additionalChars = '', null|string|Throwable $description = null): static; 245 | 246 | public function allStartsWith(mixed $startValue, bool $identical = false, null|string|Throwable $description = null): static; 247 | 248 | public function allStringType(null|string|Throwable $description = null): static; 249 | 250 | public function allStringVal(null|string|Throwable $description = null): static; 251 | 252 | public function allSubdivisionCode(string $countryCode, null|string|Throwable $description = null): static; 253 | 254 | /** 255 | * @param mixed[] $superset 256 | */ 257 | public function allSubset(array $superset, null|string|Throwable $description = null): static; 258 | 259 | public function allSymbolicLink(null|string|Throwable $description = null): static; 260 | 261 | public function allTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 262 | 263 | public function allTld(null|string|Throwable $description = null): static; 264 | 265 | public function allTrueVal(null|string|Throwable $description = null): static; 266 | 267 | public function allType(string $type, null|string|Throwable $description = null): static; 268 | 269 | public function allUnique(null|string|Throwable $description = null): static; 270 | 271 | public function allUploaded(null|string|Throwable $description = null): static; 272 | 273 | public function allUppercase(null|string|Throwable $description = null): static; 274 | 275 | public function allUrl(null|string|Throwable $description = null): static; 276 | 277 | public function allUuid(?int $version = null, null|string|Throwable $description = null): static; 278 | 279 | public function allVersion(null|string|Throwable $description = null): static; 280 | 281 | public function allVideoUrl(?string $service = null, null|string|Throwable $description = null): static; 282 | 283 | public function allVowel(string $additionalChars = '', null|string|Throwable $description = null): static; 284 | 285 | public function allWritable(null|string|Throwable $description = null): static; 286 | 287 | public function allXdigit(string $additionalChars = '', null|string|Throwable $description = null): static; 288 | 289 | public function allYes(bool $useLocale = false, null|string|Throwable $description = null): static; 290 | 291 | public function allNotAlnum(string $additionalChars = '', null|string|Throwable $description = null): static; 292 | 293 | public function allNotAlpha(string $additionalChars = '', null|string|Throwable $description = null): static; 294 | 295 | public function allNotArrayType(null|string|Throwable $description = null): static; 296 | 297 | public function allNotArrayVal(null|string|Throwable $description = null): static; 298 | 299 | public function allNotBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 300 | 301 | public function allNotBase64(null|string|Throwable $description = null): static; 302 | 303 | public function allNotBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 304 | 305 | public function allNotBic(string $countryCode, null|string|Throwable $description = null): static; 306 | 307 | public function allNotBoolType(null|string|Throwable $description = null): static; 308 | 309 | public function allNotBoolVal(null|string|Throwable $description = null): static; 310 | 311 | public function allNotBsn(null|string|Throwable $description = null): static; 312 | 313 | public function allNotCallableType(null|string|Throwable $description = null): static; 314 | 315 | public function allNotCallback(callable $callback, null|string|Throwable $description = null): static; 316 | 317 | public function allNotCharset(string $charset = '', null|string|Throwable $description = null): static; 318 | 319 | public function allNotCnh(null|string|Throwable $description = null): static; 320 | 321 | public function allNotCnpj(null|string|Throwable $description = null): static; 322 | 323 | public function allNotControl(string $additionalChars = '', null|string|Throwable $description = null): static; 324 | 325 | public function allNotConsonant(string $additionalChars = '', null|string|Throwable $description = null): static; 326 | 327 | public function allNotContains(mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): static; 328 | 329 | /** 330 | * @param mixed[] $needles 331 | */ 332 | public function allNotContainsAny(array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): static; 333 | 334 | public function allNotCountable(null|string|Throwable $description = null): static; 335 | 336 | public function allNotCountryCode(?string $set = null, null|string|Throwable $description = null): static; 337 | 338 | public function allNotCurrencyCode(null|string|Throwable $description = null): static; 339 | 340 | public function allNotCpf(null|string|Throwable $description = null): static; 341 | 342 | public function allNotCreditCard(?string $brand = null, null|string|Throwable $description = null): static; 343 | 344 | public function allNotDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 345 | 346 | public function allNotDateTime(?string $format = null, null|string|Throwable $description = null): static; 347 | 348 | public function allNotDecimal(int $decimals, null|string|Throwable $description = null): static; 349 | 350 | public function allNotDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 351 | 352 | public function allNotDirectory(null|string|Throwable $description = null): static; 353 | 354 | public function allNotDomain(bool $tldCheck = true, null|string|Throwable $description = null): static; 355 | 356 | public function allNotEmail(null|string|Throwable $description = null): static; 357 | 358 | public function allNotEndsWith(mixed $endValue, bool $identical = false, null|string|Throwable $description = null): static; 359 | 360 | public function allNotEquals(mixed $compareTo, null|string|Throwable $description = null): static; 361 | 362 | public function allNotEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 363 | 364 | public function allNotEven(null|string|Throwable $description = null): static; 365 | 366 | public function allNotExecutable(null|string|Throwable $description = null): static; 367 | 368 | public function allNotExists(null|string|Throwable $description = null): static; 369 | 370 | public function allNotExtension(string $extension, null|string|Throwable $description = null): static; 371 | 372 | public function allNotFactor(int $dividend, null|string|Throwable $description = null): static; 373 | 374 | public function allNotFalseVal(null|string|Throwable $description = null): static; 375 | 376 | public function allNotFibonacci(null|string|Throwable $description = null): static; 377 | 378 | public function allNotFile(null|string|Throwable $description = null): static; 379 | 380 | /** 381 | * @param mixed[]|int $options 382 | */ 383 | public function allNotFilterVar(int $filter, array|int|null $options = null, null|string|Throwable $description = null): static; 384 | 385 | public function allNotFinite(null|string|Throwable $description = null): static; 386 | 387 | public function allNotFloatVal(null|string|Throwable $description = null): static; 388 | 389 | public function allNotFloatType(null|string|Throwable $description = null): static; 390 | 391 | public function allNotGraph(string $additionalChars = '', null|string|Throwable $description = null): static; 392 | 393 | public function allNotGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 394 | 395 | public function allNotHexRgbColor(null|string|Throwable $description = null): static; 396 | 397 | public function allNotIban(null|string|Throwable $description = null): static; 398 | 399 | public function allNotIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 400 | 401 | public function allNotImage(?finfo $fileInfo = null, null|string|Throwable $description = null): static; 402 | 403 | public function allNotImei(null|string|Throwable $description = null): static; 404 | 405 | public function allNotIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 406 | 407 | public function allNotInfinite(null|string|Throwable $description = null): static; 408 | 409 | public function allNotInstance(string $instanceName, null|string|Throwable $description = null): static; 410 | 411 | public function allNotIntVal(null|string|Throwable $description = null): static; 412 | 413 | public function allNotIntType(null|string|Throwable $description = null): static; 414 | 415 | public function allNotIp(string $range = '*', ?int $options = null, null|string|Throwable $description = null): static; 416 | 417 | public function allNotIsbn(null|string|Throwable $description = null): static; 418 | 419 | public function allNotIterableType(null|string|Throwable $description = null): static; 420 | 421 | public function allNotJson(null|string|Throwable $description = null): static; 422 | 423 | public function allNotLanguageCode(?string $set = null, null|string|Throwable $description = null): static; 424 | 425 | public function allNotLeapDate(string $format, null|string|Throwable $description = null): static; 426 | 427 | public function allNotLeapYear(null|string|Throwable $description = null): static; 428 | 429 | public function allNotLowercase(null|string|Throwable $description = null): static; 430 | 431 | public function allNotLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 432 | 433 | public function allNotLuhn(null|string|Throwable $description = null): static; 434 | 435 | public function allNotMacAddress(null|string|Throwable $description = null): static; 436 | 437 | public function allNotMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 438 | 439 | public function allNotMimetype(string $mimetype, null|string|Throwable $description = null): static; 440 | 441 | public function allNotMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 442 | 443 | public function allNotMultiple(int $multipleOf, null|string|Throwable $description = null): static; 444 | 445 | public function allNotNegative(null|string|Throwable $description = null): static; 446 | 447 | public function allNotNfeAccessKey(null|string|Throwable $description = null): static; 448 | 449 | public function allNotNif(null|string|Throwable $description = null): static; 450 | 451 | public function allNotNip(null|string|Throwable $description = null): static; 452 | 453 | public function allNotNo(bool $useLocale = false, null|string|Throwable $description = null): static; 454 | 455 | public function allNotNoWhitespace(null|string|Throwable $description = null): static; 456 | 457 | public function allNotNullType(null|string|Throwable $description = null): static; 458 | 459 | public function allNotNumber(null|string|Throwable $description = null): static; 460 | 461 | public function allNotNumericVal(null|string|Throwable $description = null): static; 462 | 463 | public function allNotObjectType(null|string|Throwable $description = null): static; 464 | 465 | public function allNotOdd(null|string|Throwable $description = null): static; 466 | 467 | public function allNotPerfectSquare(null|string|Throwable $description = null): static; 468 | 469 | public function allNotPesel(null|string|Throwable $description = null): static; 470 | 471 | public function allNotPhone(null|string|Throwable $description = null): static; 472 | 473 | public function allNotPhpLabel(null|string|Throwable $description = null): static; 474 | 475 | public function allNotPis(null|string|Throwable $description = null): static; 476 | 477 | public function allNotPolishIdCard(null|string|Throwable $description = null): static; 478 | 479 | public function allNotPositive(null|string|Throwable $description = null): static; 480 | 481 | public function allNotPostalCode(string $countryCode, null|string|Throwable $description = null): static; 482 | 483 | public function allNotPrimeNumber(null|string|Throwable $description = null): static; 484 | 485 | public function allNotPrintable(string $additionalChars = '', null|string|Throwable $description = null): static; 486 | 487 | public function allNotPunct(string $additionalChars = '', null|string|Throwable $description = null): static; 488 | 489 | public function allNotReadable(null|string|Throwable $description = null): static; 490 | 491 | public function allNotRegex(string $regex, null|string|Throwable $description = null): static; 492 | 493 | public function allNotResourceType(null|string|Throwable $description = null): static; 494 | 495 | public function allNotRoman(null|string|Throwable $description = null): static; 496 | 497 | public function allNotScalarVal(null|string|Throwable $description = null): static; 498 | 499 | public function allNotSize(?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): static; 500 | 501 | public function allNotSlug(null|string|Throwable $description = null): static; 502 | 503 | public function allNotSorted(string $direction, null|string|Throwable $description = null): static; 504 | 505 | public function allNotSpace(string $additionalChars = '', null|string|Throwable $description = null): static; 506 | 507 | public function allNotStartsWith(mixed $startValue, bool $identical = false, null|string|Throwable $description = null): static; 508 | 509 | public function allNotStringType(null|string|Throwable $description = null): static; 510 | 511 | public function allNotStringVal(null|string|Throwable $description = null): static; 512 | 513 | public function allNotSubdivisionCode(string $countryCode, null|string|Throwable $description = null): static; 514 | 515 | /** 516 | * @param mixed[] $superset 517 | */ 518 | public function allNotSubset(array $superset, null|string|Throwable $description = null): static; 519 | 520 | public function allNotSymbolicLink(null|string|Throwable $description = null): static; 521 | 522 | public function allNotTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 523 | 524 | public function allNotTld(null|string|Throwable $description = null): static; 525 | 526 | public function allNotTrueVal(null|string|Throwable $description = null): static; 527 | 528 | public function allNotType(string $type, null|string|Throwable $description = null): static; 529 | 530 | public function allNotUnique(null|string|Throwable $description = null): static; 531 | 532 | public function allNotUploaded(null|string|Throwable $description = null): static; 533 | 534 | public function allNotUppercase(null|string|Throwable $description = null): static; 535 | 536 | public function allNotUrl(null|string|Throwable $description = null): static; 537 | 538 | public function allNotUuid(?int $version = null, null|string|Throwable $description = null): static; 539 | 540 | public function allNotVersion(null|string|Throwable $description = null): static; 541 | 542 | public function allNotVideoUrl(?string $service = null, null|string|Throwable $description = null): static; 543 | 544 | public function allNotVowel(string $additionalChars = '', null|string|Throwable $description = null): static; 545 | 546 | public function allNotWritable(null|string|Throwable $description = null): static; 547 | 548 | public function allNotXdigit(string $additionalChars = '', null|string|Throwable $description = null): static; 549 | 550 | public function allNotYes(bool $useLocale = false, null|string|Throwable $description = null): static; 551 | } 552 | -------------------------------------------------------------------------------- /src/Mixin/Chain/LengthMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Chain; 15 | 16 | use Throwable; 17 | 18 | // phpcs:disable Generic.Files.LineLength.TooLong 19 | interface LengthMixin 20 | { 21 | public function lengthBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 22 | 23 | public function lengthNotBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 24 | 25 | public function lengthBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 26 | 27 | public function lengthNotBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 28 | 29 | public function lengthDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 30 | 31 | public function lengthNotDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 32 | 33 | public function lengthDateTime(?string $format = null, null|string|Throwable $description = null): static; 34 | 35 | public function lengthNotDateTime(?string $format = null, null|string|Throwable $description = null): static; 36 | 37 | public function lengthDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 38 | 39 | public function lengthNotDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 40 | 41 | public function lengthEquals(mixed $compareTo, null|string|Throwable $description = null): static; 42 | 43 | public function lengthNotEquals(mixed $compareTo, null|string|Throwable $description = null): static; 44 | 45 | public function lengthEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 46 | 47 | public function lengthNotEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 48 | 49 | public function lengthEven(null|string|Throwable $description = null): static; 50 | 51 | public function lengthNotEven(null|string|Throwable $description = null): static; 52 | 53 | public function lengthFactor(int $dividend, null|string|Throwable $description = null): static; 54 | 55 | public function lengthNotFactor(int $dividend, null|string|Throwable $description = null): static; 56 | 57 | public function lengthFibonacci(null|string|Throwable $description = null): static; 58 | 59 | public function lengthNotFibonacci(null|string|Throwable $description = null): static; 60 | 61 | public function lengthFinite(null|string|Throwable $description = null): static; 62 | 63 | public function lengthNotFinite(null|string|Throwable $description = null): static; 64 | 65 | public function lengthFloatType(null|string|Throwable $description = null): static; 66 | 67 | public function lengthNotFloatType(null|string|Throwable $description = null): static; 68 | 69 | public function lengthFloatVal(null|string|Throwable $description = null): static; 70 | 71 | public function lengthNotFloatVal(null|string|Throwable $description = null): static; 72 | 73 | public function lengthGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 74 | 75 | public function lengthNotGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 76 | 77 | public function lengthIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 78 | 79 | public function lengthNotIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 80 | 81 | public function lengthIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 82 | 83 | public function lengthNotIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 84 | 85 | public function lengthInfinite(null|string|Throwable $description = null): static; 86 | 87 | public function lengthNotInfinite(null|string|Throwable $description = null): static; 88 | 89 | public function lengthIntType(null|string|Throwable $description = null): static; 90 | 91 | public function lengthNotIntType(null|string|Throwable $description = null): static; 92 | 93 | public function lengthIntVal(null|string|Throwable $description = null): static; 94 | 95 | public function lengthNotIntVal(null|string|Throwable $description = null): static; 96 | 97 | public function lengthLeapDate(string $format, null|string|Throwable $description = null): static; 98 | 99 | public function lengthNotLeapDate(string $format, null|string|Throwable $description = null): static; 100 | 101 | public function lengthLeapYear(null|string|Throwable $description = null): static; 102 | 103 | public function lengthNotLeapYear(null|string|Throwable $description = null): static; 104 | 105 | public function lengthLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 106 | 107 | public function lengthNotLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 108 | 109 | public function lengthMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 110 | 111 | public function lengthNotMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 112 | 113 | public function lengthMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 114 | 115 | public function lengthNotMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 116 | 117 | public function lengthMultiple(int $multipleOf, null|string|Throwable $description = null): static; 118 | 119 | public function lengthNotMultiple(int $multipleOf, null|string|Throwable $description = null): static; 120 | 121 | public function lengthNegative(null|string|Throwable $description = null): static; 122 | 123 | public function lengthNotNegative(null|string|Throwable $description = null): static; 124 | 125 | public function lengthNumber(null|string|Throwable $description = null): static; 126 | 127 | public function lengthNotNumber(null|string|Throwable $description = null): static; 128 | 129 | public function lengthNumericVal(null|string|Throwable $description = null): static; 130 | 131 | public function lengthNotNumericVal(null|string|Throwable $description = null): static; 132 | 133 | public function lengthOdd(null|string|Throwable $description = null): static; 134 | 135 | public function lengthNotOdd(null|string|Throwable $description = null): static; 136 | 137 | public function lengthPerfectSquare(null|string|Throwable $description = null): static; 138 | 139 | public function lengthNotPerfectSquare(null|string|Throwable $description = null): static; 140 | 141 | public function lengthPositive(null|string|Throwable $description = null): static; 142 | 143 | public function lengthNotPositive(null|string|Throwable $description = null): static; 144 | 145 | public function lengthPrimeNumber(null|string|Throwable $description = null): static; 146 | 147 | public function lengthNotPrimeNumber(null|string|Throwable $description = null): static; 148 | 149 | public function lengthRoman(null|string|Throwable $description = null): static; 150 | 151 | public function lengthNotRoman(null|string|Throwable $description = null): static; 152 | 153 | public function lengthStringType(null|string|Throwable $description = null): static; 154 | 155 | public function lengthNotStringType(null|string|Throwable $description = null): static; 156 | 157 | public function lengthStringVal(null|string|Throwable $description = null): static; 158 | 159 | public function lengthNotStringVal(null|string|Throwable $description = null): static; 160 | 161 | public function lengthTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 162 | 163 | public function lengthNotTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 164 | } 165 | -------------------------------------------------------------------------------- /src/Mixin/Chain/MaxMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Chain; 15 | 16 | use Throwable; 17 | 18 | // phpcs:disable Generic.Files.LineLength.TooLong 19 | interface MaxMixin 20 | { 21 | public function maxBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 22 | 23 | public function maxNotBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 24 | 25 | public function maxBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 26 | 27 | public function maxNotBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 28 | 29 | public function maxDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 30 | 31 | public function maxNotDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 32 | 33 | public function maxDateTime(?string $format = null, null|string|Throwable $description = null): static; 34 | 35 | public function maxNotDateTime(?string $format = null, null|string|Throwable $description = null): static; 36 | 37 | public function maxDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 38 | 39 | public function maxNotDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 40 | 41 | public function maxEquals(mixed $compareTo, null|string|Throwable $description = null): static; 42 | 43 | public function maxNotEquals(mixed $compareTo, null|string|Throwable $description = null): static; 44 | 45 | public function maxEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 46 | 47 | public function maxNotEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 48 | 49 | public function maxEven(null|string|Throwable $description = null): static; 50 | 51 | public function maxNotEven(null|string|Throwable $description = null): static; 52 | 53 | public function maxFactor(int $dividend, null|string|Throwable $description = null): static; 54 | 55 | public function maxNotFactor(int $dividend, null|string|Throwable $description = null): static; 56 | 57 | public function maxFibonacci(null|string|Throwable $description = null): static; 58 | 59 | public function maxNotFibonacci(null|string|Throwable $description = null): static; 60 | 61 | public function maxFinite(null|string|Throwable $description = null): static; 62 | 63 | public function maxNotFinite(null|string|Throwable $description = null): static; 64 | 65 | public function maxFloatType(null|string|Throwable $description = null): static; 66 | 67 | public function maxNotFloatType(null|string|Throwable $description = null): static; 68 | 69 | public function maxFloatVal(null|string|Throwable $description = null): static; 70 | 71 | public function maxNotFloatVal(null|string|Throwable $description = null): static; 72 | 73 | public function maxGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 74 | 75 | public function maxNotGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 76 | 77 | public function maxIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 78 | 79 | public function maxNotIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 80 | 81 | public function maxIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 82 | 83 | public function maxNotIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 84 | 85 | public function maxInfinite(null|string|Throwable $description = null): static; 86 | 87 | public function maxNotInfinite(null|string|Throwable $description = null): static; 88 | 89 | public function maxIntType(null|string|Throwable $description = null): static; 90 | 91 | public function maxNotIntType(null|string|Throwable $description = null): static; 92 | 93 | public function maxIntVal(null|string|Throwable $description = null): static; 94 | 95 | public function maxNotIntVal(null|string|Throwable $description = null): static; 96 | 97 | public function maxLeapDate(string $format, null|string|Throwable $description = null): static; 98 | 99 | public function maxNotLeapDate(string $format, null|string|Throwable $description = null): static; 100 | 101 | public function maxLeapYear(null|string|Throwable $description = null): static; 102 | 103 | public function maxNotLeapYear(null|string|Throwable $description = null): static; 104 | 105 | public function maxLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 106 | 107 | public function maxNotLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 108 | 109 | public function maxMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 110 | 111 | public function maxNotMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 112 | 113 | public function maxMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 114 | 115 | public function maxNotMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 116 | 117 | public function maxMultiple(int $multipleOf, null|string|Throwable $description = null): static; 118 | 119 | public function maxNotMultiple(int $multipleOf, null|string|Throwable $description = null): static; 120 | 121 | public function maxNegative(null|string|Throwable $description = null): static; 122 | 123 | public function maxNotNegative(null|string|Throwable $description = null): static; 124 | 125 | public function maxNumber(null|string|Throwable $description = null): static; 126 | 127 | public function maxNotNumber(null|string|Throwable $description = null): static; 128 | 129 | public function maxNumericVal(null|string|Throwable $description = null): static; 130 | 131 | public function maxNotNumericVal(null|string|Throwable $description = null): static; 132 | 133 | public function maxOdd(null|string|Throwable $description = null): static; 134 | 135 | public function maxNotOdd(null|string|Throwable $description = null): static; 136 | 137 | public function maxPerfectSquare(null|string|Throwable $description = null): static; 138 | 139 | public function maxNotPerfectSquare(null|string|Throwable $description = null): static; 140 | 141 | public function maxPositive(null|string|Throwable $description = null): static; 142 | 143 | public function maxNotPositive(null|string|Throwable $description = null): static; 144 | 145 | public function maxPrimeNumber(null|string|Throwable $description = null): static; 146 | 147 | public function maxNotPrimeNumber(null|string|Throwable $description = null): static; 148 | 149 | public function maxRoman(null|string|Throwable $description = null): static; 150 | 151 | public function maxNotRoman(null|string|Throwable $description = null): static; 152 | 153 | public function maxStringType(null|string|Throwable $description = null): static; 154 | 155 | public function maxNotStringType(null|string|Throwable $description = null): static; 156 | 157 | public function maxStringVal(null|string|Throwable $description = null): static; 158 | 159 | public function maxNotStringVal(null|string|Throwable $description = null): static; 160 | 161 | public function maxTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 162 | 163 | public function maxNotTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 164 | } 165 | -------------------------------------------------------------------------------- /src/Mixin/Chain/MinMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Chain; 15 | 16 | use Throwable; 17 | 18 | // phpcs:disable Generic.Files.LineLength.TooLong 19 | interface MinMixin 20 | { 21 | public function minBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 22 | 23 | public function minNotBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 24 | 25 | public function minBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 26 | 27 | public function minNotBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 28 | 29 | public function minDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 30 | 31 | public function minNotDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 32 | 33 | public function minDateTime(?string $format = null, null|string|Throwable $description = null): static; 34 | 35 | public function minNotDateTime(?string $format = null, null|string|Throwable $description = null): static; 36 | 37 | public function minDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 38 | 39 | public function minNotDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 40 | 41 | public function minEquals(mixed $compareTo, null|string|Throwable $description = null): static; 42 | 43 | public function minNotEquals(mixed $compareTo, null|string|Throwable $description = null): static; 44 | 45 | public function minEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 46 | 47 | public function minNotEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 48 | 49 | public function minEven(null|string|Throwable $description = null): static; 50 | 51 | public function minNotEven(null|string|Throwable $description = null): static; 52 | 53 | public function minFactor(int $dividend, null|string|Throwable $description = null): static; 54 | 55 | public function minNotFactor(int $dividend, null|string|Throwable $description = null): static; 56 | 57 | public function minFibonacci(null|string|Throwable $description = null): static; 58 | 59 | public function minNotFibonacci(null|string|Throwable $description = null): static; 60 | 61 | public function minFinite(null|string|Throwable $description = null): static; 62 | 63 | public function minNotFinite(null|string|Throwable $description = null): static; 64 | 65 | public function minFloatType(null|string|Throwable $description = null): static; 66 | 67 | public function minNotFloatType(null|string|Throwable $description = null): static; 68 | 69 | public function minFloatVal(null|string|Throwable $description = null): static; 70 | 71 | public function minNotFloatVal(null|string|Throwable $description = null): static; 72 | 73 | public function minGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 74 | 75 | public function minNotGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 76 | 77 | public function minIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 78 | 79 | public function minNotIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 80 | 81 | public function minIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 82 | 83 | public function minNotIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 84 | 85 | public function minInfinite(null|string|Throwable $description = null): static; 86 | 87 | public function minNotInfinite(null|string|Throwable $description = null): static; 88 | 89 | public function minIntType(null|string|Throwable $description = null): static; 90 | 91 | public function minNotIntType(null|string|Throwable $description = null): static; 92 | 93 | public function minIntVal(null|string|Throwable $description = null): static; 94 | 95 | public function minNotIntVal(null|string|Throwable $description = null): static; 96 | 97 | public function minLeapDate(string $format, null|string|Throwable $description = null): static; 98 | 99 | public function minNotLeapDate(string $format, null|string|Throwable $description = null): static; 100 | 101 | public function minLeapYear(null|string|Throwable $description = null): static; 102 | 103 | public function minNotLeapYear(null|string|Throwable $description = null): static; 104 | 105 | public function minLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 106 | 107 | public function minNotLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 108 | 109 | public function minMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 110 | 111 | public function minNotMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 112 | 113 | public function minMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 114 | 115 | public function minNotMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 116 | 117 | public function minMultiple(int $multipleOf, null|string|Throwable $description = null): static; 118 | 119 | public function minNotMultiple(int $multipleOf, null|string|Throwable $description = null): static; 120 | 121 | public function minNegative(null|string|Throwable $description = null): static; 122 | 123 | public function minNotNegative(null|string|Throwable $description = null): static; 124 | 125 | public function minNumber(null|string|Throwable $description = null): static; 126 | 127 | public function minNotNumber(null|string|Throwable $description = null): static; 128 | 129 | public function minNumericVal(null|string|Throwable $description = null): static; 130 | 131 | public function minNotNumericVal(null|string|Throwable $description = null): static; 132 | 133 | public function minOdd(null|string|Throwable $description = null): static; 134 | 135 | public function minNotOdd(null|string|Throwable $description = null): static; 136 | 137 | public function minPerfectSquare(null|string|Throwable $description = null): static; 138 | 139 | public function minNotPerfectSquare(null|string|Throwable $description = null): static; 140 | 141 | public function minPositive(null|string|Throwable $description = null): static; 142 | 143 | public function minNotPositive(null|string|Throwable $description = null): static; 144 | 145 | public function minPrimeNumber(null|string|Throwable $description = null): static; 146 | 147 | public function minNotPrimeNumber(null|string|Throwable $description = null): static; 148 | 149 | public function minRoman(null|string|Throwable $description = null): static; 150 | 151 | public function minNotRoman(null|string|Throwable $description = null): static; 152 | 153 | public function minStringType(null|string|Throwable $description = null): static; 154 | 155 | public function minNotStringType(null|string|Throwable $description = null): static; 156 | 157 | public function minStringVal(null|string|Throwable $description = null): static; 158 | 159 | public function minNotStringVal(null|string|Throwable $description = null): static; 160 | 161 | public function minTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 162 | 163 | public function minNotTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 164 | } 165 | -------------------------------------------------------------------------------- /src/Mixin/Chain/Mixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Chain; 15 | 16 | use finfo; 17 | use Throwable; 18 | 19 | // phpcs:disable Generic.Files.LineLength.TooLong 20 | interface Mixin extends AllMixin, KeyMixin, LengthMixin, MaxMixin, MinMixin, NullOrMixin, PropertyMixin 21 | { 22 | public function alnum(string $additionalChars = '', null|string|Throwable $description = null): static; 23 | 24 | public function alpha(string $additionalChars = '', null|string|Throwable $description = null): static; 25 | 26 | public function arrayType(null|string|Throwable $description = null): static; 27 | 28 | public function arrayVal(null|string|Throwable $description = null): static; 29 | 30 | public function base(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 31 | 32 | public function base64(null|string|Throwable $description = null): static; 33 | 34 | public function between(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 35 | 36 | public function bic(string $countryCode, null|string|Throwable $description = null): static; 37 | 38 | public function boolType(null|string|Throwable $description = null): static; 39 | 40 | public function boolVal(null|string|Throwable $description = null): static; 41 | 42 | public function bsn(null|string|Throwable $description = null): static; 43 | 44 | public function callableType(null|string|Throwable $description = null): static; 45 | 46 | public function callback(callable $callback, null|string|Throwable $description = null): static; 47 | 48 | public function charset(string $charset = '', null|string|Throwable $description = null): static; 49 | 50 | public function cnh(null|string|Throwable $description = null): static; 51 | 52 | public function cnpj(null|string|Throwable $description = null): static; 53 | 54 | public function control(string $additionalChars = '', null|string|Throwable $description = null): static; 55 | 56 | public function consonant(string $additionalChars = '', null|string|Throwable $description = null): static; 57 | 58 | public function contains(mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): static; 59 | 60 | /** 61 | * @param mixed[] $needles 62 | */ 63 | public function containsAny(array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): static; 64 | 65 | public function countable(null|string|Throwable $description = null): static; 66 | 67 | public function countryCode(?string $set = null, null|string|Throwable $description = null): static; 68 | 69 | public function currencyCode(null|string|Throwable $description = null): static; 70 | 71 | public function cpf(null|string|Throwable $description = null): static; 72 | 73 | public function creditCard(?string $brand = null, null|string|Throwable $description = null): static; 74 | 75 | public function date(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 76 | 77 | public function dateTime(?string $format = null, null|string|Throwable $description = null): static; 78 | 79 | public function decimal(int $decimals, null|string|Throwable $description = null): static; 80 | 81 | public function digit(string $additionalChars = '', null|string|Throwable $description = null): static; 82 | 83 | public function directory(null|string|Throwable $description = null): static; 84 | 85 | public function domain(bool $tldCheck = true, null|string|Throwable $description = null): static; 86 | 87 | public function email(null|string|Throwable $description = null): static; 88 | 89 | public function endsWith(mixed $endValue, bool $identical = false, null|string|Throwable $description = null): static; 90 | 91 | public function equals(mixed $compareTo, null|string|Throwable $description = null): static; 92 | 93 | public function equivalent(mixed $compareTo, null|string|Throwable $description = null): static; 94 | 95 | public function even(null|string|Throwable $description = null): static; 96 | 97 | public function executable(null|string|Throwable $description = null): static; 98 | 99 | public function exists(null|string|Throwable $description = null): static; 100 | 101 | public function extension(string $extension, null|string|Throwable $description = null): static; 102 | 103 | public function factor(int $dividend, null|string|Throwable $description = null): static; 104 | 105 | public function falseVal(null|string|Throwable $description = null): static; 106 | 107 | public function fibonacci(null|string|Throwable $description = null): static; 108 | 109 | public function file(null|string|Throwable $description = null): static; 110 | 111 | /** 112 | * @param mixed[]|int $options 113 | */ 114 | public function filterVar(int $filter, array|int|null $options = null, null|string|Throwable $description = null): static; 115 | 116 | public function finite(null|string|Throwable $description = null): static; 117 | 118 | public function floatVal(null|string|Throwable $description = null): static; 119 | 120 | public function floatType(null|string|Throwable $description = null): static; 121 | 122 | public function graph(string $additionalChars = '', null|string|Throwable $description = null): static; 123 | 124 | public function greaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 125 | 126 | public function hexRgbColor(null|string|Throwable $description = null): static; 127 | 128 | public function iban(null|string|Throwable $description = null): static; 129 | 130 | public function identical(mixed $compareTo, null|string|Throwable $description = null): static; 131 | 132 | public function image(?finfo $fileInfo = null, null|string|Throwable $description = null): static; 133 | 134 | public function imei(null|string|Throwable $description = null): static; 135 | 136 | public function in(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 137 | 138 | public function infinite(null|string|Throwable $description = null): static; 139 | 140 | public function instance(string $instanceName, null|string|Throwable $description = null): static; 141 | 142 | public function intVal(null|string|Throwable $description = null): static; 143 | 144 | public function intType(null|string|Throwable $description = null): static; 145 | 146 | public function ip(string $range = '*', ?int $options = null, null|string|Throwable $description = null): static; 147 | 148 | public function isbn(null|string|Throwable $description = null): static; 149 | 150 | public function iterableType(null|string|Throwable $description = null): static; 151 | 152 | public function json(null|string|Throwable $description = null): static; 153 | 154 | public function languageCode(?string $set = null, null|string|Throwable $description = null): static; 155 | 156 | public function leapDate(string $format, null|string|Throwable $description = null): static; 157 | 158 | public function leapYear(null|string|Throwable $description = null): static; 159 | 160 | public function lowercase(null|string|Throwable $description = null): static; 161 | 162 | public function lessThan(mixed $compareTo, null|string|Throwable $description = null): static; 163 | 164 | public function luhn(null|string|Throwable $description = null): static; 165 | 166 | public function macAddress(null|string|Throwable $description = null): static; 167 | 168 | public function maxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 169 | 170 | public function mimetype(string $mimetype, null|string|Throwable $description = null): static; 171 | 172 | public function minAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 173 | 174 | public function multiple(int $multipleOf, null|string|Throwable $description = null): static; 175 | 176 | public function negative(null|string|Throwable $description = null): static; 177 | 178 | public function nfeAccessKey(null|string|Throwable $description = null): static; 179 | 180 | public function nif(null|string|Throwable $description = null): static; 181 | 182 | public function nip(null|string|Throwable $description = null): static; 183 | 184 | public function no(bool $useLocale = false, null|string|Throwable $description = null): static; 185 | 186 | public function notBlank(null|string|Throwable $description = null): static; 187 | 188 | public function notEmoji(null|string|Throwable $description = null): static; 189 | 190 | public function notEmpty(null|string|Throwable $description = null): static; 191 | 192 | public function notOptional(null|string|Throwable $description = null): static; 193 | 194 | public function noWhitespace(null|string|Throwable $description = null): static; 195 | 196 | public function nullType(null|string|Throwable $description = null): static; 197 | 198 | public function number(null|string|Throwable $description = null): static; 199 | 200 | public function numericVal(null|string|Throwable $description = null): static; 201 | 202 | public function objectType(null|string|Throwable $description = null): static; 203 | 204 | public function odd(null|string|Throwable $description = null): static; 205 | 206 | public function perfectSquare(null|string|Throwable $description = null): static; 207 | 208 | public function pesel(null|string|Throwable $description = null): static; 209 | 210 | public function phone(null|string|Throwable $description = null): static; 211 | 212 | public function phpLabel(null|string|Throwable $description = null): static; 213 | 214 | public function pis(null|string|Throwable $description = null): static; 215 | 216 | public function polishIdCard(null|string|Throwable $description = null): static; 217 | 218 | public function positive(null|string|Throwable $description = null): static; 219 | 220 | public function postalCode(string $countryCode, null|string|Throwable $description = null): static; 221 | 222 | public function primeNumber(null|string|Throwable $description = null): static; 223 | 224 | public function printable(string $additionalChars = '', null|string|Throwable $description = null): static; 225 | 226 | public function punct(string $additionalChars = '', null|string|Throwable $description = null): static; 227 | 228 | public function readable(null|string|Throwable $description = null): static; 229 | 230 | public function regex(string $regex, null|string|Throwable $description = null): static; 231 | 232 | public function resourceType(null|string|Throwable $description = null): static; 233 | 234 | public function roman(null|string|Throwable $description = null): static; 235 | 236 | public function scalarVal(null|string|Throwable $description = null): static; 237 | 238 | public function size(?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): static; 239 | 240 | public function slug(null|string|Throwable $description = null): static; 241 | 242 | public function sorted(string $direction, null|string|Throwable $description = null): static; 243 | 244 | public function space(string $additionalChars = '', null|string|Throwable $description = null): static; 245 | 246 | public function startsWith(mixed $startValue, bool $identical = false, null|string|Throwable $description = null): static; 247 | 248 | public function stringType(null|string|Throwable $description = null): static; 249 | 250 | public function stringVal(null|string|Throwable $description = null): static; 251 | 252 | public function subdivisionCode(string $countryCode, null|string|Throwable $description = null): static; 253 | 254 | /** 255 | * @param mixed[] $superset 256 | */ 257 | public function subset(array $superset, null|string|Throwable $description = null): static; 258 | 259 | public function symbolicLink(null|string|Throwable $description = null): static; 260 | 261 | public function time(string $format = 'H:i:s', null|string|Throwable $description = null): static; 262 | 263 | public function tld(null|string|Throwable $description = null): static; 264 | 265 | public function trueVal(null|string|Throwable $description = null): static; 266 | 267 | public function type(string $type, null|string|Throwable $description = null): static; 268 | 269 | public function unique(null|string|Throwable $description = null): static; 270 | 271 | public function uploaded(null|string|Throwable $description = null): static; 272 | 273 | public function uppercase(null|string|Throwable $description = null): static; 274 | 275 | public function url(null|string|Throwable $description = null): static; 276 | 277 | public function uuid(?int $version = null, null|string|Throwable $description = null): static; 278 | 279 | public function version(null|string|Throwable $description = null): static; 280 | 281 | public function videoUrl(?string $service = null, null|string|Throwable $description = null): static; 282 | 283 | public function vowel(string $additionalChars = '', null|string|Throwable $description = null): static; 284 | 285 | public function writable(null|string|Throwable $description = null): static; 286 | 287 | public function xdigit(string $additionalChars = '', null|string|Throwable $description = null): static; 288 | 289 | public function yes(bool $useLocale = false, null|string|Throwable $description = null): static; 290 | 291 | public function notAlnum(string $additionalChars = '', null|string|Throwable $description = null): static; 292 | 293 | public function notAlpha(string $additionalChars = '', null|string|Throwable $description = null): static; 294 | 295 | public function notArrayType(null|string|Throwable $description = null): static; 296 | 297 | public function notArrayVal(null|string|Throwable $description = null): static; 298 | 299 | public function notBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 300 | 301 | public function notBase64(null|string|Throwable $description = null): static; 302 | 303 | public function notBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 304 | 305 | public function notBic(string $countryCode, null|string|Throwable $description = null): static; 306 | 307 | public function notBoolType(null|string|Throwable $description = null): static; 308 | 309 | public function notBoolVal(null|string|Throwable $description = null): static; 310 | 311 | public function notBsn(null|string|Throwable $description = null): static; 312 | 313 | public function notCallableType(null|string|Throwable $description = null): static; 314 | 315 | public function notCallback(callable $callback, null|string|Throwable $description = null): static; 316 | 317 | public function notCharset(string $charset = '', null|string|Throwable $description = null): static; 318 | 319 | public function notCnh(null|string|Throwable $description = null): static; 320 | 321 | public function notCnpj(null|string|Throwable $description = null): static; 322 | 323 | public function notControl(string $additionalChars = '', null|string|Throwable $description = null): static; 324 | 325 | public function notConsonant(string $additionalChars = '', null|string|Throwable $description = null): static; 326 | 327 | public function notContains(mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): static; 328 | 329 | /** 330 | * @param mixed[] $needles 331 | */ 332 | public function notContainsAny(array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): static; 333 | 334 | public function notCountable(null|string|Throwable $description = null): static; 335 | 336 | public function notCountryCode(?string $set = null, null|string|Throwable $description = null): static; 337 | 338 | public function notCurrencyCode(null|string|Throwable $description = null): static; 339 | 340 | public function notCpf(null|string|Throwable $description = null): static; 341 | 342 | public function notCreditCard(?string $brand = null, null|string|Throwable $description = null): static; 343 | 344 | public function notDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 345 | 346 | public function notDateTime(?string $format = null, null|string|Throwable $description = null): static; 347 | 348 | public function notDecimal(int $decimals, null|string|Throwable $description = null): static; 349 | 350 | public function notDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 351 | 352 | public function notDirectory(null|string|Throwable $description = null): static; 353 | 354 | public function notDomain(bool $tldCheck = true, null|string|Throwable $description = null): static; 355 | 356 | public function notEmail(null|string|Throwable $description = null): static; 357 | 358 | public function notEndsWith(mixed $endValue, bool $identical = false, null|string|Throwable $description = null): static; 359 | 360 | public function notEquals(mixed $compareTo, null|string|Throwable $description = null): static; 361 | 362 | public function notEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 363 | 364 | public function notEven(null|string|Throwable $description = null): static; 365 | 366 | public function notExecutable(null|string|Throwable $description = null): static; 367 | 368 | public function notExists(null|string|Throwable $description = null): static; 369 | 370 | public function notExtension(string $extension, null|string|Throwable $description = null): static; 371 | 372 | public function notFactor(int $dividend, null|string|Throwable $description = null): static; 373 | 374 | public function notFalseVal(null|string|Throwable $description = null): static; 375 | 376 | public function notFibonacci(null|string|Throwable $description = null): static; 377 | 378 | public function notFile(null|string|Throwable $description = null): static; 379 | 380 | /** 381 | * @param mixed[]|int $options 382 | */ 383 | public function notFilterVar(int $filter, array|int|null $options = null, null|string|Throwable $description = null): static; 384 | 385 | public function notFinite(null|string|Throwable $description = null): static; 386 | 387 | public function notFloatVal(null|string|Throwable $description = null): static; 388 | 389 | public function notFloatType(null|string|Throwable $description = null): static; 390 | 391 | public function notGraph(string $additionalChars = '', null|string|Throwable $description = null): static; 392 | 393 | public function notGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 394 | 395 | public function notHexRgbColor(null|string|Throwable $description = null): static; 396 | 397 | public function notIban(null|string|Throwable $description = null): static; 398 | 399 | public function notIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 400 | 401 | public function notImage(?finfo $fileInfo = null, null|string|Throwable $description = null): static; 402 | 403 | public function notImei(null|string|Throwable $description = null): static; 404 | 405 | public function notIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 406 | 407 | public function notInfinite(null|string|Throwable $description = null): static; 408 | 409 | public function notInstance(string $instanceName, null|string|Throwable $description = null): static; 410 | 411 | public function notIntVal(null|string|Throwable $description = null): static; 412 | 413 | public function notIntType(null|string|Throwable $description = null): static; 414 | 415 | public function notIp(string $range = '*', ?int $options = null, null|string|Throwable $description = null): static; 416 | 417 | public function notIsbn(null|string|Throwable $description = null): static; 418 | 419 | public function notIterableType(null|string|Throwable $description = null): static; 420 | 421 | public function notJson(null|string|Throwable $description = null): static; 422 | 423 | public function notLanguageCode(?string $set = null, null|string|Throwable $description = null): static; 424 | 425 | public function notLeapDate(string $format, null|string|Throwable $description = null): static; 426 | 427 | public function notLeapYear(null|string|Throwable $description = null): static; 428 | 429 | public function notLowercase(null|string|Throwable $description = null): static; 430 | 431 | public function notLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 432 | 433 | public function notLuhn(null|string|Throwable $description = null): static; 434 | 435 | public function notMacAddress(null|string|Throwable $description = null): static; 436 | 437 | public function notMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 438 | 439 | public function notMimetype(string $mimetype, null|string|Throwable $description = null): static; 440 | 441 | public function notMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 442 | 443 | public function notMultiple(int $multipleOf, null|string|Throwable $description = null): static; 444 | 445 | public function notNegative(null|string|Throwable $description = null): static; 446 | 447 | public function notNfeAccessKey(null|string|Throwable $description = null): static; 448 | 449 | public function notNif(null|string|Throwable $description = null): static; 450 | 451 | public function notNip(null|string|Throwable $description = null): static; 452 | 453 | public function notNo(bool $useLocale = false, null|string|Throwable $description = null): static; 454 | 455 | public function notNoWhitespace(null|string|Throwable $description = null): static; 456 | 457 | public function notNullType(null|string|Throwable $description = null): static; 458 | 459 | public function notNumber(null|string|Throwable $description = null): static; 460 | 461 | public function notNumericVal(null|string|Throwable $description = null): static; 462 | 463 | public function notObjectType(null|string|Throwable $description = null): static; 464 | 465 | public function notOdd(null|string|Throwable $description = null): static; 466 | 467 | public function notPerfectSquare(null|string|Throwable $description = null): static; 468 | 469 | public function notPesel(null|string|Throwable $description = null): static; 470 | 471 | public function notPhone(null|string|Throwable $description = null): static; 472 | 473 | public function notPhpLabel(null|string|Throwable $description = null): static; 474 | 475 | public function notPis(null|string|Throwable $description = null): static; 476 | 477 | public function notPolishIdCard(null|string|Throwable $description = null): static; 478 | 479 | public function notPositive(null|string|Throwable $description = null): static; 480 | 481 | public function notPostalCode(string $countryCode, null|string|Throwable $description = null): static; 482 | 483 | public function notPrimeNumber(null|string|Throwable $description = null): static; 484 | 485 | public function notPrintable(string $additionalChars = '', null|string|Throwable $description = null): static; 486 | 487 | public function notPunct(string $additionalChars = '', null|string|Throwable $description = null): static; 488 | 489 | public function notReadable(null|string|Throwable $description = null): static; 490 | 491 | public function notRegex(string $regex, null|string|Throwable $description = null): static; 492 | 493 | public function notResourceType(null|string|Throwable $description = null): static; 494 | 495 | public function notRoman(null|string|Throwable $description = null): static; 496 | 497 | public function notScalarVal(null|string|Throwable $description = null): static; 498 | 499 | public function notSize(?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): static; 500 | 501 | public function notSlug(null|string|Throwable $description = null): static; 502 | 503 | public function notSorted(string $direction, null|string|Throwable $description = null): static; 504 | 505 | public function notSpace(string $additionalChars = '', null|string|Throwable $description = null): static; 506 | 507 | public function notStartsWith(mixed $startValue, bool $identical = false, null|string|Throwable $description = null): static; 508 | 509 | public function notStringType(null|string|Throwable $description = null): static; 510 | 511 | public function notStringVal(null|string|Throwable $description = null): static; 512 | 513 | public function notSubdivisionCode(string $countryCode, null|string|Throwable $description = null): static; 514 | 515 | /** 516 | * @param mixed[] $superset 517 | */ 518 | public function notSubset(array $superset, null|string|Throwable $description = null): static; 519 | 520 | public function notSymbolicLink(null|string|Throwable $description = null): static; 521 | 522 | public function notTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 523 | 524 | public function notTld(null|string|Throwable $description = null): static; 525 | 526 | public function notTrueVal(null|string|Throwable $description = null): static; 527 | 528 | public function notType(string $type, null|string|Throwable $description = null): static; 529 | 530 | public function notUnique(null|string|Throwable $description = null): static; 531 | 532 | public function notUploaded(null|string|Throwable $description = null): static; 533 | 534 | public function notUppercase(null|string|Throwable $description = null): static; 535 | 536 | public function notUrl(null|string|Throwable $description = null): static; 537 | 538 | public function notUuid(?int $version = null, null|string|Throwable $description = null): static; 539 | 540 | public function notVersion(null|string|Throwable $description = null): static; 541 | 542 | public function notVideoUrl(?string $service = null, null|string|Throwable $description = null): static; 543 | 544 | public function notVowel(string $additionalChars = '', null|string|Throwable $description = null): static; 545 | 546 | public function notWritable(null|string|Throwable $description = null): static; 547 | 548 | public function notXdigit(string $additionalChars = '', null|string|Throwable $description = null): static; 549 | 550 | public function notYes(bool $useLocale = false, null|string|Throwable $description = null): static; 551 | } 552 | -------------------------------------------------------------------------------- /src/Mixin/Chain/NullOrMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Chain; 15 | 16 | use finfo; 17 | use Throwable; 18 | 19 | // phpcs:disable Generic.Files.LineLength.TooLong 20 | interface NullOrMixin 21 | { 22 | public function nullOrAlnum(string $additionalChars = '', null|string|Throwable $description = null): static; 23 | 24 | public function nullOrAlpha(string $additionalChars = '', null|string|Throwable $description = null): static; 25 | 26 | public function nullOrArrayType(null|string|Throwable $description = null): static; 27 | 28 | public function nullOrArrayVal(null|string|Throwable $description = null): static; 29 | 30 | public function nullOrBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 31 | 32 | public function nullOrBase64(null|string|Throwable $description = null): static; 33 | 34 | public function nullOrBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 35 | 36 | public function nullOrBic(string $countryCode, null|string|Throwable $description = null): static; 37 | 38 | public function nullOrBoolType(null|string|Throwable $description = null): static; 39 | 40 | public function nullOrBoolVal(null|string|Throwable $description = null): static; 41 | 42 | public function nullOrBsn(null|string|Throwable $description = null): static; 43 | 44 | public function nullOrCallableType(null|string|Throwable $description = null): static; 45 | 46 | public function nullOrCallback(callable $callback, null|string|Throwable $description = null): static; 47 | 48 | public function nullOrCharset(string $charset = '', null|string|Throwable $description = null): static; 49 | 50 | public function nullOrCnh(null|string|Throwable $description = null): static; 51 | 52 | public function nullOrCnpj(null|string|Throwable $description = null): static; 53 | 54 | public function nullOrControl(string $additionalChars = '', null|string|Throwable $description = null): static; 55 | 56 | public function nullOrConsonant(string $additionalChars = '', null|string|Throwable $description = null): static; 57 | 58 | public function nullOrContains(mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): static; 59 | 60 | /** 61 | * @param mixed[] $needles 62 | */ 63 | public function nullOrContainsAny(array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): static; 64 | 65 | public function nullOrCountable(null|string|Throwable $description = null): static; 66 | 67 | public function nullOrCountryCode(?string $set = null, null|string|Throwable $description = null): static; 68 | 69 | public function nullOrCurrencyCode(null|string|Throwable $description = null): static; 70 | 71 | public function nullOrCpf(null|string|Throwable $description = null): static; 72 | 73 | public function nullOrCreditCard(?string $brand = null, null|string|Throwable $description = null): static; 74 | 75 | public function nullOrDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 76 | 77 | public function nullOrDateTime(?string $format = null, null|string|Throwable $description = null): static; 78 | 79 | public function nullOrDecimal(int $decimals, null|string|Throwable $description = null): static; 80 | 81 | public function nullOrDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 82 | 83 | public function nullOrDirectory(null|string|Throwable $description = null): static; 84 | 85 | public function nullOrDomain(bool $tldCheck = true, null|string|Throwable $description = null): static; 86 | 87 | public function nullOrEmail(null|string|Throwable $description = null): static; 88 | 89 | public function nullOrEndsWith(mixed $endValue, bool $identical = false, null|string|Throwable $description = null): static; 90 | 91 | public function nullOrEquals(mixed $compareTo, null|string|Throwable $description = null): static; 92 | 93 | public function nullOrEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 94 | 95 | public function nullOrEven(null|string|Throwable $description = null): static; 96 | 97 | public function nullOrExecutable(null|string|Throwable $description = null): static; 98 | 99 | public function nullOrExists(null|string|Throwable $description = null): static; 100 | 101 | public function nullOrExtension(string $extension, null|string|Throwable $description = null): static; 102 | 103 | public function nullOrFactor(int $dividend, null|string|Throwable $description = null): static; 104 | 105 | public function nullOrFalseVal(null|string|Throwable $description = null): static; 106 | 107 | public function nullOrFibonacci(null|string|Throwable $description = null): static; 108 | 109 | public function nullOrFile(null|string|Throwable $description = null): static; 110 | 111 | /** 112 | * @param mixed[]|int $options 113 | */ 114 | public function nullOrFilterVar(int $filter, array|int|null $options = null, null|string|Throwable $description = null): static; 115 | 116 | public function nullOrFinite(null|string|Throwable $description = null): static; 117 | 118 | public function nullOrFloatVal(null|string|Throwable $description = null): static; 119 | 120 | public function nullOrFloatType(null|string|Throwable $description = null): static; 121 | 122 | public function nullOrGraph(string $additionalChars = '', null|string|Throwable $description = null): static; 123 | 124 | public function nullOrGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 125 | 126 | public function nullOrHexRgbColor(null|string|Throwable $description = null): static; 127 | 128 | public function nullOrIban(null|string|Throwable $description = null): static; 129 | 130 | public function nullOrIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 131 | 132 | public function nullOrImage(?finfo $fileInfo = null, null|string|Throwable $description = null): static; 133 | 134 | public function nullOrImei(null|string|Throwable $description = null): static; 135 | 136 | public function nullOrIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 137 | 138 | public function nullOrInfinite(null|string|Throwable $description = null): static; 139 | 140 | public function nullOrInstance(string $instanceName, null|string|Throwable $description = null): static; 141 | 142 | public function nullOrIntVal(null|string|Throwable $description = null): static; 143 | 144 | public function nullOrIntType(null|string|Throwable $description = null): static; 145 | 146 | public function nullOrIp(string $range = '*', ?int $options = null, null|string|Throwable $description = null): static; 147 | 148 | public function nullOrIsbn(null|string|Throwable $description = null): static; 149 | 150 | public function nullOrIterableType(null|string|Throwable $description = null): static; 151 | 152 | public function nullOrJson(null|string|Throwable $description = null): static; 153 | 154 | public function nullOrLanguageCode(?string $set = null, null|string|Throwable $description = null): static; 155 | 156 | public function nullOrLeapDate(string $format, null|string|Throwable $description = null): static; 157 | 158 | public function nullOrLeapYear(null|string|Throwable $description = null): static; 159 | 160 | public function nullOrLowercase(null|string|Throwable $description = null): static; 161 | 162 | public function nullOrLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 163 | 164 | public function nullOrLuhn(null|string|Throwable $description = null): static; 165 | 166 | public function nullOrMacAddress(null|string|Throwable $description = null): static; 167 | 168 | public function nullOrMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 169 | 170 | public function nullOrMimetype(string $mimetype, null|string|Throwable $description = null): static; 171 | 172 | public function nullOrMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 173 | 174 | public function nullOrMultiple(int $multipleOf, null|string|Throwable $description = null): static; 175 | 176 | public function nullOrNegative(null|string|Throwable $description = null): static; 177 | 178 | public function nullOrNfeAccessKey(null|string|Throwable $description = null): static; 179 | 180 | public function nullOrNif(null|string|Throwable $description = null): static; 181 | 182 | public function nullOrNip(null|string|Throwable $description = null): static; 183 | 184 | public function nullOrNo(bool $useLocale = false, null|string|Throwable $description = null): static; 185 | 186 | public function nullOrNotBlank(null|string|Throwable $description = null): static; 187 | 188 | public function nullOrNotEmoji(null|string|Throwable $description = null): static; 189 | 190 | public function nullOrNotEmpty(null|string|Throwable $description = null): static; 191 | 192 | public function nullOrNotOptional(null|string|Throwable $description = null): static; 193 | 194 | public function nullOrNoWhitespace(null|string|Throwable $description = null): static; 195 | 196 | public function nullOrNullType(null|string|Throwable $description = null): static; 197 | 198 | public function nullOrNumber(null|string|Throwable $description = null): static; 199 | 200 | public function nullOrNumericVal(null|string|Throwable $description = null): static; 201 | 202 | public function nullOrObjectType(null|string|Throwable $description = null): static; 203 | 204 | public function nullOrOdd(null|string|Throwable $description = null): static; 205 | 206 | public function nullOrPerfectSquare(null|string|Throwable $description = null): static; 207 | 208 | public function nullOrPesel(null|string|Throwable $description = null): static; 209 | 210 | public function nullOrPhone(null|string|Throwable $description = null): static; 211 | 212 | public function nullOrPhpLabel(null|string|Throwable $description = null): static; 213 | 214 | public function nullOrPis(null|string|Throwable $description = null): static; 215 | 216 | public function nullOrPolishIdCard(null|string|Throwable $description = null): static; 217 | 218 | public function nullOrPositive(null|string|Throwable $description = null): static; 219 | 220 | public function nullOrPostalCode(string $countryCode, null|string|Throwable $description = null): static; 221 | 222 | public function nullOrPrimeNumber(null|string|Throwable $description = null): static; 223 | 224 | public function nullOrPrintable(string $additionalChars = '', null|string|Throwable $description = null): static; 225 | 226 | public function nullOrPunct(string $additionalChars = '', null|string|Throwable $description = null): static; 227 | 228 | public function nullOrReadable(null|string|Throwable $description = null): static; 229 | 230 | public function nullOrRegex(string $regex, null|string|Throwable $description = null): static; 231 | 232 | public function nullOrResourceType(null|string|Throwable $description = null): static; 233 | 234 | public function nullOrRoman(null|string|Throwable $description = null): static; 235 | 236 | public function nullOrScalarVal(null|string|Throwable $description = null): static; 237 | 238 | public function nullOrSize(?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): static; 239 | 240 | public function nullOrSlug(null|string|Throwable $description = null): static; 241 | 242 | public function nullOrSorted(string $direction, null|string|Throwable $description = null): static; 243 | 244 | public function nullOrSpace(string $additionalChars = '', null|string|Throwable $description = null): static; 245 | 246 | public function nullOrStartsWith(mixed $startValue, bool $identical = false, null|string|Throwable $description = null): static; 247 | 248 | public function nullOrStringType(null|string|Throwable $description = null): static; 249 | 250 | public function nullOrStringVal(null|string|Throwable $description = null): static; 251 | 252 | public function nullOrSubdivisionCode(string $countryCode, null|string|Throwable $description = null): static; 253 | 254 | /** 255 | * @param mixed[] $superset 256 | */ 257 | public function nullOrSubset(array $superset, null|string|Throwable $description = null): static; 258 | 259 | public function nullOrSymbolicLink(null|string|Throwable $description = null): static; 260 | 261 | public function nullOrTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 262 | 263 | public function nullOrTld(null|string|Throwable $description = null): static; 264 | 265 | public function nullOrTrueVal(null|string|Throwable $description = null): static; 266 | 267 | public function nullOrType(string $type, null|string|Throwable $description = null): static; 268 | 269 | public function nullOrUnique(null|string|Throwable $description = null): static; 270 | 271 | public function nullOrUploaded(null|string|Throwable $description = null): static; 272 | 273 | public function nullOrUppercase(null|string|Throwable $description = null): static; 274 | 275 | public function nullOrUrl(null|string|Throwable $description = null): static; 276 | 277 | public function nullOrUuid(?int $version = null, null|string|Throwable $description = null): static; 278 | 279 | public function nullOrVersion(null|string|Throwable $description = null): static; 280 | 281 | public function nullOrVideoUrl(?string $service = null, null|string|Throwable $description = null): static; 282 | 283 | public function nullOrVowel(string $additionalChars = '', null|string|Throwable $description = null): static; 284 | 285 | public function nullOrWritable(null|string|Throwable $description = null): static; 286 | 287 | public function nullOrXdigit(string $additionalChars = '', null|string|Throwable $description = null): static; 288 | 289 | public function nullOrYes(bool $useLocale = false, null|string|Throwable $description = null): static; 290 | 291 | public function nullOrNotAlnum(string $additionalChars = '', null|string|Throwable $description = null): static; 292 | 293 | public function nullOrNotAlpha(string $additionalChars = '', null|string|Throwable $description = null): static; 294 | 295 | public function nullOrNotArrayType(null|string|Throwable $description = null): static; 296 | 297 | public function nullOrNotArrayVal(null|string|Throwable $description = null): static; 298 | 299 | public function nullOrNotBase(int $base, ?string $chars = null, null|string|Throwable $description = null): static; 300 | 301 | public function nullOrNotBase64(null|string|Throwable $description = null): static; 302 | 303 | public function nullOrNotBetween(mixed $minimum, mixed $maximum, null|string|Throwable $description = null): static; 304 | 305 | public function nullOrNotBic(string $countryCode, null|string|Throwable $description = null): static; 306 | 307 | public function nullOrNotBoolType(null|string|Throwable $description = null): static; 308 | 309 | public function nullOrNotBoolVal(null|string|Throwable $description = null): static; 310 | 311 | public function nullOrNotBsn(null|string|Throwable $description = null): static; 312 | 313 | public function nullOrNotCallableType(null|string|Throwable $description = null): static; 314 | 315 | public function nullOrNotCallback(callable $callback, null|string|Throwable $description = null): static; 316 | 317 | public function nullOrNotCharset(string $charset = '', null|string|Throwable $description = null): static; 318 | 319 | public function nullOrNotCnh(null|string|Throwable $description = null): static; 320 | 321 | public function nullOrNotCnpj(null|string|Throwable $description = null): static; 322 | 323 | public function nullOrNotControl(string $additionalChars = '', null|string|Throwable $description = null): static; 324 | 325 | public function nullOrNotConsonant(string $additionalChars = '', null|string|Throwable $description = null): static; 326 | 327 | public function nullOrNotContains(mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): static; 328 | 329 | /** 330 | * @param mixed[] $needles 331 | */ 332 | public function nullOrNotContainsAny(array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): static; 333 | 334 | public function nullOrNotCountable(null|string|Throwable $description = null): static; 335 | 336 | public function nullOrNotCountryCode(?string $set = null, null|string|Throwable $description = null): static; 337 | 338 | public function nullOrNotCurrencyCode(null|string|Throwable $description = null): static; 339 | 340 | public function nullOrNotCpf(null|string|Throwable $description = null): static; 341 | 342 | public function nullOrNotCreditCard(?string $brand = null, null|string|Throwable $description = null): static; 343 | 344 | public function nullOrNotDate(string $format = 'Y-m-d', null|string|Throwable $description = null): static; 345 | 346 | public function nullOrNotDateTime(?string $format = null, null|string|Throwable $description = null): static; 347 | 348 | public function nullOrNotDecimal(int $decimals, null|string|Throwable $description = null): static; 349 | 350 | public function nullOrNotDigit(string $additionalChars = '', null|string|Throwable $description = null): static; 351 | 352 | public function nullOrNotDirectory(null|string|Throwable $description = null): static; 353 | 354 | public function nullOrNotDomain(bool $tldCheck = true, null|string|Throwable $description = null): static; 355 | 356 | public function nullOrNotEmail(null|string|Throwable $description = null): static; 357 | 358 | public function nullOrNotEndsWith(mixed $endValue, bool $identical = false, null|string|Throwable $description = null): static; 359 | 360 | public function nullOrNotEquals(mixed $compareTo, null|string|Throwable $description = null): static; 361 | 362 | public function nullOrNotEquivalent(mixed $compareTo, null|string|Throwable $description = null): static; 363 | 364 | public function nullOrNotEven(null|string|Throwable $description = null): static; 365 | 366 | public function nullOrNotExecutable(null|string|Throwable $description = null): static; 367 | 368 | public function nullOrNotExists(null|string|Throwable $description = null): static; 369 | 370 | public function nullOrNotExtension(string $extension, null|string|Throwable $description = null): static; 371 | 372 | public function nullOrNotFactor(int $dividend, null|string|Throwable $description = null): static; 373 | 374 | public function nullOrNotFalseVal(null|string|Throwable $description = null): static; 375 | 376 | public function nullOrNotFibonacci(null|string|Throwable $description = null): static; 377 | 378 | public function nullOrNotFile(null|string|Throwable $description = null): static; 379 | 380 | /** 381 | * @param mixed[]|int $options 382 | */ 383 | public function nullOrNotFilterVar(int $filter, array|int|null $options = null, null|string|Throwable $description = null): static; 384 | 385 | public function nullOrNotFinite(null|string|Throwable $description = null): static; 386 | 387 | public function nullOrNotFloatVal(null|string|Throwable $description = null): static; 388 | 389 | public function nullOrNotFloatType(null|string|Throwable $description = null): static; 390 | 391 | public function nullOrNotGraph(string $additionalChars = '', null|string|Throwable $description = null): static; 392 | 393 | public function nullOrNotGreaterThan(mixed $compareTo, null|string|Throwable $description = null): static; 394 | 395 | public function nullOrNotHexRgbColor(null|string|Throwable $description = null): static; 396 | 397 | public function nullOrNotIban(null|string|Throwable $description = null): static; 398 | 399 | public function nullOrNotIdentical(mixed $compareTo, null|string|Throwable $description = null): static; 400 | 401 | public function nullOrNotImage(?finfo $fileInfo = null, null|string|Throwable $description = null): static; 402 | 403 | public function nullOrNotImei(null|string|Throwable $description = null): static; 404 | 405 | public function nullOrNotIn(mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): static; 406 | 407 | public function nullOrNotInfinite(null|string|Throwable $description = null): static; 408 | 409 | public function nullOrNotInstance(string $instanceName, null|string|Throwable $description = null): static; 410 | 411 | public function nullOrNotIntVal(null|string|Throwable $description = null): static; 412 | 413 | public function nullOrNotIntType(null|string|Throwable $description = null): static; 414 | 415 | public function nullOrNotIp(string $range = '*', ?int $options = null, null|string|Throwable $description = null): static; 416 | 417 | public function nullOrNotIsbn(null|string|Throwable $description = null): static; 418 | 419 | public function nullOrNotIterableType(null|string|Throwable $description = null): static; 420 | 421 | public function nullOrNotJson(null|string|Throwable $description = null): static; 422 | 423 | public function nullOrNotLanguageCode(?string $set = null, null|string|Throwable $description = null): static; 424 | 425 | public function nullOrNotLeapDate(string $format, null|string|Throwable $description = null): static; 426 | 427 | public function nullOrNotLeapYear(null|string|Throwable $description = null): static; 428 | 429 | public function nullOrNotLowercase(null|string|Throwable $description = null): static; 430 | 431 | public function nullOrNotLessThan(mixed $compareTo, null|string|Throwable $description = null): static; 432 | 433 | public function nullOrNotLuhn(null|string|Throwable $description = null): static; 434 | 435 | public function nullOrNotMacAddress(null|string|Throwable $description = null): static; 436 | 437 | public function nullOrNotMaxAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 438 | 439 | public function nullOrNotMimetype(string $mimetype, null|string|Throwable $description = null): static; 440 | 441 | public function nullOrNotMinAge(int $age, ?string $format = null, null|string|Throwable $description = null): static; 442 | 443 | public function nullOrNotMultiple(int $multipleOf, null|string|Throwable $description = null): static; 444 | 445 | public function nullOrNotNegative(null|string|Throwable $description = null): static; 446 | 447 | public function nullOrNotNfeAccessKey(null|string|Throwable $description = null): static; 448 | 449 | public function nullOrNotNif(null|string|Throwable $description = null): static; 450 | 451 | public function nullOrNotNip(null|string|Throwable $description = null): static; 452 | 453 | public function nullOrNotNo(bool $useLocale = false, null|string|Throwable $description = null): static; 454 | 455 | public function nullOrNotNoWhitespace(null|string|Throwable $description = null): static; 456 | 457 | public function nullOrNotNullType(null|string|Throwable $description = null): static; 458 | 459 | public function nullOrNotNumber(null|string|Throwable $description = null): static; 460 | 461 | public function nullOrNotNumericVal(null|string|Throwable $description = null): static; 462 | 463 | public function nullOrNotObjectType(null|string|Throwable $description = null): static; 464 | 465 | public function nullOrNotOdd(null|string|Throwable $description = null): static; 466 | 467 | public function nullOrNotPerfectSquare(null|string|Throwable $description = null): static; 468 | 469 | public function nullOrNotPesel(null|string|Throwable $description = null): static; 470 | 471 | public function nullOrNotPhone(null|string|Throwable $description = null): static; 472 | 473 | public function nullOrNotPhpLabel(null|string|Throwable $description = null): static; 474 | 475 | public function nullOrNotPis(null|string|Throwable $description = null): static; 476 | 477 | public function nullOrNotPolishIdCard(null|string|Throwable $description = null): static; 478 | 479 | public function nullOrNotPositive(null|string|Throwable $description = null): static; 480 | 481 | public function nullOrNotPostalCode(string $countryCode, null|string|Throwable $description = null): static; 482 | 483 | public function nullOrNotPrimeNumber(null|string|Throwable $description = null): static; 484 | 485 | public function nullOrNotPrintable(string $additionalChars = '', null|string|Throwable $description = null): static; 486 | 487 | public function nullOrNotPunct(string $additionalChars = '', null|string|Throwable $description = null): static; 488 | 489 | public function nullOrNotReadable(null|string|Throwable $description = null): static; 490 | 491 | public function nullOrNotRegex(string $regex, null|string|Throwable $description = null): static; 492 | 493 | public function nullOrNotResourceType(null|string|Throwable $description = null): static; 494 | 495 | public function nullOrNotRoman(null|string|Throwable $description = null): static; 496 | 497 | public function nullOrNotScalarVal(null|string|Throwable $description = null): static; 498 | 499 | public function nullOrNotSize(?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): static; 500 | 501 | public function nullOrNotSlug(null|string|Throwable $description = null): static; 502 | 503 | public function nullOrNotSorted(string $direction, null|string|Throwable $description = null): static; 504 | 505 | public function nullOrNotSpace(string $additionalChars = '', null|string|Throwable $description = null): static; 506 | 507 | public function nullOrNotStartsWith(mixed $startValue, bool $identical = false, null|string|Throwable $description = null): static; 508 | 509 | public function nullOrNotStringType(null|string|Throwable $description = null): static; 510 | 511 | public function nullOrNotStringVal(null|string|Throwable $description = null): static; 512 | 513 | public function nullOrNotSubdivisionCode(string $countryCode, null|string|Throwable $description = null): static; 514 | 515 | /** 516 | * @param mixed[] $superset 517 | */ 518 | public function nullOrNotSubset(array $superset, null|string|Throwable $description = null): static; 519 | 520 | public function nullOrNotSymbolicLink(null|string|Throwable $description = null): static; 521 | 522 | public function nullOrNotTime(string $format = 'H:i:s', null|string|Throwable $description = null): static; 523 | 524 | public function nullOrNotTld(null|string|Throwable $description = null): static; 525 | 526 | public function nullOrNotTrueVal(null|string|Throwable $description = null): static; 527 | 528 | public function nullOrNotType(string $type, null|string|Throwable $description = null): static; 529 | 530 | public function nullOrNotUnique(null|string|Throwable $description = null): static; 531 | 532 | public function nullOrNotUploaded(null|string|Throwable $description = null): static; 533 | 534 | public function nullOrNotUppercase(null|string|Throwable $description = null): static; 535 | 536 | public function nullOrNotUrl(null|string|Throwable $description = null): static; 537 | 538 | public function nullOrNotUuid(?int $version = null, null|string|Throwable $description = null): static; 539 | 540 | public function nullOrNotVersion(null|string|Throwable $description = null): static; 541 | 542 | public function nullOrNotVideoUrl(?string $service = null, null|string|Throwable $description = null): static; 543 | 544 | public function nullOrNotVowel(string $additionalChars = '', null|string|Throwable $description = null): static; 545 | 546 | public function nullOrNotWritable(null|string|Throwable $description = null): static; 547 | 548 | public function nullOrNotXdigit(string $additionalChars = '', null|string|Throwable $description = null): static; 549 | 550 | public function nullOrNotYes(bool $useLocale = false, null|string|Throwable $description = null): static; 551 | } 552 | -------------------------------------------------------------------------------- /src/Mixin/Static/LengthMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Static; 15 | 16 | use Throwable; 17 | 18 | // phpcs:disable Generic.Files.LineLength.TooLong 19 | interface LengthMixin 20 | { 21 | public static function lengthBase(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 22 | 23 | public static function lengthNotBase(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 24 | 25 | public static function lengthBetween(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 26 | 27 | public static function lengthNotBetween(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 28 | 29 | public static function lengthDate(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 30 | 31 | public static function lengthNotDate(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 32 | 33 | public static function lengthDateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 34 | 35 | public static function lengthNotDateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 36 | 37 | public static function lengthDigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 38 | 39 | public static function lengthNotDigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 40 | 41 | public static function lengthEquals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 42 | 43 | public static function lengthNotEquals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 44 | 45 | public static function lengthEquivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 46 | 47 | public static function lengthNotEquivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 48 | 49 | public static function lengthEven(mixed $input, null|string|Throwable $description = null): void; 50 | 51 | public static function lengthNotEven(mixed $input, null|string|Throwable $description = null): void; 52 | 53 | public static function lengthFactor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 54 | 55 | public static function lengthNotFactor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 56 | 57 | public static function lengthFibonacci(mixed $input, null|string|Throwable $description = null): void; 58 | 59 | public static function lengthNotFibonacci(mixed $input, null|string|Throwable $description = null): void; 60 | 61 | public static function lengthFinite(mixed $input, null|string|Throwable $description = null): void; 62 | 63 | public static function lengthNotFinite(mixed $input, null|string|Throwable $description = null): void; 64 | 65 | public static function lengthFloatType(mixed $input, null|string|Throwable $description = null): void; 66 | 67 | public static function lengthNotFloatType(mixed $input, null|string|Throwable $description = null): void; 68 | 69 | public static function lengthFloatVal(mixed $input, null|string|Throwable $description = null): void; 70 | 71 | public static function lengthNotFloatVal(mixed $input, null|string|Throwable $description = null): void; 72 | 73 | public static function lengthGreaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 74 | 75 | public static function lengthNotGreaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 76 | 77 | public static function lengthIdentical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 78 | 79 | public static function lengthNotIdentical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 80 | 81 | public static function lengthIn(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 82 | 83 | public static function lengthNotIn(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 84 | 85 | public static function lengthInfinite(mixed $input, null|string|Throwable $description = null): void; 86 | 87 | public static function lengthNotInfinite(mixed $input, null|string|Throwable $description = null): void; 88 | 89 | public static function lengthIntType(mixed $input, null|string|Throwable $description = null): void; 90 | 91 | public static function lengthNotIntType(mixed $input, null|string|Throwable $description = null): void; 92 | 93 | public static function lengthIntVal(mixed $input, null|string|Throwable $description = null): void; 94 | 95 | public static function lengthNotIntVal(mixed $input, null|string|Throwable $description = null): void; 96 | 97 | public static function lengthLeapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 98 | 99 | public static function lengthNotLeapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 100 | 101 | public static function lengthLeapYear(mixed $input, null|string|Throwable $description = null): void; 102 | 103 | public static function lengthNotLeapYear(mixed $input, null|string|Throwable $description = null): void; 104 | 105 | public static function lengthLessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 106 | 107 | public static function lengthNotLessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 108 | 109 | public static function lengthMaxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 110 | 111 | public static function lengthNotMaxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 112 | 113 | public static function lengthMinAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 114 | 115 | public static function lengthNotMinAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 116 | 117 | public static function lengthMultiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 118 | 119 | public static function lengthNotMultiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 120 | 121 | public static function lengthNegative(mixed $input, null|string|Throwable $description = null): void; 122 | 123 | public static function lengthNotNegative(mixed $input, null|string|Throwable $description = null): void; 124 | 125 | public static function lengthNumber(mixed $input, null|string|Throwable $description = null): void; 126 | 127 | public static function lengthNotNumber(mixed $input, null|string|Throwable $description = null): void; 128 | 129 | public static function lengthNumericVal(mixed $input, null|string|Throwable $description = null): void; 130 | 131 | public static function lengthNotNumericVal(mixed $input, null|string|Throwable $description = null): void; 132 | 133 | public static function lengthOdd(mixed $input, null|string|Throwable $description = null): void; 134 | 135 | public static function lengthNotOdd(mixed $input, null|string|Throwable $description = null): void; 136 | 137 | public static function lengthPerfectSquare(mixed $input, null|string|Throwable $description = null): void; 138 | 139 | public static function lengthNotPerfectSquare(mixed $input, null|string|Throwable $description = null): void; 140 | 141 | public static function lengthPositive(mixed $input, null|string|Throwable $description = null): void; 142 | 143 | public static function lengthNotPositive(mixed $input, null|string|Throwable $description = null): void; 144 | 145 | public static function lengthPrimeNumber(mixed $input, null|string|Throwable $description = null): void; 146 | 147 | public static function lengthNotPrimeNumber(mixed $input, null|string|Throwable $description = null): void; 148 | 149 | public static function lengthRoman(mixed $input, null|string|Throwable $description = null): void; 150 | 151 | public static function lengthNotRoman(mixed $input, null|string|Throwable $description = null): void; 152 | 153 | public static function lengthStringType(mixed $input, null|string|Throwable $description = null): void; 154 | 155 | public static function lengthNotStringType(mixed $input, null|string|Throwable $description = null): void; 156 | 157 | public static function lengthStringVal(mixed $input, null|string|Throwable $description = null): void; 158 | 159 | public static function lengthNotStringVal(mixed $input, null|string|Throwable $description = null): void; 160 | 161 | public static function lengthTime(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 162 | 163 | public static function lengthNotTime(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 164 | } 165 | -------------------------------------------------------------------------------- /src/Mixin/Static/MaxMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Static; 15 | 16 | use Throwable; 17 | 18 | // phpcs:disable Generic.Files.LineLength.TooLong 19 | interface MaxMixin 20 | { 21 | public static function maxBase(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 22 | 23 | public static function maxNotBase(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 24 | 25 | public static function maxBetween(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 26 | 27 | public static function maxNotBetween(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 28 | 29 | public static function maxDate(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 30 | 31 | public static function maxNotDate(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 32 | 33 | public static function maxDateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 34 | 35 | public static function maxNotDateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 36 | 37 | public static function maxDigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 38 | 39 | public static function maxNotDigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 40 | 41 | public static function maxEquals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 42 | 43 | public static function maxNotEquals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 44 | 45 | public static function maxEquivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 46 | 47 | public static function maxNotEquivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 48 | 49 | public static function maxEven(mixed $input, null|string|Throwable $description = null): void; 50 | 51 | public static function maxNotEven(mixed $input, null|string|Throwable $description = null): void; 52 | 53 | public static function maxFactor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 54 | 55 | public static function maxNotFactor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 56 | 57 | public static function maxFibonacci(mixed $input, null|string|Throwable $description = null): void; 58 | 59 | public static function maxNotFibonacci(mixed $input, null|string|Throwable $description = null): void; 60 | 61 | public static function maxFinite(mixed $input, null|string|Throwable $description = null): void; 62 | 63 | public static function maxNotFinite(mixed $input, null|string|Throwable $description = null): void; 64 | 65 | public static function maxFloatType(mixed $input, null|string|Throwable $description = null): void; 66 | 67 | public static function maxNotFloatType(mixed $input, null|string|Throwable $description = null): void; 68 | 69 | public static function maxFloatVal(mixed $input, null|string|Throwable $description = null): void; 70 | 71 | public static function maxNotFloatVal(mixed $input, null|string|Throwable $description = null): void; 72 | 73 | public static function maxGreaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 74 | 75 | public static function maxNotGreaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 76 | 77 | public static function maxIdentical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 78 | 79 | public static function maxNotIdentical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 80 | 81 | public static function maxIn(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 82 | 83 | public static function maxNotIn(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 84 | 85 | public static function maxInfinite(mixed $input, null|string|Throwable $description = null): void; 86 | 87 | public static function maxNotInfinite(mixed $input, null|string|Throwable $description = null): void; 88 | 89 | public static function maxIntType(mixed $input, null|string|Throwable $description = null): void; 90 | 91 | public static function maxNotIntType(mixed $input, null|string|Throwable $description = null): void; 92 | 93 | public static function maxIntVal(mixed $input, null|string|Throwable $description = null): void; 94 | 95 | public static function maxNotIntVal(mixed $input, null|string|Throwable $description = null): void; 96 | 97 | public static function maxLeapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 98 | 99 | public static function maxNotLeapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 100 | 101 | public static function maxLeapYear(mixed $input, null|string|Throwable $description = null): void; 102 | 103 | public static function maxNotLeapYear(mixed $input, null|string|Throwable $description = null): void; 104 | 105 | public static function maxLessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 106 | 107 | public static function maxNotLessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 108 | 109 | public static function maxMaxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 110 | 111 | public static function maxNotMaxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 112 | 113 | public static function maxMinAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 114 | 115 | public static function maxNotMinAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 116 | 117 | public static function maxMultiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 118 | 119 | public static function maxNotMultiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 120 | 121 | public static function maxNegative(mixed $input, null|string|Throwable $description = null): void; 122 | 123 | public static function maxNotNegative(mixed $input, null|string|Throwable $description = null): void; 124 | 125 | public static function maxNumber(mixed $input, null|string|Throwable $description = null): void; 126 | 127 | public static function maxNotNumber(mixed $input, null|string|Throwable $description = null): void; 128 | 129 | public static function maxNumericVal(mixed $input, null|string|Throwable $description = null): void; 130 | 131 | public static function maxNotNumericVal(mixed $input, null|string|Throwable $description = null): void; 132 | 133 | public static function maxOdd(mixed $input, null|string|Throwable $description = null): void; 134 | 135 | public static function maxNotOdd(mixed $input, null|string|Throwable $description = null): void; 136 | 137 | public static function maxPerfectSquare(mixed $input, null|string|Throwable $description = null): void; 138 | 139 | public static function maxNotPerfectSquare(mixed $input, null|string|Throwable $description = null): void; 140 | 141 | public static function maxPositive(mixed $input, null|string|Throwable $description = null): void; 142 | 143 | public static function maxNotPositive(mixed $input, null|string|Throwable $description = null): void; 144 | 145 | public static function maxPrimeNumber(mixed $input, null|string|Throwable $description = null): void; 146 | 147 | public static function maxNotPrimeNumber(mixed $input, null|string|Throwable $description = null): void; 148 | 149 | public static function maxRoman(mixed $input, null|string|Throwable $description = null): void; 150 | 151 | public static function maxNotRoman(mixed $input, null|string|Throwable $description = null): void; 152 | 153 | public static function maxStringType(mixed $input, null|string|Throwable $description = null): void; 154 | 155 | public static function maxNotStringType(mixed $input, null|string|Throwable $description = null): void; 156 | 157 | public static function maxStringVal(mixed $input, null|string|Throwable $description = null): void; 158 | 159 | public static function maxNotStringVal(mixed $input, null|string|Throwable $description = null): void; 160 | 161 | public static function maxTime(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 162 | 163 | public static function maxNotTime(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 164 | } 165 | -------------------------------------------------------------------------------- /src/Mixin/Static/MinMixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Static; 15 | 16 | use Throwable; 17 | 18 | // phpcs:disable Generic.Files.LineLength.TooLong 19 | interface MinMixin 20 | { 21 | public static function minBase(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 22 | 23 | public static function minNotBase(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 24 | 25 | public static function minBetween(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 26 | 27 | public static function minNotBetween(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 28 | 29 | public static function minDate(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 30 | 31 | public static function minNotDate(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 32 | 33 | public static function minDateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 34 | 35 | public static function minNotDateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 36 | 37 | public static function minDigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 38 | 39 | public static function minNotDigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 40 | 41 | public static function minEquals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 42 | 43 | public static function minNotEquals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 44 | 45 | public static function minEquivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 46 | 47 | public static function minNotEquivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 48 | 49 | public static function minEven(mixed $input, null|string|Throwable $description = null): void; 50 | 51 | public static function minNotEven(mixed $input, null|string|Throwable $description = null): void; 52 | 53 | public static function minFactor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 54 | 55 | public static function minNotFactor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 56 | 57 | public static function minFibonacci(mixed $input, null|string|Throwable $description = null): void; 58 | 59 | public static function minNotFibonacci(mixed $input, null|string|Throwable $description = null): void; 60 | 61 | public static function minFinite(mixed $input, null|string|Throwable $description = null): void; 62 | 63 | public static function minNotFinite(mixed $input, null|string|Throwable $description = null): void; 64 | 65 | public static function minFloatType(mixed $input, null|string|Throwable $description = null): void; 66 | 67 | public static function minNotFloatType(mixed $input, null|string|Throwable $description = null): void; 68 | 69 | public static function minFloatVal(mixed $input, null|string|Throwable $description = null): void; 70 | 71 | public static function minNotFloatVal(mixed $input, null|string|Throwable $description = null): void; 72 | 73 | public static function minGreaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 74 | 75 | public static function minNotGreaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 76 | 77 | public static function minIdentical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 78 | 79 | public static function minNotIdentical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 80 | 81 | public static function minIn(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 82 | 83 | public static function minNotIn(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 84 | 85 | public static function minInfinite(mixed $input, null|string|Throwable $description = null): void; 86 | 87 | public static function minNotInfinite(mixed $input, null|string|Throwable $description = null): void; 88 | 89 | public static function minIntType(mixed $input, null|string|Throwable $description = null): void; 90 | 91 | public static function minNotIntType(mixed $input, null|string|Throwable $description = null): void; 92 | 93 | public static function minIntVal(mixed $input, null|string|Throwable $description = null): void; 94 | 95 | public static function minNotIntVal(mixed $input, null|string|Throwable $description = null): void; 96 | 97 | public static function minLeapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 98 | 99 | public static function minNotLeapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 100 | 101 | public static function minLeapYear(mixed $input, null|string|Throwable $description = null): void; 102 | 103 | public static function minNotLeapYear(mixed $input, null|string|Throwable $description = null): void; 104 | 105 | public static function minLessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 106 | 107 | public static function minNotLessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 108 | 109 | public static function minMaxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 110 | 111 | public static function minNotMaxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 112 | 113 | public static function minMinAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 114 | 115 | public static function minNotMinAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 116 | 117 | public static function minMultiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 118 | 119 | public static function minNotMultiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 120 | 121 | public static function minNegative(mixed $input, null|string|Throwable $description = null): void; 122 | 123 | public static function minNotNegative(mixed $input, null|string|Throwable $description = null): void; 124 | 125 | public static function minNumber(mixed $input, null|string|Throwable $description = null): void; 126 | 127 | public static function minNotNumber(mixed $input, null|string|Throwable $description = null): void; 128 | 129 | public static function minNumericVal(mixed $input, null|string|Throwable $description = null): void; 130 | 131 | public static function minNotNumericVal(mixed $input, null|string|Throwable $description = null): void; 132 | 133 | public static function minOdd(mixed $input, null|string|Throwable $description = null): void; 134 | 135 | public static function minNotOdd(mixed $input, null|string|Throwable $description = null): void; 136 | 137 | public static function minPerfectSquare(mixed $input, null|string|Throwable $description = null): void; 138 | 139 | public static function minNotPerfectSquare(mixed $input, null|string|Throwable $description = null): void; 140 | 141 | public static function minPositive(mixed $input, null|string|Throwable $description = null): void; 142 | 143 | public static function minNotPositive(mixed $input, null|string|Throwable $description = null): void; 144 | 145 | public static function minPrimeNumber(mixed $input, null|string|Throwable $description = null): void; 146 | 147 | public static function minNotPrimeNumber(mixed $input, null|string|Throwable $description = null): void; 148 | 149 | public static function minRoman(mixed $input, null|string|Throwable $description = null): void; 150 | 151 | public static function minNotRoman(mixed $input, null|string|Throwable $description = null): void; 152 | 153 | public static function minStringType(mixed $input, null|string|Throwable $description = null): void; 154 | 155 | public static function minNotStringType(mixed $input, null|string|Throwable $description = null): void; 156 | 157 | public static function minStringVal(mixed $input, null|string|Throwable $description = null): void; 158 | 159 | public static function minNotStringVal(mixed $input, null|string|Throwable $description = null): void; 160 | 161 | public static function minTime(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 162 | 163 | public static function minNotTime(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 164 | } 165 | -------------------------------------------------------------------------------- /src/Mixin/Static/Mixin.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Mixin\Static; 15 | 16 | use finfo; 17 | use Throwable; 18 | 19 | // phpcs:disable Generic.Files.LineLength.TooLong 20 | interface Mixin extends AllMixin, KeyMixin, LengthMixin, MaxMixin, MinMixin, NullOrMixin, PropertyMixin 21 | { 22 | public static function alnum(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 23 | 24 | public static function alpha(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 25 | 26 | public static function arrayType(mixed $input, null|string|Throwable $description = null): void; 27 | 28 | public static function arrayVal(mixed $input, null|string|Throwable $description = null): void; 29 | 30 | public static function base(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 31 | 32 | public static function base64(mixed $input, null|string|Throwable $description = null): void; 33 | 34 | public static function between(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 35 | 36 | public static function bic(mixed $input, string $countryCode, null|string|Throwable $description = null): void; 37 | 38 | public static function boolType(mixed $input, null|string|Throwable $description = null): void; 39 | 40 | public static function boolVal(mixed $input, null|string|Throwable $description = null): void; 41 | 42 | public static function bsn(mixed $input, null|string|Throwable $description = null): void; 43 | 44 | public static function callableType(mixed $input, null|string|Throwable $description = null): void; 45 | 46 | public static function callback(mixed $input, callable $callback, null|string|Throwable $description = null): void; 47 | 48 | public static function charset(mixed $input, string $charset = '', null|string|Throwable $description = null): void; 49 | 50 | public static function cnh(mixed $input, null|string|Throwable $description = null): void; 51 | 52 | public static function cnpj(mixed $input, null|string|Throwable $description = null): void; 53 | 54 | public static function control(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 55 | 56 | public static function consonant(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 57 | 58 | public static function contains(mixed $input, mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): void; 59 | 60 | /** 61 | * @param mixed[] $needles 62 | */ 63 | public static function containsAny(mixed $input, array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): void; 64 | 65 | public static function countable(mixed $input, null|string|Throwable $description = null): void; 66 | 67 | public static function countryCode(mixed $input, ?string $set = null, null|string|Throwable $description = null): void; 68 | 69 | public static function currencyCode(mixed $input, null|string|Throwable $description = null): void; 70 | 71 | public static function cpf(mixed $input, null|string|Throwable $description = null): void; 72 | 73 | public static function creditCard(mixed $input, ?string $brand = null, null|string|Throwable $description = null): void; 74 | 75 | public static function date(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 76 | 77 | public static function dateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 78 | 79 | public static function decimal(mixed $input, int $decimals, null|string|Throwable $description = null): void; 80 | 81 | public static function digit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 82 | 83 | public static function directory(mixed $input, null|string|Throwable $description = null): void; 84 | 85 | public static function domain(mixed $input, bool $tldCheck = true, null|string|Throwable $description = null): void; 86 | 87 | public static function email(mixed $input, null|string|Throwable $description = null): void; 88 | 89 | public static function endsWith(mixed $input, mixed $endValue, bool $identical = false, null|string|Throwable $description = null): void; 90 | 91 | public static function equals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 92 | 93 | public static function equivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 94 | 95 | public static function even(mixed $input, null|string|Throwable $description = null): void; 96 | 97 | public static function executable(mixed $input, null|string|Throwable $description = null): void; 98 | 99 | public static function exists(mixed $input, null|string|Throwable $description = null): void; 100 | 101 | public static function extension(mixed $input, string $extension, null|string|Throwable $description = null): void; 102 | 103 | public static function factor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 104 | 105 | public static function falseVal(mixed $input, null|string|Throwable $description = null): void; 106 | 107 | public static function fibonacci(mixed $input, null|string|Throwable $description = null): void; 108 | 109 | public static function file(mixed $input, null|string|Throwable $description = null): void; 110 | 111 | /** 112 | * @param mixed[]|int $options 113 | */ 114 | public static function filterVar(mixed $input, int $filter, array|int|null $options = null, null|string|Throwable $description = null): void; 115 | 116 | public static function finite(mixed $input, null|string|Throwable $description = null): void; 117 | 118 | public static function floatVal(mixed $input, null|string|Throwable $description = null): void; 119 | 120 | public static function floatType(mixed $input, null|string|Throwable $description = null): void; 121 | 122 | public static function graph(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 123 | 124 | public static function greaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 125 | 126 | public static function hexRgbColor(mixed $input, null|string|Throwable $description = null): void; 127 | 128 | public static function iban(mixed $input, null|string|Throwable $description = null): void; 129 | 130 | public static function identical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 131 | 132 | public static function image(mixed $input, ?finfo $fileInfo = null, null|string|Throwable $description = null): void; 133 | 134 | public static function imei(mixed $input, null|string|Throwable $description = null): void; 135 | 136 | public static function in(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 137 | 138 | public static function infinite(mixed $input, null|string|Throwable $description = null): void; 139 | 140 | public static function instance(mixed $input, string $instanceName, null|string|Throwable $description = null): void; 141 | 142 | public static function intVal(mixed $input, null|string|Throwable $description = null): void; 143 | 144 | public static function intType(mixed $input, null|string|Throwable $description = null): void; 145 | 146 | public static function ip(mixed $input, string $range = '*', ?int $options = null, null|string|Throwable $description = null): void; 147 | 148 | public static function isbn(mixed $input, null|string|Throwable $description = null): void; 149 | 150 | public static function iterableType(mixed $input, null|string|Throwable $description = null): void; 151 | 152 | public static function json(mixed $input, null|string|Throwable $description = null): void; 153 | 154 | public static function languageCode(mixed $input, ?string $set = null, null|string|Throwable $description = null): void; 155 | 156 | public static function leapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 157 | 158 | public static function leapYear(mixed $input, null|string|Throwable $description = null): void; 159 | 160 | public static function lowercase(mixed $input, null|string|Throwable $description = null): void; 161 | 162 | public static function lessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 163 | 164 | public static function luhn(mixed $input, null|string|Throwable $description = null): void; 165 | 166 | public static function macAddress(mixed $input, null|string|Throwable $description = null): void; 167 | 168 | public static function maxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 169 | 170 | public static function mimetype(mixed $input, string $mimetype, null|string|Throwable $description = null): void; 171 | 172 | public static function minAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 173 | 174 | public static function multiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 175 | 176 | public static function negative(mixed $input, null|string|Throwable $description = null): void; 177 | 178 | public static function nfeAccessKey(mixed $input, null|string|Throwable $description = null): void; 179 | 180 | public static function nif(mixed $input, null|string|Throwable $description = null): void; 181 | 182 | public static function nip(mixed $input, null|string|Throwable $description = null): void; 183 | 184 | public static function no(mixed $input, bool $useLocale = false, null|string|Throwable $description = null): void; 185 | 186 | public static function notBlank(mixed $input, null|string|Throwable $description = null): void; 187 | 188 | public static function notEmoji(mixed $input, null|string|Throwable $description = null): void; 189 | 190 | public static function notEmpty(mixed $input, null|string|Throwable $description = null): void; 191 | 192 | public static function notOptional(mixed $input, null|string|Throwable $description = null): void; 193 | 194 | public static function noWhitespace(mixed $input, null|string|Throwable $description = null): void; 195 | 196 | public static function nullType(mixed $input, null|string|Throwable $description = null): void; 197 | 198 | public static function number(mixed $input, null|string|Throwable $description = null): void; 199 | 200 | public static function numericVal(mixed $input, null|string|Throwable $description = null): void; 201 | 202 | public static function objectType(mixed $input, null|string|Throwable $description = null): void; 203 | 204 | public static function odd(mixed $input, null|string|Throwable $description = null): void; 205 | 206 | public static function perfectSquare(mixed $input, null|string|Throwable $description = null): void; 207 | 208 | public static function pesel(mixed $input, null|string|Throwable $description = null): void; 209 | 210 | public static function phone(mixed $input, null|string|Throwable $description = null): void; 211 | 212 | public static function phpLabel(mixed $input, null|string|Throwable $description = null): void; 213 | 214 | public static function pis(mixed $input, null|string|Throwable $description = null): void; 215 | 216 | public static function polishIdCard(mixed $input, null|string|Throwable $description = null): void; 217 | 218 | public static function positive(mixed $input, null|string|Throwable $description = null): void; 219 | 220 | public static function postalCode(mixed $input, string $countryCode, null|string|Throwable $description = null): void; 221 | 222 | public static function primeNumber(mixed $input, null|string|Throwable $description = null): void; 223 | 224 | public static function printable(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 225 | 226 | public static function punct(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 227 | 228 | public static function readable(mixed $input, null|string|Throwable $description = null): void; 229 | 230 | public static function regex(mixed $input, string $regex, null|string|Throwable $description = null): void; 231 | 232 | public static function resourceType(mixed $input, null|string|Throwable $description = null): void; 233 | 234 | public static function roman(mixed $input, null|string|Throwable $description = null): void; 235 | 236 | public static function scalarVal(mixed $input, null|string|Throwable $description = null): void; 237 | 238 | public static function size(mixed $input, ?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): void; 239 | 240 | public static function slug(mixed $input, null|string|Throwable $description = null): void; 241 | 242 | public static function sorted(mixed $input, string $direction, null|string|Throwable $description = null): void; 243 | 244 | public static function space(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 245 | 246 | public static function startsWith(mixed $input, mixed $startValue, bool $identical = false, null|string|Throwable $description = null): void; 247 | 248 | public static function stringType(mixed $input, null|string|Throwable $description = null): void; 249 | 250 | public static function stringVal(mixed $input, null|string|Throwable $description = null): void; 251 | 252 | public static function subdivisionCode(mixed $input, string $countryCode, null|string|Throwable $description = null): void; 253 | 254 | /** 255 | * @param mixed[] $superset 256 | */ 257 | public static function subset(mixed $input, array $superset, null|string|Throwable $description = null): void; 258 | 259 | public static function symbolicLink(mixed $input, null|string|Throwable $description = null): void; 260 | 261 | public static function time(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 262 | 263 | public static function tld(mixed $input, null|string|Throwable $description = null): void; 264 | 265 | public static function trueVal(mixed $input, null|string|Throwable $description = null): void; 266 | 267 | public static function type(mixed $input, string $type, null|string|Throwable $description = null): void; 268 | 269 | public static function unique(mixed $input, null|string|Throwable $description = null): void; 270 | 271 | public static function uploaded(mixed $input, null|string|Throwable $description = null): void; 272 | 273 | public static function uppercase(mixed $input, null|string|Throwable $description = null): void; 274 | 275 | public static function url(mixed $input, null|string|Throwable $description = null): void; 276 | 277 | public static function uuid(mixed $input, ?int $version = null, null|string|Throwable $description = null): void; 278 | 279 | public static function version(mixed $input, null|string|Throwable $description = null): void; 280 | 281 | public static function videoUrl(mixed $input, ?string $service = null, null|string|Throwable $description = null): void; 282 | 283 | public static function vowel(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 284 | 285 | public static function writable(mixed $input, null|string|Throwable $description = null): void; 286 | 287 | public static function xdigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 288 | 289 | public static function yes(mixed $input, bool $useLocale = false, null|string|Throwable $description = null): void; 290 | 291 | public static function notAlnum(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 292 | 293 | public static function notAlpha(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 294 | 295 | public static function notArrayType(mixed $input, null|string|Throwable $description = null): void; 296 | 297 | public static function notArrayVal(mixed $input, null|string|Throwable $description = null): void; 298 | 299 | public static function notBase(mixed $input, int $base, ?string $chars = null, null|string|Throwable $description = null): void; 300 | 301 | public static function notBase64(mixed $input, null|string|Throwable $description = null): void; 302 | 303 | public static function notBetween(mixed $input, mixed $minimum, mixed $maximum, null|string|Throwable $description = null): void; 304 | 305 | public static function notBic(mixed $input, string $countryCode, null|string|Throwable $description = null): void; 306 | 307 | public static function notBoolType(mixed $input, null|string|Throwable $description = null): void; 308 | 309 | public static function notBoolVal(mixed $input, null|string|Throwable $description = null): void; 310 | 311 | public static function notBsn(mixed $input, null|string|Throwable $description = null): void; 312 | 313 | public static function notCallableType(mixed $input, null|string|Throwable $description = null): void; 314 | 315 | public static function notCallback(mixed $input, callable $callback, null|string|Throwable $description = null): void; 316 | 317 | public static function notCharset(mixed $input, string $charset = '', null|string|Throwable $description = null): void; 318 | 319 | public static function notCnh(mixed $input, null|string|Throwable $description = null): void; 320 | 321 | public static function notCnpj(mixed $input, null|string|Throwable $description = null): void; 322 | 323 | public static function notControl(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 324 | 325 | public static function notConsonant(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 326 | 327 | public static function notContains(mixed $input, mixed $containsValue, bool $identical = false, null|string|Throwable $description = null): void; 328 | 329 | /** 330 | * @param mixed[] $needles 331 | */ 332 | public static function notContainsAny(mixed $input, array $needles, bool $strictCompareArray = false, null|string|Throwable $description = null): void; 333 | 334 | public static function notCountable(mixed $input, null|string|Throwable $description = null): void; 335 | 336 | public static function notCountryCode(mixed $input, ?string $set = null, null|string|Throwable $description = null): void; 337 | 338 | public static function notCurrencyCode(mixed $input, null|string|Throwable $description = null): void; 339 | 340 | public static function notCpf(mixed $input, null|string|Throwable $description = null): void; 341 | 342 | public static function notCreditCard(mixed $input, ?string $brand = null, null|string|Throwable $description = null): void; 343 | 344 | public static function notDate(mixed $input, string $format = 'Y-m-d', null|string|Throwable $description = null): void; 345 | 346 | public static function notDateTime(mixed $input, ?string $format = null, null|string|Throwable $description = null): void; 347 | 348 | public static function notDecimal(mixed $input, int $decimals, null|string|Throwable $description = null): void; 349 | 350 | public static function notDigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 351 | 352 | public static function notDirectory(mixed $input, null|string|Throwable $description = null): void; 353 | 354 | public static function notDomain(mixed $input, bool $tldCheck = true, null|string|Throwable $description = null): void; 355 | 356 | public static function notEmail(mixed $input, null|string|Throwable $description = null): void; 357 | 358 | public static function notEndsWith(mixed $input, mixed $endValue, bool $identical = false, null|string|Throwable $description = null): void; 359 | 360 | public static function notEquals(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 361 | 362 | public static function notEquivalent(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 363 | 364 | public static function notEven(mixed $input, null|string|Throwable $description = null): void; 365 | 366 | public static function notExecutable(mixed $input, null|string|Throwable $description = null): void; 367 | 368 | public static function notExists(mixed $input, null|string|Throwable $description = null): void; 369 | 370 | public static function notExtension(mixed $input, string $extension, null|string|Throwable $description = null): void; 371 | 372 | public static function notFactor(mixed $input, int $dividend, null|string|Throwable $description = null): void; 373 | 374 | public static function notFalseVal(mixed $input, null|string|Throwable $description = null): void; 375 | 376 | public static function notFibonacci(mixed $input, null|string|Throwable $description = null): void; 377 | 378 | public static function notFile(mixed $input, null|string|Throwable $description = null): void; 379 | 380 | /** 381 | * @param mixed[]|int $options 382 | */ 383 | public static function notFilterVar(mixed $input, int $filter, array|int|null $options = null, null|string|Throwable $description = null): void; 384 | 385 | public static function notFinite(mixed $input, null|string|Throwable $description = null): void; 386 | 387 | public static function notFloatVal(mixed $input, null|string|Throwable $description = null): void; 388 | 389 | public static function notFloatType(mixed $input, null|string|Throwable $description = null): void; 390 | 391 | public static function notGraph(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 392 | 393 | public static function notGreaterThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 394 | 395 | public static function notHexRgbColor(mixed $input, null|string|Throwable $description = null): void; 396 | 397 | public static function notIban(mixed $input, null|string|Throwable $description = null): void; 398 | 399 | public static function notIdentical(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 400 | 401 | public static function notImage(mixed $input, ?finfo $fileInfo = null, null|string|Throwable $description = null): void; 402 | 403 | public static function notImei(mixed $input, null|string|Throwable $description = null): void; 404 | 405 | public static function notIn(mixed $input, mixed $haystack, bool $compareIdentical = false, null|string|Throwable $description = null): void; 406 | 407 | public static function notInfinite(mixed $input, null|string|Throwable $description = null): void; 408 | 409 | public static function notInstance(mixed $input, string $instanceName, null|string|Throwable $description = null): void; 410 | 411 | public static function notIntVal(mixed $input, null|string|Throwable $description = null): void; 412 | 413 | public static function notIntType(mixed $input, null|string|Throwable $description = null): void; 414 | 415 | public static function notIp(mixed $input, string $range = '*', ?int $options = null, null|string|Throwable $description = null): void; 416 | 417 | public static function notIsbn(mixed $input, null|string|Throwable $description = null): void; 418 | 419 | public static function notIterableType(mixed $input, null|string|Throwable $description = null): void; 420 | 421 | public static function notJson(mixed $input, null|string|Throwable $description = null): void; 422 | 423 | public static function notLanguageCode(mixed $input, ?string $set = null, null|string|Throwable $description = null): void; 424 | 425 | public static function notLeapDate(mixed $input, string $format, null|string|Throwable $description = null): void; 426 | 427 | public static function notLeapYear(mixed $input, null|string|Throwable $description = null): void; 428 | 429 | public static function notLowercase(mixed $input, null|string|Throwable $description = null): void; 430 | 431 | public static function notLessThan(mixed $input, mixed $compareTo, null|string|Throwable $description = null): void; 432 | 433 | public static function notLuhn(mixed $input, null|string|Throwable $description = null): void; 434 | 435 | public static function notMacAddress(mixed $input, null|string|Throwable $description = null): void; 436 | 437 | public static function notMaxAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 438 | 439 | public static function notMimetype(mixed $input, string $mimetype, null|string|Throwable $description = null): void; 440 | 441 | public static function notMinAge(mixed $input, int $age, ?string $format = null, null|string|Throwable $description = null): void; 442 | 443 | public static function notMultiple(mixed $input, int $multipleOf, null|string|Throwable $description = null): void; 444 | 445 | public static function notNegative(mixed $input, null|string|Throwable $description = null): void; 446 | 447 | public static function notNfeAccessKey(mixed $input, null|string|Throwable $description = null): void; 448 | 449 | public static function notNif(mixed $input, null|string|Throwable $description = null): void; 450 | 451 | public static function notNip(mixed $input, null|string|Throwable $description = null): void; 452 | 453 | public static function notNo(mixed $input, bool $useLocale = false, null|string|Throwable $description = null): void; 454 | 455 | public static function notNoWhitespace(mixed $input, null|string|Throwable $description = null): void; 456 | 457 | public static function notNullType(mixed $input, null|string|Throwable $description = null): void; 458 | 459 | public static function notNumber(mixed $input, null|string|Throwable $description = null): void; 460 | 461 | public static function notNumericVal(mixed $input, null|string|Throwable $description = null): void; 462 | 463 | public static function notObjectType(mixed $input, null|string|Throwable $description = null): void; 464 | 465 | public static function notOdd(mixed $input, null|string|Throwable $description = null): void; 466 | 467 | public static function notPerfectSquare(mixed $input, null|string|Throwable $description = null): void; 468 | 469 | public static function notPesel(mixed $input, null|string|Throwable $description = null): void; 470 | 471 | public static function notPhone(mixed $input, null|string|Throwable $description = null): void; 472 | 473 | public static function notPhpLabel(mixed $input, null|string|Throwable $description = null): void; 474 | 475 | public static function notPis(mixed $input, null|string|Throwable $description = null): void; 476 | 477 | public static function notPolishIdCard(mixed $input, null|string|Throwable $description = null): void; 478 | 479 | public static function notPositive(mixed $input, null|string|Throwable $description = null): void; 480 | 481 | public static function notPostalCode(mixed $input, string $countryCode, null|string|Throwable $description = null): void; 482 | 483 | public static function notPrimeNumber(mixed $input, null|string|Throwable $description = null): void; 484 | 485 | public static function notPrintable(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 486 | 487 | public static function notPunct(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 488 | 489 | public static function notReadable(mixed $input, null|string|Throwable $description = null): void; 490 | 491 | public static function notRegex(mixed $input, string $regex, null|string|Throwable $description = null): void; 492 | 493 | public static function notResourceType(mixed $input, null|string|Throwable $description = null): void; 494 | 495 | public static function notRoman(mixed $input, null|string|Throwable $description = null): void; 496 | 497 | public static function notScalarVal(mixed $input, null|string|Throwable $description = null): void; 498 | 499 | public static function notSize(mixed $input, ?string $minSize = null, ?string $maxSize = null, null|string|Throwable $description = null): void; 500 | 501 | public static function notSlug(mixed $input, null|string|Throwable $description = null): void; 502 | 503 | public static function notSorted(mixed $input, string $direction, null|string|Throwable $description = null): void; 504 | 505 | public static function notSpace(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 506 | 507 | public static function notStartsWith(mixed $input, mixed $startValue, bool $identical = false, null|string|Throwable $description = null): void; 508 | 509 | public static function notStringType(mixed $input, null|string|Throwable $description = null): void; 510 | 511 | public static function notStringVal(mixed $input, null|string|Throwable $description = null): void; 512 | 513 | public static function notSubdivisionCode(mixed $input, string $countryCode, null|string|Throwable $description = null): void; 514 | 515 | /** 516 | * @param mixed[] $superset 517 | */ 518 | public static function notSubset(mixed $input, array $superset, null|string|Throwable $description = null): void; 519 | 520 | public static function notSymbolicLink(mixed $input, null|string|Throwable $description = null): void; 521 | 522 | public static function notTime(mixed $input, string $format = 'H:i:s', null|string|Throwable $description = null): void; 523 | 524 | public static function notTld(mixed $input, null|string|Throwable $description = null): void; 525 | 526 | public static function notTrueVal(mixed $input, null|string|Throwable $description = null): void; 527 | 528 | public static function notType(mixed $input, string $type, null|string|Throwable $description = null): void; 529 | 530 | public static function notUnique(mixed $input, null|string|Throwable $description = null): void; 531 | 532 | public static function notUploaded(mixed $input, null|string|Throwable $description = null): void; 533 | 534 | public static function notUppercase(mixed $input, null|string|Throwable $description = null): void; 535 | 536 | public static function notUrl(mixed $input, null|string|Throwable $description = null): void; 537 | 538 | public static function notUuid(mixed $input, ?int $version = null, null|string|Throwable $description = null): void; 539 | 540 | public static function notVersion(mixed $input, null|string|Throwable $description = null): void; 541 | 542 | public static function notVideoUrl(mixed $input, ?string $service = null, null|string|Throwable $description = null): void; 543 | 544 | public static function notVowel(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 545 | 546 | public static function notWritable(mixed $input, null|string|Throwable $description = null): void; 547 | 548 | public static function notXdigit(mixed $input, string $additionalChars = '', null|string|Throwable $description = null): void; 549 | 550 | public static function notYes(mixed $input, bool $useLocale = false, null|string|Throwable $description = null): void; 551 | } 552 | -------------------------------------------------------------------------------- /src/Rule/All.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Rule; 15 | 16 | use Respect\Validation\Exceptions\ValidationException; 17 | use Respect\Validation\Rules\Each; 18 | use Respect\Validation\Rules\IterableType; 19 | use Respect\Validation\Validatable; 20 | 21 | use function Respect\Stringifier\stringify; 22 | 23 | final class All extends Rule 24 | { 25 | public function __construct(Validatable $rule) 26 | { 27 | parent::__construct( 28 | new IterableType(), 29 | new Each($rule), 30 | ); 31 | } 32 | 33 | protected function getFilteredInput(mixed $input): mixed 34 | { 35 | return $input; 36 | } 37 | 38 | protected function getCustomizedException(ValidationException $exception): ValidationException 39 | { 40 | $params = $exception->getParams(); 41 | $params['name'] = stringify($params['input']) . ' (like all items of the input)'; 42 | $exception->updateParams($params); 43 | 44 | return $exception; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Rule/Envelope.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Rule; 15 | 16 | use Respect\Validation\Exceptions\ValidationException; 17 | use Respect\Validation\Rules\AbstractEnvelope; 18 | use Respect\Validation\Validatable; 19 | 20 | final class Envelope extends AbstractEnvelope 21 | { 22 | public function __construct(Validatable $validatable, string $template) 23 | { 24 | parent::__construct($validatable, []); 25 | $this->template = $template; 26 | } 27 | 28 | /** 29 | * {@inheritDoc} 30 | */ 31 | public function reportError($input, array $extraParameters = []): ValidationException 32 | { 33 | $exception = parent::reportError($input, $extraParameters); 34 | $exception->updateTemplate((string) $this->template); 35 | 36 | return $exception; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Rule/Length.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Rule; 15 | 16 | use Countable as PhpCountable; 17 | use Respect\Validation\Exceptions\ValidationException; 18 | use Respect\Validation\Rules\AnyOf; 19 | use Respect\Validation\Rules\Countable; 20 | use Respect\Validation\Rules\StringType; 21 | use Respect\Validation\Validatable; 22 | 23 | use function count; 24 | use function is_array; 25 | use function mb_strlen; 26 | 27 | final class Length extends Rule 28 | { 29 | public function __construct(Validatable $rule) 30 | { 31 | parent::__construct( 32 | new Envelope( 33 | new AnyOf(new StringType(), new Countable()), 34 | '{{input}} must be a string or a countable object' 35 | ), 36 | $rule 37 | ); 38 | } 39 | 40 | /** 41 | * @param array|PhpCountable|string $input 42 | */ 43 | protected function getFilteredInput(mixed $input): int 44 | { 45 | if (is_array($input)) { 46 | return count($input); 47 | } 48 | 49 | if ($input instanceof PhpCountable) { 50 | return $input->count(); 51 | } 52 | 53 | return mb_strlen($input); 54 | } 55 | 56 | protected function getCustomizedException(ValidationException $exception): ValidationException 57 | { 58 | $params = $exception->getParams(); 59 | $params['name'] = $params['input'] . ' (the length of the input)'; 60 | $exception->updateParams($params); 61 | 62 | return $exception; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Rule/Max.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Rule; 15 | 16 | use Respect\Validation\Exceptions\ValidationException; 17 | use Respect\Validation\Rules\AllOf; 18 | use Respect\Validation\Rules\AnyOf; 19 | use Respect\Validation\Rules\ArrayType; 20 | use Respect\Validation\Rules\Call; 21 | use Respect\Validation\Rules\GreaterThan; 22 | use Respect\Validation\Rules\IterableType; 23 | use Respect\Validation\Validatable; 24 | 25 | use function is_array; 26 | use function iterator_to_array; 27 | use function max; 28 | use function Respect\Stringifier\stringify; 29 | 30 | final class Max extends Rule 31 | { 32 | public function __construct(Validatable $rule) 33 | { 34 | parent::__construct( 35 | new Envelope( 36 | new AllOf( 37 | new AnyOf(new ArrayType(), new IterableType()), 38 | new Call('count', new GreaterThan(0)), 39 | ), 40 | '{{input}} must be an non-empty array or iterable', 41 | ), 42 | $rule, 43 | ); 44 | } 45 | 46 | /** 47 | * @param array|iterable $input 48 | */ 49 | protected function getFilteredInput(mixed $input): mixed 50 | { 51 | if (is_array($input)) { 52 | return max($input); 53 | } 54 | 55 | return $this->getFilteredInput(iterator_to_array($input)); 56 | } 57 | 58 | protected function getCustomizedException(ValidationException $exception): ValidationException 59 | { 60 | $params = $exception->getParams(); 61 | $params['name'] = stringify($params['input']) . ' (the maximum of the input)'; 62 | $exception->updateParams($params); 63 | 64 | return $exception; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Rule/Min.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Rule; 15 | 16 | use Respect\Validation\Exceptions\ValidationException; 17 | use Respect\Validation\Rules\AllOf; 18 | use Respect\Validation\Rules\AnyOf; 19 | use Respect\Validation\Rules\ArrayType; 20 | use Respect\Validation\Rules\Call; 21 | use Respect\Validation\Rules\GreaterThan; 22 | use Respect\Validation\Rules\IterableType; 23 | use Respect\Validation\Validatable; 24 | 25 | use function is_array; 26 | use function iterator_to_array; 27 | use function min; 28 | use function Respect\Stringifier\stringify; 29 | 30 | final class Min extends Rule 31 | { 32 | public function __construct(Validatable $rule) 33 | { 34 | parent::__construct( 35 | new Envelope( 36 | new AllOf( 37 | new AnyOf(new ArrayType(), new IterableType()), 38 | new Call('count', new GreaterThan(0)), 39 | ), 40 | '{{input}} must be an non-empty array or iterable', 41 | ), 42 | $rule, 43 | ); 44 | } 45 | 46 | /** 47 | * @param array|iterable $input 48 | */ 49 | protected function getFilteredInput(mixed $input): mixed 50 | { 51 | if (is_array($input)) { 52 | return min($input); 53 | } 54 | 55 | return $this->getFilteredInput(iterator_to_array($input)); 56 | } 57 | 58 | protected function getCustomizedException(ValidationException $exception): ValidationException 59 | { 60 | $params = $exception->getParams(); 61 | $params['name'] = stringify($params['input']) . ' (the minimum of the input)'; 62 | $exception->updateParams($params); 63 | 64 | return $exception; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Rule/Rule.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE file 9 | * that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Respect\Assertion\Rule; 15 | 16 | use Respect\Validation\Exceptions\ValidationException; 17 | use Respect\Validation\Rules\AbstractRule; 18 | use Respect\Validation\Validatable; 19 | 20 | abstract class Rule extends AbstractRule 21 | { 22 | abstract protected function getFilteredInput(mixed $input): mixed; 23 | 24 | abstract protected function getCustomizedException(ValidationException $exception): ValidationException; 25 | 26 | public function __construct( 27 | private readonly Validatable $preconditionRule, 28 | private readonly Validatable $rule, 29 | ) { 30 | } 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | public function validate($input): bool 36 | { 37 | return $this->preconditionRule->validate($input) && $this->rule->validate($this->getFilteredInput($input)); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | public function check($input): void 44 | { 45 | $this->preconditionRule->assert($input); 46 | 47 | try { 48 | $this->rule->check($this->getFilteredInput($input)); 49 | } catch (ValidationException $exception) { 50 | throw $this->getCustomizedException($exception); 51 | } 52 | } 53 | } 54 | --------------------------------------------------------------------------------