pax_global_header00006660000000000000000000000064137026264330014520gustar00rootroot0000000000000052 comment=af507bd2875078cab9065b304e94330699f2de34 php-webmozart-assert-1.9.1/000077500000000000000000000000001370262643300156265ustar00rootroot00000000000000php-webmozart-assert-1.9.1/.editorconfig000066400000000000000000000002361370262643300203040ustar00rootroot00000000000000root = true [*] charset=utf-8 end_of_line=lf trim_trailing_whitespace=true insert_final_newline=true indent_style=space indent_size=4 [*.yml] indent_size=2 php-webmozart-assert-1.9.1/.gitignore000066400000000000000000000000271370262643300176150ustar00rootroot00000000000000vendor/ /composer.lock php-webmozart-assert-1.9.1/.styleci.yml000066400000000000000000000002761370262643300201100ustar00rootroot00000000000000preset: symfony finder: exclude: - "tests" enabled: - ordered_use disabled: - phpdoc_annotation_without_dot # This is still buggy: https://github.com/symfony/symfony/pull/19198 php-webmozart-assert-1.9.1/.travis.yml000066400000000000000000000023331370262643300177400ustar00rootroot00000000000000language: php cache: directories: - $HOME/.composer/cache/files matrix: include: - php: 5.3 dist: precise - php: 5.4 dist: trusty - php: 5.5 dist: trusty - php: 5.6 - php: 7.0 - php: 7.1 - php: 7.2 - php: 7.3 env: - COVERAGE=yes - ANALYSIS=yes - php: 7.4 - php: hhvm-3.30 - php: nightly allow_failures: - php: nightly fast_finish: true before_install: - if [[ $COVERAGE != yes ]]; then phpenv config-rm xdebug.ini || true; fi; install: - if [[ $TRAVIS_PHP_VERSION = hhvm-3.30 ]]; then composer require phpunit/phpunit:4.8.36 --dev; fi - export COMPOSER_FLAGS="--prefer-dist --no-interaction" - if [[ $TRAVIS_PHP_VERSION = nightly ]]; then export COMPOSER_FLAGS="$COMOPSER_FLAGS --ignore-platform-reqs"; fi - composer update $COMPOSER_FLAGS script: - if [[ $COVERAGE = yes ]]; then vendor/bin/phpunit --coverage-clover=coverage.clover; else vendor/bin/phpunit; fi - if [[ $ANALYSIS = yes ]]; then composer i --working-dir=ci && ci/vendor/bin/psalm; fi after_script: - if [[ $COVERAGE = yes ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi php-webmozart-assert-1.9.1/CHANGELOG.md000066400000000000000000000120401370262643300174340ustar00rootroot00000000000000Changelog ========= ## UNRELEASED ## 1.9.1 ## Fixed * provisional support for PHP 8.0 ## 1.9.0 * added better Psalm support for `all*` & `nullOr*` methods * These methods are now understood by Psalm through a mixin. You may need a newer version of Psalm in order to use this * added `@psalm-pure` annotation to `Assert::notFalse()` * added more `@psalm-assert` annotations where appropriate ## Changed * the `all*` & `nullOr*` methods are now declared on an interface, instead of `@method` annotations. This interface is linked to the `Assert` class with a `@mixin` annotation. Most IDE's have supported this for a long time, and you should not lose any autocompletion capabilities. PHPStan has supported this since version `0.12.20`. This package is marked incompatible (with a composer conflict) with phpstan version prior to that. If you do not use PHPStan than this does not matter. ## 1.8.0 ### Added * added `Assert::notStartsWith()` * added `Assert::notEndsWith()` * added `Assert::inArray()` * added `@psalm-pure` annotations to pure assertions ### Fixed * Exception messages of comparisons between `DateTime(Immutable)` objects now display their date & time. * Custom Exception messages for `Assert::count()` now use the values to render the exception message. ## 1.7.0 (2020-02-14) ### Added * added `Assert::notFalse()` * added `Assert::isAOf()` * added `Assert::isAnyOf()` * added `Assert::isNotA()` ## 1.6.0 (2019-11-24) ### Added * added `Assert::validArrayKey()` * added `Assert::isNonEmptyList()` * added `Assert::isNonEmptyMap()` * added `@throws InvalidArgumentException` annotations to all methods that throw. * added `@psalm-assert` for the list type to the `isList` assertion. ### Fixed * `ResourceBundle` & `SimpleXMLElement` now pass the `isCountable` assertions. They are countable, without implementing the `Countable` interface. * The doc block of `range` now has the proper variables. * An empty array will now pass `isList` and `isMap`. As it is a valid form of both. If a non-empty variant is needed, use `isNonEmptyList` or `isNonEmptyMap`. ### Changed * Removed some `@psalm-assert` annotations, that were 'side effect' assertions See: * [#144](https://github.com/webmozart/assert/pull/144) * [#145](https://github.com/webmozart/assert/issues/145) * [#146](https://github.com/webmozart/assert/pull/146) * [#150](https://github.com/webmozart/assert/pull/150) * If you use Psalm, the minimum version needed is `3.6.0`. Which is enforced through a composer conflict. If you don't use Psalm, then this has no impact. ## 1.5.0 (2019-08-24) ### Added * added `Assert::uniqueValues()` * added `Assert::unicodeLetters()` * added: `Assert::email()` * added support for [Psalm](https://github.com/vimeo/psalm), by adding `@psalm-assert` annotations where appropriate. ### Fixed * `Assert::endsWith()` would not give the correct result when dealing with a multibyte suffix. * `Assert::length(), minLength, maxLength, lengthBetween` would not give the correct result when dealing with multibyte characters. **NOTE**: These 2 changes may break your assertions if you relied on the fact that multibyte characters didn't behave correctly. ### Changed * The names of some variables have been updated to better reflect what they are. * All function calls are now in their FQN form, slightly increasing performance. * Tests are now properly ran against HHVM-3.30 and PHP nightly. ### Deprecation * deprecated `Assert::isTraversable()` in favor of `Assert::isIterable()` * This was already done in 1.3.0, but it was only done through a silenced `trigger_error`. It is now annotated as well. ## 1.4.0 (2018-12-25) ### Added * added `Assert::ip()` * added `Assert::ipv4()` * added `Assert::ipv6()` * added `Assert::notRegex()` * added `Assert::interfaceExists()` * added `Assert::isList()` * added `Assert::isMap()` * added polyfill for ctype ### Fixed * Special case when comparing objects implementing `__toString()` ## 1.3.0 (2018-01-29) ### Added * added `Assert::minCount()` * added `Assert::maxCount()` * added `Assert::countBetween()` * added `Assert::isCountable()` * added `Assert::notWhitespaceOnly()` * added `Assert::natural()` * added `Assert::notContains()` * added `Assert::isArrayAccessible()` * added `Assert::isInstanceOfAny()` * added `Assert::isIterable()` ### Fixed * `stringNotEmpty` will no longer report "0" is an empty string ### Deprecation * deprecated `Assert::isTraversable()` in favor of `Assert::isIterable()` ## 1.2.0 (2016-11-23) * added `Assert::throws()` * added `Assert::count()` * added extension point `Assert::reportInvalidArgument()` for custom subclasses ## 1.1.0 (2016-08-09) * added `Assert::object()` * added `Assert::propertyExists()` * added `Assert::propertyNotExists()` * added `Assert::methodExists()` * added `Assert::methodNotExists()` * added `Assert::uuid()` ## 1.0.2 (2015-08-24) * integrated Style CI * add tests for minimum package dependencies on Travis CI ## 1.0.1 (2015-05-12) * added support for PHP 5.3.3 ## 1.0.0 (2015-05-12) * first stable release ## 1.0.0-beta (2015-03-19) * first beta release php-webmozart-assert-1.9.1/LICENSE000066400000000000000000000020741370262643300166360ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Bernhard Schussek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. php-webmozart-assert-1.9.1/README.md000066400000000000000000000372731370262643300171210ustar00rootroot00000000000000Webmozart Assert ================ [![Build Status](https://travis-ci.org/webmozart/assert.svg?branch=master)](https://travis-ci.org/webmozart/assert) [![Build status](https://ci.appveyor.com/api/projects/status/lyg83bcsisrr94se/branch/master?svg=true)](https://ci.appveyor.com/project/webmozart/assert/branch/master) [![Code Coverage](https://scrutinizer-ci.com/g/webmozart/assert/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/webmozart/assert/?branch=master) [![Latest Stable Version](https://poser.pugx.org/webmozart/assert/v/stable.svg)](https://packagist.org/packages/webmozart/assert) [![Total Downloads](https://poser.pugx.org/webmozart/assert/downloads.svg)](https://packagist.org/packages/webmozart/assert) This library contains efficient assertions to test the input and output of your methods. With these assertions, you can greatly reduce the amount of coding needed to write a safe implementation. All assertions in the [`Assert`] class throw an `\InvalidArgumentException` if they fail. FAQ --- **What's the difference to [beberlei/assert]?** This library is heavily inspired by Benjamin Eberlei's wonderful [assert package], but fixes a usability issue with error messages that can't be fixed there without breaking backwards compatibility. This package features usable error messages by default. However, you can also easily write custom error messages: ``` Assert::string($path, 'The path is expected to be a string. Got: %s'); ``` In [beberlei/assert], the ordering of the `%s` placeholders is different for every assertion. This package, on the contrary, provides consistent placeholder ordering for all assertions: * `%s`: The tested value as string, e.g. `"/foo/bar"`. * `%2$s`, `%3$s`, ...: Additional assertion-specific values, e.g. the minimum/maximum length, allowed values, etc. Check the source code of the assertions to find out details about the additional available placeholders. Installation ------------ Use [Composer] to install the package: ``` $ composer require webmozart/assert ``` Example ------- ```php use Webmozart\Assert\Assert; class Employee { public function __construct($id) { Assert::integer($id, 'The employee ID must be an integer. Got: %s'); Assert::greaterThan($id, 0, 'The employee ID must be a positive integer. Got: %s'); } } ``` If you create an employee with an invalid ID, an exception is thrown: ```php new Employee('foobar'); // => InvalidArgumentException: // The employee ID must be an integer. Got: string new Employee(-10); // => InvalidArgumentException: // The employee ID must be a positive integer. Got: -10 ``` Assertions ---------- The [`Assert`] class provides the following assertions: ### Type Assertions Method | Description -------------------------------------------------------- | -------------------------------------------------- `string($value, $message = '')` | Check that a value is a string `stringNotEmpty($value, $message = '')` | Check that a value is a non-empty string `integer($value, $message = '')` | Check that a value is an integer `integerish($value, $message = '')` | Check that a value casts to an integer `float($value, $message = '')` | Check that a value is a float `numeric($value, $message = '')` | Check that a value is numeric `natural($value, $message= ''')` | Check that a value is a non-negative integer `boolean($value, $message = '')` | Check that a value is a boolean `scalar($value, $message = '')` | Check that a value is a scalar `object($value, $message = '')` | Check that a value is an object `resource($value, $type = null, $message = '')` | Check that a value is a resource `isCallable($value, $message = '')` | Check that a value is a callable `isArray($value, $message = '')` | Check that a value is an array `isTraversable($value, $message = '')` (deprecated) | Check that a value is an array or a `\Traversable` `isIterable($value, $message = '')` | Check that a value is an array or a `\Traversable` `isCountable($value, $message = '')` | Check that a value is an array or a `\Countable` `isInstanceOf($value, $class, $message = '')` | Check that a value is an `instanceof` a class `isInstanceOfAny($value, array $classes, $message = '')` | Check that a value is an `instanceof` at least one class on the array of classes `notInstanceOf($value, $class, $message = '')` | Check that a value is not an `instanceof` a class `isAOf($value, $class, $message = '')` | Check that a value is of the class or has one of its parents `isAnyOf($value, array $classes, $message = '')` | Check that a value is of at least one of the classes or has one of its parents `isNotA($value, $class, $message = '')` | Check that a value is not of the class or has not one of its parents `isArrayAccessible($value, $message = '')` | Check that a value can be accessed as an array `uniqueValues($values, $message = '')` | Check that the given array contains unique values ### Comparison Assertions Method | Description ----------------------------------------------- | ------------------------------------------------------------------ `true($value, $message = '')` | Check that a value is `true` `false($value, $message = '')` | Check that a value is `false` `notFalse($value, $message = '')` | Check that a value is not `false` `null($value, $message = '')` | Check that a value is `null` `notNull($value, $message = '')` | Check that a value is not `null` `isEmpty($value, $message = '')` | Check that a value is `empty()` `notEmpty($value, $message = '')` | Check that a value is not `empty()` `eq($value, $value2, $message = '')` | Check that a value equals another (`==`) `notEq($value, $value2, $message = '')` | Check that a value does not equal another (`!=`) `same($value, $value2, $message = '')` | Check that a value is identical to another (`===`) `notSame($value, $value2, $message = '')` | Check that a value is not identical to another (`!==`) `greaterThan($value, $value2, $message = '')` | Check that a value is greater than another `greaterThanEq($value, $value2, $message = '')` | Check that a value is greater than or equal to another `lessThan($value, $value2, $message = '')` | Check that a value is less than another `lessThanEq($value, $value2, $message = '')` | Check that a value is less than or equal to another `range($value, $min, $max, $message = '')` | Check that a value is within a range `inArray($value, array $values, $message = '')` | Check that a value is one of a list of values `oneOf($value, array $values, $message = '')` | Check that a value is one of a list of values (alias of `inArray`) ### String Assertions You should check that a value is a string with `Assert::string()` before making any of the following assertions. Method | Description --------------------------------------------------- | ----------------------------------------------------------------- `contains($value, $subString, $message = '')` | Check that a string contains a substring `notContains($value, $subString, $message = '')` | Check that a string does not contain a substring `startsWith($value, $prefix, $message = '')` | Check that a string has a prefix `notStartsWith($value, $prefix, $message = '')` | Check that a string does not have a prefix `startsWithLetter($value, $message = '')` | Check that a string starts with a letter `endsWith($value, $suffix, $message = '')` | Check that a string has a suffix `notEndsWith($value, $suffix, $message = '')` | Check that a string does not have a suffix `regex($value, $pattern, $message = '')` | Check that a string matches a regular expression `notRegex($value, $pattern, $message = '')` | Check that a string does not match a regular expression `unicodeLetters($value, $message = '')` | Check that a string contains Unicode letters only `alpha($value, $message = '')` | Check that a string contains letters only `digits($value, $message = '')` | Check that a string contains digits only `alnum($value, $message = '')` | Check that a string contains letters and digits only `lower($value, $message = '')` | Check that a string contains lowercase characters only `upper($value, $message = '')` | Check that a string contains uppercase characters only `length($value, $length, $message = '')` | Check that a string has a certain number of characters `minLength($value, $min, $message = '')` | Check that a string has at least a certain number of characters `maxLength($value, $max, $message = '')` | Check that a string has at most a certain number of characters `lengthBetween($value, $min, $max, $message = '')` | Check that a string has a length in the given range `uuid($value, $message = '')` | Check that a string is a valid UUID `ip($value, $message = '')` | Check that a string is a valid IP (either IPv4 or IPv6) `ipv4($value, $message = '')` | Check that a string is a valid IPv4 `ipv6($value, $message = '')` | Check that a string is a valid IPv6 `email($value, $message = '')` | Check that a string is a valid e-mail address `notWhitespaceOnly($value, $message = '')` | Check that a string contains at least one non-whitespace character ### File Assertions Method | Description ----------------------------------- | -------------------------------------------------- `fileExists($value, $message = '')` | Check that a value is an existing path `file($value, $message = '')` | Check that a value is an existing file `directory($value, $message = '')` | Check that a value is an existing directory `readable($value, $message = '')` | Check that a value is a readable path `writable($value, $message = '')` | Check that a value is a writable path ### Object Assertions Method | Description ----------------------------------------------------- | -------------------------------------------------- `classExists($value, $message = '')` | Check that a value is an existing class name `subclassOf($value, $class, $message = '')` | Check that a class is a subclass of another `interfaceExists($value, $message = '')` | Check that a value is an existing interface name `implementsInterface($value, $class, $message = '')` | Check that a class implements an interface `propertyExists($value, $property, $message = '')` | Check that a property exists in a class/object `propertyNotExists($value, $property, $message = '')` | Check that a property does not exist in a class/object `methodExists($value, $method, $message = '')` | Check that a method exists in a class/object `methodNotExists($value, $method, $message = '')` | Check that a method does not exist in a class/object ### Array Assertions Method | Description -------------------------------------------------- | ------------------------------------------------------------------ `keyExists($array, $key, $message = '')` | Check that a key exists in an array `keyNotExists($array, $key, $message = '')` | Check that a key does not exist in an array `validArrayKey($key, $message = '')` | Check that a value is a valid array key (int or string) `count($array, $number, $message = '')` | Check that an array contains a specific number of elements `minCount($array, $min, $message = '')` | Check that an array contains at least a certain number of elements `maxCount($array, $max, $message = '')` | Check that an array contains at most a certain number of elements `countBetween($array, $min, $max, $message = '')` | Check that an array has a count in the given range `isList($array, $message = '')` | Check that an array is a non-associative list `isNonEmptyList($array, $message = '')` | Check that an array is a non-associative list, and not empty `isMap($array, $message = '')` | Check that an array is associative and has strings as keys `isNonEmptyMap($array, $message = '')` | Check that an array is associative and has strings as keys, and is not empty ### Function Assertions Method | Description ------------------------------------------- | ----------------------------------------------------------------------------------------------------- `throws($closure, $class, $message = '')` | Check that a function throws a certain exception. Subclasses of the exception class will be accepted. ### Collection Assertions All of the above assertions can be prefixed with `all*()` to test the contents of an array or a `\Traversable`: ```php Assert::allIsInstanceOf($employees, 'Acme\Employee'); ``` ### Nullable Assertions All of the above assertions can be prefixed with `nullOr*()` to run the assertion only if it the value is not `null`: ```php Assert::nullOrString($middleName, 'The middle name must be a string or null. Got: %s'); ``` ### Extending Assert The `Assert` class comes with a few methods, which can be overridden to change the class behaviour. You can also extend it to add your own assertions. #### Overriding methods Overriding the following methods in your assertion class allows you to change the behaviour of the assertions: * `public static function __callStatic($name, $arguments)` * This method is used to 'create' the `nullOr` and `all` versions of the assertions. * `protected static function valueToString($value)` * This method is used for error messages, to convert the value to a string value for displaying. You could use this for representing a value object with a `__toString` method for example. * `protected static function typeToString($value)` * This method is used for error messages, to convert the a value to a string representing its type. * `protected static function strlen($value)` * This method is used to calculate string length for relevant methods, using the `mb_strlen` if available and useful. * `protected static function reportInvalidArgument($message)` * This method is called when an assertion fails, with the specified error message. Here you can throw your own exception, or log something. Authors ------- * [Bernhard Schussek] a.k.a. [@webmozart] * [The Community Contributors] Contribute ---------- Contributions to the package are always welcome! * Report any bugs or issues you find on the [issue tracker]. * You can grab the source code at the package's [Git repository]. License ------- All contents of this package are licensed under the [MIT license]. [beberlei/assert]: https://github.com/beberlei/assert [assert package]: https://github.com/beberlei/assert [Composer]: https://getcomposer.org [Bernhard Schussek]: https://webmozarts.com [The Community Contributors]: https://github.com/webmozart/assert/graphs/contributors [issue tracker]: https://github.com/webmozart/assert/issues [Git repository]: https://github.com/webmozart/assert [@webmozart]: https://twitter.com/webmozart [MIT license]: LICENSE [`Assert`]: src/Assert.php php-webmozart-assert-1.9.1/appveyor.yml000066400000000000000000000014441370262643300202210ustar00rootroot00000000000000build: false platform: x86 clone_folder: c:\projects\webmozart\assert branches: only: - master init: - SET PATH=c:\php;%PATH% - SET COMPOSER_NO_INTERACTION=1 - SET PHP=1 cache: - '%LOCALAPPDATA%\Composer\files' install: - ps: Set-Service wuauserv -StartupType Manual - cinst -y php composer - refreshenv - cd c:\tools\php74 - copy php.ini-production php.ini /Y - echo date.timezone="UTC" >> php.ini - echo extension_dir=ext >> php.ini - echo extension=php_openssl.dll >> php.ini - echo extension=php_mbstring.dll >> php.ini - echo extension=php_curl.dll >> php.ini - echo memory_limit=3G >> php.ini - cd %APPVEYOR_BUILD_FOLDER% - composer install --no-interaction --no-progress test_script: - cd %APPVEYOR_BUILD_FOLDER% - vendor\bin\phpunit.bat --verbose php-webmozart-assert-1.9.1/bin/000077500000000000000000000000001370262643300163765ustar00rootroot00000000000000php-webmozart-assert-1.9.1/bin/generate.php000066400000000000000000000005531370262643300207040ustar00rootroot00000000000000generate()); php-webmozart-assert-1.9.1/bin/src/000077500000000000000000000000001370262643300171655ustar00rootroot00000000000000php-webmozart-assert-1.9.1/bin/src/MixinGenerator.php000066400000000000000000000332171370262643300226370ustar00rootroot00000000000000 * * @var string[] */ private $unsupportedMethods = [ 'nullOrNotInstanceOf', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allNotInstanceOf', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'nullOrNotEmpty', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allNotEmpty', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allNotNull', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'nullOrIsNotA', // not supported by psalm (https://github.com/vimeo/psalm/issues/3444) 'allIsNotA', // not supported by psalm (https://github.com/vimeo/psalm/issues/3444) 'nullOrNotFalse', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allNotFalse', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'nullOrUpper', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allUpper', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'nullOrIsNonEmptyMap', // not supported by psalm (https://github.com/vimeo/psalm/issues/3444) 'allIsNonEmptyMap', // not supported by psalm (https://github.com/vimeo/psalm/issues/3444) ]; /** * @psalm-var list * * @var string[] */ private $skipMethods = [ 'nullOrNull', // meaningless 'nullOrNotNull', // meaningless ]; public function generate(): string { $file = "fileComment()."\n\n"; $file .= $this->namespace()."\n"; return $file; } private function fileComment(): string { return $this->phpdoc(['provides type inference and auto-completion for magic static methods of Assert.'], 0); } private function namespace(): string { $assert = new ReflectionClass(Assert::class); $namespace = sprintf("namespace %s;\n\n", $assert->getNamespaceName()); $namespace .= sprintf("use %s;\n", ArrayAccess::class); $namespace .= sprintf("use %s;\n", Closure::class); $namespace .= sprintf("use %s;\n", Countable::class); $namespace .= sprintf("use %s;\n", InvalidArgumentException::class); $namespace .= sprintf("use %s;\n", Throwable::class); $namespace .= "\n"; $namespace .= $this->interface($assert); return $namespace; } private function interface(ReflectionClass $assert): string { $staticMethods = $this->getMethods($assert); $phpdocMethods = []; $declaredMethods = []; foreach ($staticMethods as $method) { $nullOr = $this->nullOr($method, 4); if (null !== $nullOr) { $declaredMethods[] = $nullOr; } $all = $this->all($method, 4); if (null !== $all) { $declaredMethods[] = $all; } } $interface = ''; if (count($phpdocMethods) > 0) { $interface = $this->phpdoc($phpdocMethods, 0)."\n"; } $interface .= "interface Mixin\n{\n"; $interface .= implode("\n\n", $declaredMethods); $interface .= "\n}"; return $interface; } /** * @param ReflectionMethod $method * @param int $indent * * @return string|null * * @throws ReflectionException */ private function nullOr(ReflectionMethod $method, int $indent): ?string { return $this->assertion($method, 'nullOr%s', 'null|%s', $indent); } /** * @param ReflectionMethod $method * @param int $indent * * @return string|null * * @throws ReflectionException */ private function all(ReflectionMethod $method, int $indent): ?string { return $this->assertion($method, 'all%s', 'iterable<%s>', $indent); } /** * @param ReflectionMethod $method * @param string $methodNameTemplate * @param string $typeTemplate * @param int $indent * * @return string|null * * @throws ReflectionException */ private function assertion(ReflectionMethod $method, string $methodNameTemplate, string $typeTemplate, int $indent): ?string { $newMethodName = sprintf($methodNameTemplate, ucfirst($method->name)); $comment = $method->getDocComment(); $parsedComment = $this->parseDocComment($comment); $parameters = []; /** @psalm-var array $parametersDefaults */ $parametersDefaults = []; $parametersReflection = $method->getParameters(); foreach ($parametersReflection as $parameterReflection) { $parameters[] = $parameterReflection->name; if ($parameterReflection->isDefaultValueAvailable()) { /** @var mixed $defaultValue */ $defaultValue = $parameterReflection->getDefaultValue(); Assert::nullOrScalar($defaultValue); $parametersDefaults[$parameterReflection->name] = $defaultValue; } } if (in_array($newMethodName, $this->skipMethods, true)) { return null; } $paramsAdded = false; $phpdocLines = []; foreach ($parsedComment as $key => $values) { if ($this->shouldSkipAnnotation($newMethodName, $key)) { continue; } if ($paramsAdded || 'param' === $key) { $paramsAdded = true; if (count($phpdocLines) > 0) { $phpdocLines[] = ''; } } if ('deprecated' === $key) { $phpdocLines[] = ''; } $longestType = 0; $longestName = 0; foreach ($values as $i => $value) { $parts = $this->splitDocLine($value); if (('param' === $key || 'psalm-param' === $key) && isset($parts[1]) && $parts[1] === '$'.$parameters[0] && 'mixed' !== $parts[0]) { $parts[0] = $this->applyTypeTemplate($parts[0], $typeTemplate); $values[$i] = implode(' ', $parts); } } if ('param' === $key) { [$longestType, $longestName] = $this->findLongestTypeAndName($values); } foreach ($values as $value) { $parts = $this->splitDocLine($value); $type = $parts[0]; if ('psalm-assert' === $key) { $type = $this->applyTypeTemplate($type, $typeTemplate); } if ('param' === $key) { if (!array_key_exists(1, $parts)) { throw new RuntimeException(sprintf('param key must come with type and variable name in method: %s', $method->name)); } $type = str_pad($type, $longestType, ' '); $parts[1] = str_pad($parts[1], $longestName, ' '); } $comment = sprintf('@%s %s', $key, $type); if (count($parts) >= 2) { $comment .= sprintf(' %s', implode(' ', array_slice($parts, 1))); } $phpdocLines[] = trim($comment); } if ('deprecated' === $key) { $phpdocLines[] = ''; } } $phpdocLinesDeduplicatedEmptyLines = []; foreach ($phpdocLines as $line) { $currentLine = trim($line); if ('' === $currentLine && count($phpdocLinesDeduplicatedEmptyLines) > 0) { $previousLine = trim($phpdocLinesDeduplicatedEmptyLines[count($phpdocLinesDeduplicatedEmptyLines) - 1]); if ('' === $previousLine) { continue; } } $phpdocLinesDeduplicatedEmptyLines[] = $line; } return $this->staticMethod($newMethodName, $parameters, $parametersDefaults, $phpdocLinesDeduplicatedEmptyLines, $indent); } private function applyTypeTemplate(string $type, string $typeTemplate): string { $combinedType = sprintf($typeTemplate, $type); if ('null|empty' === $combinedType) { $combinedType = 'empty'; // @see https://github.com/vimeo/psalm/issues/3492 } return $combinedType; } private function shouldSkipAnnotation(string $newMethodName, string $key): bool { if (!in_array($newMethodName, $this->unsupportedMethods, true)) { return false; } return 'psalm-assert' === $key; } /** * @psalm-param array $values * @psalm-return array{int, int} * * @param string[] $values * * @return int[] */ private function findLongestTypeAndName(array $values): array { $longestType = 0; $longestName = 0; foreach ($values as $value) { $parts = $this->splitDocLine($value); $type = $parts[0]; if (strlen($type) > $longestType) { $longestType = strlen($type); } if (!array_key_exists(1, $parts)) { continue; } $name = $parts[1]; if (strlen($name) > $longestName) { $longestName = strlen($name); } } return [$longestType, $longestName]; } /** * @psalm-param list $parameters * @psalm-param array $defaultValues * @psalm-param list $phpdocLines * * @param string $name * @param string[] $parameters * @param string[] $defaultValues * @param array $phpdocLines * @param int $indent * * @return string */ private function staticMethod(string $name, array $parameters, array $defaultValues, array $phpdocLines, int $indent): string { $indentation = str_repeat(' ', $indent); $staticFunction = $this->phpdoc($phpdocLines, $indent)."\n"; $staticFunction .= $indentation.'public static function '.$name.$this->functionParameters($parameters, $defaultValues).';'; return $staticFunction; } /** * @psalm-param list $parameters * @psalm-param array $defaultValues * * @param string[] $parameters * @param string[] $defaultValues * * @return string */ private function functionParameters(array $parameters, array $defaultValues): string { $result = ''; foreach ($parameters as $i => $parameter) { if ($i > 0) { $result .= ', '; } $result .= '$'.$parameter; if (array_key_exists($parameter, $defaultValues)) { $defaultValue = null === $defaultValues[$parameter] ? 'null' : var_export($defaultValues[$parameter], true); $result .= ' = '.$defaultValue; } } return '('.$result.')'; } /** * @psalm-param list $lines * * @param string[] $lines * @param int $indent * * @return string */ private function phpdoc(array $lines, int $indent): string { $indentation = str_repeat(' ', $indent); $phpdoc = $indentation.'/**'; foreach ($lines as $line) { $phpdoc .= "\n".$indentation.rtrim(' * '.$line); } $phpdoc .= "\n".$indentation.' */'; return $phpdoc; } /** * @psalm-return array> * * @param string $comment * * @return string[][] */ private function parseDocComment(string $comment): array { $lines = explode("\n", $comment); $result = []; foreach ($lines as $line) { if (preg_match('~^\*\s+@(\S+)(\s+.*)?$~', trim($line), $matches)) { if (2 === count($matches)) { $matches[2] = ''; } $result[$matches[1]][] = trim($matches[2]); } } return $result; } /** * @psalm-return array{0: string, 1?: string, 2?: string} * * @param string $line * * @return string[] */ private function splitDocLine(string $line): array { if (!preg_match('~^(.*)\s+(\$\S+)(?:\s+(.*))?$~', $line, $matches)) { return [$line]; } $parts = [trim($matches[1]), $matches[2]]; if (count($matches) > 3) { $parts[2] = $matches[3]; } return $parts; } /** * @psalm-return list * * @param ReflectionClass $assert * * @return ReflectionMethod[] */ private function getMethods(ReflectionClass $assert): array { $methods = []; $staticMethods = $assert->getMethods(ReflectionMethod::IS_STATIC); foreach ($staticMethods as $staticMethod) { $modifiers = $staticMethod->getModifiers(); if (0 === ($modifiers & ReflectionMethod::IS_PUBLIC)) { continue; } if ('__callStatic' === $staticMethod->name) { continue; } $methods[] = $staticMethod; } return $methods; } } php-webmozart-assert-1.9.1/ci/000077500000000000000000000000001370262643300162215ustar00rootroot00000000000000php-webmozart-assert-1.9.1/ci/composer.json000066400000000000000000000001071370262643300207410ustar00rootroot00000000000000{ "require": { "vimeo/psalm": "dev-master#61f5a06" } } php-webmozart-assert-1.9.1/ci/composer.lock000066400000000000000000001367771370262643300207470ustar00rootroot00000000000000{ "_readme": [ "This file locks the dependencies of your project to a known state", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], "content-hash": "6af99c65c31c3822c999098ce8a15ade", "packages": [ { "name": "amphp/amp", "version": "v2.4.3", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", "reference": "23ac95fc6d6973231763f5ed7d1309b39429b974" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/amphp/amp/zipball/23ac95fc6d6973231763f5ed7d1309b39429b974", "reference": "23ac95fc6d6973231763f5ed7d1309b39429b974", "shasum": "" }, "require": { "php": ">=7" }, "require-dev": { "amphp/php-cs-fixer-config": "dev-master", "amphp/phpunit-util": "^1", "ext-json": "*", "jetbrains/phpstorm-stubs": "^2019.3", "phpunit/phpunit": "^6.0.9 | ^7", "react/promise": "^2", "vimeo/psalm": "^3.11@dev" }, "type": "library", "extra": { "branch-alias": { "dev-master": "2.x-dev" } }, "autoload": { "psr-4": { "Amp\\": "lib" }, "files": [ "lib/functions.php", "lib/Internal/functions.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Daniel Lowrey", "email": "rdlowrey@php.net" }, { "name": "Aaron Piotrowski", "email": "aaron@trowski.com" }, { "name": "Bob Weinand", "email": "bobwei9@hotmail.com" }, { "name": "Niklas Keller", "email": "me@kelunik.com" } ], "description": "A non-blocking concurrency framework for PHP applications.", "homepage": "http://amphp.org/amp", "keywords": [ "async", "asynchronous", "awaitable", "concurrency", "event", "event-loop", "future", "non-blocking", "promise" ], "time": "2020-04-19T15:54:21+00:00" }, { "name": "amphp/byte-stream", "version": "v1.7.3", "source": { "type": "git", "url": "https://github.com/amphp/byte-stream.git", "reference": "b867505edb79dda8f253ca3c3a2bbadae4b16592" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/amphp/byte-stream/zipball/b867505edb79dda8f253ca3c3a2bbadae4b16592", "reference": "b867505edb79dda8f253ca3c3a2bbadae4b16592", "shasum": "" }, "require": { "amphp/amp": "^2" }, "require-dev": { "amphp/php-cs-fixer-config": "dev-master", "amphp/phpunit-util": "^1", "friendsofphp/php-cs-fixer": "^2.3", "jetbrains/phpstorm-stubs": "^2019.3", "phpunit/phpunit": "^6 || ^7 || ^8", "vimeo/psalm": "^3.9@dev" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { "Amp\\ByteStream\\": "lib" }, "files": [ "lib/functions.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Aaron Piotrowski", "email": "aaron@trowski.com" }, { "name": "Niklas Keller", "email": "me@kelunik.com" } ], "description": "A stream abstraction to make working with non-blocking I/O simple.", "homepage": "http://amphp.org/byte-stream", "keywords": [ "amp", "amphp", "async", "io", "non-blocking", "stream" ], "time": "2020-04-04T16:56:54+00:00" }, { "name": "composer/semver", "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/composer/semver.git", "reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/composer/semver/zipball/c6bea70230ef4dd483e6bbcab6005f682ed3a8de", "reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de", "shasum": "" }, "require": { "php": "^5.3.2 || ^7.0" }, "require-dev": { "phpunit/phpunit": "^4.5 || ^5.0.5" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { "Composer\\Semver\\": "src" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Nils Adermann", "email": "naderman@naderman.de", "homepage": "http://www.naderman.de" }, { "name": "Jordi Boggiano", "email": "j.boggiano@seld.be", "homepage": "http://seld.be" }, { "name": "Rob Bast", "email": "rob.bast@gmail.com", "homepage": "http://robbast.nl" } ], "description": "Semver library that offers utilities, version constraint parsing and validation.", "keywords": [ "semantic", "semver", "validation", "versioning" ], "time": "2020-01-13T12:06:48+00:00" }, { "name": "composer/xdebug-handler", "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", "reference": "1ab9842d69e64fb3a01be6b656501032d1b78cb7" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/1ab9842d69e64fb3a01be6b656501032d1b78cb7", "reference": "1ab9842d69e64fb3a01be6b656501032d1b78cb7", "shasum": "" }, "require": { "php": "^5.3.2 || ^7.0 || ^8.0", "psr/log": "^1.0" }, "require-dev": { "phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 8" }, "type": "library", "autoload": { "psr-4": { "Composer\\XdebugHandler\\": "src" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "John Stevenson", "email": "john-stevenson@blueyonder.co.uk" } ], "description": "Restarts a process without Xdebug.", "keywords": [ "Xdebug", "performance" ], "time": "2020-03-01T12:26:26+00:00" }, { "name": "felixfbecker/advanced-json-rpc", "version": "v3.1.1", "source": { "type": "git", "url": "https://github.com/felixfbecker/php-advanced-json-rpc.git", "reference": "0ed363f8de17d284d479ec813c9ad3f6834b5c40" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/felixfbecker/php-advanced-json-rpc/zipball/0ed363f8de17d284d479ec813c9ad3f6834b5c40", "reference": "0ed363f8de17d284d479ec813c9ad3f6834b5c40", "shasum": "" }, "require": { "netresearch/jsonmapper": "^1.0 || ^2.0", "php": ">=7.0", "phpdocumentor/reflection-docblock": "^4.0.0 || ^5.0.0" }, "require-dev": { "phpunit/phpunit": "^6.0.0" }, "type": "library", "autoload": { "psr-4": { "AdvancedJsonRpc\\": "lib/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "ISC" ], "authors": [ { "name": "Felix Becker", "email": "felix.b@outlook.com" } ], "description": "A more advanced JSONRPC implementation", "time": "2020-03-11T15:21:41+00:00" }, { "name": "felixfbecker/language-server-protocol", "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/felixfbecker/php-language-server-protocol.git", "reference": "378801f6139bb74ac215d81cca1272af61df9a9f" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/378801f6139bb74ac215d81cca1272af61df9a9f", "reference": "378801f6139bb74ac215d81cca1272af61df9a9f", "shasum": "" }, "require": { "php": "^7.0" }, "require-dev": { "phpstan/phpstan": "*", "phpunit/phpunit": "^6.3", "squizlabs/php_codesniffer": "^3.1" }, "type": "library", "autoload": { "psr-4": { "LanguageServerProtocol\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "ISC" ], "authors": [ { "name": "Felix Becker", "email": "felix.b@outlook.com" } ], "description": "PHP classes for the Language Server Protocol", "keywords": [ "language", "microsoft", "php", "server" ], "time": "2019-06-23T21:03:50+00:00" }, { "name": "netresearch/jsonmapper", "version": "v2.1.0", "source": { "type": "git", "url": "https://github.com/cweiske/jsonmapper.git", "reference": "e0f1e33a71587aca81be5cffbb9746510e1fe04e" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/e0f1e33a71587aca81be5cffbb9746510e1fe04e", "reference": "e0f1e33a71587aca81be5cffbb9746510e1fe04e", "shasum": "" }, "require": { "ext-json": "*", "ext-pcre": "*", "ext-reflection": "*", "ext-spl": "*", "php": ">=5.6" }, "require-dev": { "phpunit/phpunit": "~4.8.35 || ~5.7 || ~6.4 || ~7.0", "squizlabs/php_codesniffer": "~3.5" }, "type": "library", "autoload": { "psr-0": { "JsonMapper": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "OSL-3.0" ], "authors": [ { "name": "Christian Weiske", "email": "cweiske@cweiske.de", "homepage": "http://github.com/cweiske/jsonmapper/", "role": "Developer" } ], "description": "Map nested JSON structures onto PHP classes", "time": "2020-04-16T18:48:43+00:00" }, { "name": "nikic/php-parser", "version": "v4.4.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", "reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120", "reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120", "shasum": "" }, "require": { "ext-tokenizer": "*", "php": ">=7.0" }, "require-dev": { "ircmaxell/php-yacc": "0.0.5", "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" }, "bin": [ "bin/php-parse" ], "type": "library", "extra": { "branch-alias": { "dev-master": "4.3-dev" } }, "autoload": { "psr-4": { "PhpParser\\": "lib/PhpParser" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Nikita Popov" } ], "description": "A PHP parser written in PHP", "keywords": [ "parser", "php" ], "time": "2020-04-10T16:34:50+00:00" }, { "name": "ocramius/package-versions", "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/Ocramius/PackageVersions.git", "reference": "44af6f3a2e2e04f2af46bcb302ad9600cba41c7d" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/44af6f3a2e2e04f2af46bcb302ad9600cba41c7d", "reference": "44af6f3a2e2e04f2af46bcb302ad9600cba41c7d", "shasum": "" }, "require": { "composer-plugin-api": "^1.0.0", "php": "^7.1.0" }, "require-dev": { "composer/composer": "^1.6.3", "doctrine/coding-standard": "^5.0.1", "ext-zip": "*", "infection/infection": "^0.7.1", "phpunit/phpunit": "^7.5.17" }, "type": "composer-plugin", "extra": { "class": "PackageVersions\\Installer", "branch-alias": { "dev-master": "2.0.x-dev" } }, "autoload": { "psr-4": { "PackageVersions\\": "src/PackageVersions" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Marco Pivetta", "email": "ocramius@gmail.com" } ], "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", "time": "2019-11-15T16:17:10+00:00" }, { "name": "openlss/lib-array2xml", "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/nullivex/lib-array2xml.git", "reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/nullivex/lib-array2xml/zipball/a91f18a8dfc69ffabe5f9b068bc39bb202c81d90", "reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90", "shasum": "" }, "require": { "php": ">=5.3.2" }, "type": "library", "autoload": { "psr-0": { "LSS": "" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "Apache-2.0" ], "authors": [ { "name": "Bryan Tong", "email": "bryan@nullivex.com", "homepage": "https://www.nullivex.com" }, { "name": "Tony Butler", "email": "spudz76@gmail.com", "homepage": "https://www.nullivex.com" } ], "description": "Array2XML conversion library credit to lalit.org", "homepage": "https://www.nullivex.com", "keywords": [ "array", "array conversion", "xml", "xml conversion" ], "time": "2019-03-29T20:06:56+00:00" }, { "name": "phpdocumentor/reflection-common", "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", "shasum": "" }, "require": { "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "~6" }, "type": "library", "extra": { "branch-alias": { "dev-master": "2.x-dev" } }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Jaap van Otterdijk", "email": "opensource@ijaap.nl" } ], "description": "Common reflection classes used by phpdocumentor to reflect the code structure", "homepage": "http://www.phpdoc.org", "keywords": [ "FQSEN", "phpDocumentor", "phpdoc", "reflection", "static analysis" ], "time": "2018-08-07T13:53:10+00:00" }, { "name": "phpdocumentor/reflection-docblock", "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", "shasum": "" }, "require": { "ext-filter": "^7.1", "php": "^7.2", "phpdocumentor/reflection-common": "^2.0", "phpdocumentor/type-resolver": "^1.0", "webmozart/assert": "^1" }, "require-dev": { "doctrine/instantiator": "^1", "mockery/mockery": "^1" }, "type": "library", "extra": { "branch-alias": { "dev-master": "5.x-dev" } }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Mike van Riel", "email": "me@mikevanriel.com" }, { "name": "Jaap van Otterdijk", "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "time": "2020-02-22T12:28:44+00:00" }, { "name": "phpdocumentor/type-resolver", "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", "shasum": "" }, "require": { "php": "^7.2", "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { "ext-tokenizer": "^7.2", "mockery/mockery": "~1" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Mike van Riel", "email": "me@mikevanriel.com" } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "time": "2020-02-18T18:59:58+00:00" }, { "name": "psr/container", "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/php-fig/container.git", "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", "shasum": "" }, "require": { "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } }, "autoload": { "psr-4": { "Psr\\Container\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "PHP-FIG", "homepage": "http://www.php-fig.org/" } ], "description": "Common Container Interface (PHP FIG PSR-11)", "homepage": "https://github.com/php-fig/container", "keywords": [ "PSR-11", "container", "container-interface", "container-interop", "psr" ], "time": "2017-02-14T16:28:37+00:00" }, { "name": "psr/log", "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", "shasum": "" }, "require": { "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.1.x-dev" } }, "autoload": { "psr-4": { "Psr\\Log\\": "Psr/Log/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "PHP-FIG", "homepage": "http://www.php-fig.org/" } ], "description": "Common interface for logging libraries", "homepage": "https://github.com/php-fig/log", "keywords": [ "log", "psr", "psr-3" ], "time": "2020-03-23T09:12:05+00:00" }, { "name": "sebastian/diff", "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", "shasum": "" }, "require": { "php": "^7.1" }, "require-dev": { "phpunit/phpunit": "^7.5 || ^8.0", "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { "dev-master": "3.0-dev" } }, "autoload": { "classmap": [ "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Kore Nordmann", "email": "mail@kore-nordmann.de" }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" } ], "description": "Diff implementation", "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ "diff", "udiff", "unidiff", "unified diff" ], "time": "2019-02-04T06:01:07+00:00" }, { "name": "symfony/console", "version": "v5.0.7", "source": { "type": "git", "url": "https://github.com/symfony/console.git", "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/symfony/console/zipball/5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", "reference": "5fa1caadc8cdaa17bcfb25219f3b53fe294a9935", "shasum": "" }, "require": { "php": "^7.2.5", "symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-php73": "^1.8", "symfony/service-contracts": "^1.1|^2" }, "conflict": { "symfony/dependency-injection": "<4.4", "symfony/event-dispatcher": "<4.4", "symfony/lock": "<4.4", "symfony/process": "<4.4" }, "provide": { "psr/log-implementation": "1.0" }, "require-dev": { "psr/log": "~1.0", "symfony/config": "^4.4|^5.0", "symfony/dependency-injection": "^4.4|^5.0", "symfony/event-dispatcher": "^4.4|^5.0", "symfony/lock": "^4.4|^5.0", "symfony/process": "^4.4|^5.0", "symfony/var-dumper": "^4.4|^5.0" }, "suggest": { "psr/log": "For using the console logger", "symfony/event-dispatcher": "", "symfony/lock": "", "symfony/process": "" }, "type": "library", "extra": { "branch-alias": { "dev-master": "5.0-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Console\\": "" }, "exclude-from-classmap": [ "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Fabien Potencier", "email": "fabien@symfony.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], "description": "Symfony Console Component", "homepage": "https://symfony.com", "time": "2020-03-30T11:42:42+00:00" }, { "name": "symfony/polyfill-ctype", "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/4719fa9c18b0464d399f1a63bf624b42b6fa8d14", "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14", "shasum": "" }, "require": { "php": ">=5.3.3" }, "suggest": { "ext-ctype": "For best performance" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.15-dev" } }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Ctype\\": "" }, "files": [ "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Gert de Pagter", "email": "BackEndTea@gmail.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", "homepage": "https://symfony.com", "keywords": [ "compatibility", "ctype", "polyfill", "portable" ], "time": "2020-02-27T09:26:54+00:00" }, { "name": "symfony/polyfill-mbstring", "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/81ffd3a9c6d707be22e3012b827de1c9775fc5ac", "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac", "shasum": "" }, "require": { "php": ">=5.3.3" }, "suggest": { "ext-mbstring": "For best performance" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.15-dev" } }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Mbstring\\": "" }, "files": [ "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Nicolas Grekas", "email": "p@tchwork.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for the Mbstring extension", "homepage": "https://symfony.com", "keywords": [ "compatibility", "mbstring", "polyfill", "portable", "shim" ], "time": "2020-03-09T19:04:49+00:00" }, { "name": "symfony/polyfill-php73", "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", "reference": "0f27e9f464ea3da33cbe7ca3bdf4eb66def9d0f7" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f27e9f464ea3da33cbe7ca3bdf4eb66def9d0f7", "reference": "0f27e9f464ea3da33cbe7ca3bdf4eb66def9d0f7", "shasum": "" }, "require": { "php": ">=5.3.3" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.15-dev" } }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Php73\\": "" }, "files": [ "bootstrap.php" ], "classmap": [ "Resources/stubs" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Nicolas Grekas", "email": "p@tchwork.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", "homepage": "https://symfony.com", "keywords": [ "compatibility", "polyfill", "portable", "shim" ], "time": "2020-02-27T09:26:54+00:00" }, { "name": "symfony/service-contracts", "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", "reference": "144c5e51266b281231e947b51223ba14acf1a749" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/symfony/service-contracts/zipball/144c5e51266b281231e947b51223ba14acf1a749", "reference": "144c5e51266b281231e947b51223ba14acf1a749", "shasum": "" }, "require": { "php": "^7.2.5", "psr/container": "^1.0" }, "suggest": { "symfony/service-implementation": "" }, "type": "library", "extra": { "branch-alias": { "dev-master": "2.0-dev" } }, "autoload": { "psr-4": { "Symfony\\Contracts\\Service\\": "" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Nicolas Grekas", "email": "p@tchwork.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], "description": "Generic abstractions related to writing services", "homepage": "https://symfony.com", "keywords": [ "abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards" ], "time": "2019-11-18T17:27:11+00:00" }, { "name": "vimeo/psalm", "version": "dev-master", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", "reference": "61f5a06" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/vimeo/psalm/zipball/61f5a06", "reference": "61f5a06", "shasum": "" }, "require": { "amphp/amp": "^2.1", "amphp/byte-stream": "^1.5", "composer/semver": "^1.4", "composer/xdebug-handler": "^1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-simplexml": "*", "ext-tokenizer": "*", "felixfbecker/advanced-json-rpc": "^3.0.3", "felixfbecker/language-server-protocol": "^1.4", "netresearch/jsonmapper": "^1.0 || ^2.0", "nikic/php-parser": "^4.3", "ocramius/package-versions": "^1.2", "openlss/lib-array2xml": "^1.0", "php": "^7.1.3|^8", "sebastian/diff": "^3.0 || ^4.0", "symfony/console": "^3.4.17 || ^4.1.6 || ^5.0", "webmozart/glob": "^4.1", "webmozart/path-util": "^2.3" }, "provide": { "psalm/psalm": "self.version" }, "require-dev": { "amphp/amp": "^2.4.2", "bamarni/composer-bin-plugin": "^1.2", "brianium/paratest": "^4.0.0", "ext-curl": "*", "php-coveralls/php-coveralls": "^2.2", "phpmyadmin/sql-parser": "5.1.0", "phpspec/prophecy": ">=1.9.0", "phpunit/phpunit": "^7.5.16 || ^8.5 || ^9.0", "psalm/plugin-phpunit": "^0.10", "slevomat/coding-standard": "^5.0", "squizlabs/php_codesniffer": "^3.5", "symfony/process": "^4.3" }, "suggest": { "ext-igbinary": "^2.0.5" }, "bin": [ "psalm", "psalm-language-server", "psalm-plugin", "psalm-refactor", "psalter" ], "type": "library", "extra": { "branch-alias": { "dev-master": "3.x-dev", "dev-2.x": "2.x-dev", "dev-1.x": "1.x-dev" } }, "autoload": { "psr-4": { "Psalm\\Plugin\\": "src/Psalm/Plugin", "Psalm\\": "src/Psalm" }, "files": [ "src/functions.php", "src/spl_object_id.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Matthew Brown" } ], "description": "A static analysis tool for finding errors in PHP applications", "keywords": [ "code", "inspection", "php" ], "time": "2020-04-18T15:57:25+00:00" }, { "name": "webmozart/assert", "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "shasum": "" }, "require": { "php": "^5.3.3 || ^7.0", "symfony/polyfill-ctype": "^1.8" }, "conflict": { "vimeo/psalm": "<3.9.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Bernhard Schussek", "email": "bschussek@gmail.com" } ], "description": "Assertions to validate method input/output with nice error messages.", "keywords": [ "assert", "check", "validate" ], "time": "2020-04-18T12:12:48+00:00" }, { "name": "webmozart/glob", "version": "4.1.0", "source": { "type": "git", "url": "https://github.com/webmozart/glob.git", "reference": "3cbf63d4973cf9d780b93d2da8eec7e4a9e63bbe" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/webmozart/glob/zipball/3cbf63d4973cf9d780b93d2da8eec7e4a9e63bbe", "reference": "3cbf63d4973cf9d780b93d2da8eec7e4a9e63bbe", "shasum": "" }, "require": { "php": "^5.3.3|^7.0", "webmozart/path-util": "^2.2" }, "require-dev": { "phpunit/phpunit": "^4.6", "sebastian/version": "^1.0.1", "symfony/filesystem": "^2.5" }, "type": "library", "extra": { "branch-alias": { "dev-master": "4.1-dev" } }, "autoload": { "psr-4": { "Webmozart\\Glob\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Bernhard Schussek", "email": "bschussek@gmail.com" } ], "description": "A PHP implementation of Ant's glob.", "time": "2015-12-29T11:14:33+00:00" }, { "name": "webmozart/path-util", "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/webmozart/path-util.git", "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/webmozart/path-util/zipball/d939f7edc24c9a1bb9c0dee5cb05d8e859490725", "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725", "shasum": "" }, "require": { "php": ">=5.3.3", "webmozart/assert": "~1.0" }, "require-dev": { "phpunit/phpunit": "^4.6", "sebastian/version": "^1.0.1" }, "type": "library", "extra": { "branch-alias": { "dev-master": "2.3-dev" } }, "autoload": { "psr-4": { "Webmozart\\PathUtil\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Bernhard Schussek", "email": "bschussek@gmail.com" } ], "description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.", "time": "2015-12-17T08:42:14+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": { "vimeo/psalm": 20 }, "prefer-stable": false, "prefer-lowest": false, "platform": [], "platform-dev": [] } php-webmozart-assert-1.9.1/composer.json000066400000000000000000000015711370262643300203540ustar00rootroot00000000000000{ "name": "webmozart/assert", "description": "Assertions to validate method input/output with nice error messages.", "keywords": [ "assert", "check", "validate" ], "license": "MIT", "authors": [ { "name": "Bernhard Schussek", "email": "bschussek@gmail.com" } ], "require": { "php": "^5.3.3 || ^7.0 || ^8.0", "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "conflict": { "vimeo/psalm": "<3.9.1", "phpstan/phpstan": "<0.12.20" }, "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" } }, "autoload-dev": { "psr-4": { "Webmozart\\Assert\\Tests\\": "tests/", "Webmozart\\Assert\\Bin\\": "bin/src" } } } php-webmozart-assert-1.9.1/phpunit.xml.dist000066400000000000000000000012161370262643300210010ustar00rootroot00000000000000 ./tests/ ./tests/static-analysis ./src/ php-webmozart-assert-1.9.1/psalm.xml000066400000000000000000000006271370262643300174710ustar00rootroot00000000000000 php-webmozart-assert-1.9.1/src/000077500000000000000000000000001370262643300164155ustar00rootroot00000000000000php-webmozart-assert-1.9.1/src/Assert.php000066400000000000000000001550251370262643300203770ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Webmozart\Assert; use ArrayAccess; use BadMethodCallException; use Closure; use Countable; use DateTime; use DateTimeImmutable; use Exception; use InvalidArgumentException; use ResourceBundle; use SimpleXMLElement; use Throwable; use Traversable; /** * Efficient assertions to validate the input/output of your methods. * * @mixin Mixin * * @since 1.0 * * @author Bernhard Schussek */ class Assert { /** * @psalm-pure * @psalm-assert string $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function string($value, $message = '') { if (!\is_string($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a string. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert non-empty-string $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function stringNotEmpty($value, $message = '') { static::string($value, $message); static::notEq($value, '', $message); } /** * @psalm-pure * @psalm-assert int $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function integer($value, $message = '') { if (!\is_int($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an integer. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert numeric $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function integerish($value, $message = '') { if (!\is_numeric($value) || $value != (int) $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an integerish value. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert float $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function float($value, $message = '') { if (!\is_float($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a float. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert numeric $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function numeric($value, $message = '') { if (!\is_numeric($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a numeric. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert int $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function natural($value, $message = '') { if (!\is_int($value) || $value < 0) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a non-negative integer. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert bool $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function boolean($value, $message = '') { if (!\is_bool($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a boolean. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert scalar $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function scalar($value, $message = '') { if (!\is_scalar($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a scalar. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert object $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function object($value, $message = '') { if (!\is_object($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an object. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert resource $value * * @param mixed $value * @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php * @param string $message * * @throws InvalidArgumentException */ public static function resource($value, $type = null, $message = '') { if (!\is_resource($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a resource. Got: %s', static::typeToString($value) )); } if ($type && $type !== \get_resource_type($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a resource of type %2$s. Got: %s', static::typeToString($value), $type )); } } /** * @psalm-pure * @psalm-assert callable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function isCallable($value, $message = '') { if (!\is_callable($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a callable. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert array $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function isArray($value, $message = '') { if (!\is_array($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert iterable $value * * @deprecated use "isIterable" or "isInstanceOf" instead * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function isTraversable($value, $message = '') { @\trigger_error( \sprintf( 'The "%s" assertion is deprecated. You should stop using it, as it will soon be removed in 2.0 version. Use "isIterable" or "isInstanceOf" instead.', __METHOD__ ), \E_USER_DEPRECATED ); if (!\is_array($value) && !($value instanceof Traversable)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a traversable. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert array|ArrayAccess $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function isArrayAccessible($value, $message = '') { if (!\is_array($value) && !($value instanceof ArrayAccess)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array accessible. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert countable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function isCountable($value, $message = '') { if ( !\is_array($value) && !($value instanceof Countable) && !($value instanceof ResourceBundle) && !($value instanceof SimpleXMLElement) ) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a countable. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function isIterable($value, $message = '') { if (!\is_array($value) && !($value instanceof Traversable)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an iterable. Got: %s', static::typeToString($value) )); } } /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert ExpectedType $value * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function isInstanceOf($value, $class, $message = '') { if (!($value instanceof $class)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an instance of %2$s. Got: %s', static::typeToString($value), $class )); } } /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert !ExpectedType $value * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function notInstanceOf($value, $class, $message = '') { if ($value instanceof $class) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an instance other than %2$s. Got: %s', static::typeToString($value), $class )); } } /** * @psalm-pure * @psalm-param array $classes * * @param mixed $value * @param array $classes * @param string $message * * @throws InvalidArgumentException */ public static function isInstanceOfAny($value, array $classes, $message = '') { foreach ($classes as $class) { if ($value instanceof $class) { return; } } static::reportInvalidArgument(\sprintf( $message ?: 'Expected an instance of any of %2$s. Got: %s', static::typeToString($value), \implode(', ', \array_map(array('static', 'valueToString'), $classes)) )); } /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert ExpectedType|class-string $value * * @param object|string $value * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function isAOf($value, $class, $message = '') { static::string($class, 'Expected class as a string. Got: %s'); if (!\is_a($value, $class, \is_string($value))) { static::reportInvalidArgument(sprintf( $message ?: 'Expected an instance of this class or to this class among his parents %2$s. Got: %s', static::typeToString($value), $class )); } } /** * @psalm-pure * @psalm-template UnexpectedType of object * @psalm-param class-string $class * @psalm-assert !UnexpectedType $value * @psalm-assert !class-string $value * * @param object|string $value * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function isNotA($value, $class, $message = '') { static::string($class, 'Expected class as a string. Got: %s'); if (\is_a($value, $class, \is_string($value))) { static::reportInvalidArgument(sprintf( $message ?: 'Expected an instance of this class or to this class among his parents other than %2$s. Got: %s', static::typeToString($value), $class )); } } /** * @psalm-pure * @psalm-param array $classes * * @param object|string $value * @param string[] $classes * @param string $message * * @throws InvalidArgumentException */ public static function isAnyOf($value, array $classes, $message = '') { foreach ($classes as $class) { static::string($class, 'Expected class as a string. Got: %s'); if (\is_a($value, $class, \is_string($value))) { return; } } static::reportInvalidArgument(sprintf( $message ?: 'Expected an any of instance of this class or to this class among his parents other than %2$s. Got: %s', static::typeToString($value), \implode(', ', \array_map(array('static', 'valueToString'), $classes)) )); } /** * @psalm-pure * @psalm-assert empty $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function isEmpty($value, $message = '') { if (!empty($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an empty value. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert !empty $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function notEmpty($value, $message = '') { if (empty($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a non-empty value. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert null $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function null($value, $message = '') { if (null !== $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected null. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert !null $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function notNull($value, $message = '') { if (null === $value) { static::reportInvalidArgument( $message ?: 'Expected a value other than null.' ); } } /** * @psalm-pure * @psalm-assert true $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function true($value, $message = '') { if (true !== $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to be true. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert false $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function false($value, $message = '') { if (false !== $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to be false. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert !false $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function notFalse($value, $message = '') { if (false === $value) { static::reportInvalidArgument( $message ?: 'Expected a value other than false.' ); } } /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function ip($value, $message = '') { if (false === \filter_var($value, \FILTER_VALIDATE_IP)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to be an IP. Got: %s', static::valueToString($value) )); } } /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function ipv4($value, $message = '') { if (false === \filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to be an IPv4. Got: %s', static::valueToString($value) )); } } /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function ipv6($value, $message = '') { if (false === \filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to be an IPv6. Got: %s', static::valueToString($value) )); } } /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function email($value, $message = '') { if (false === \filter_var($value, FILTER_VALIDATE_EMAIL)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to be a valid e-mail address. Got: %s', static::valueToString($value) )); } } /** * Does non strict comparisons on the items, so ['3', 3] will not pass the assertion. * * @param array $values * @param string $message * * @throws InvalidArgumentException */ public static function uniqueValues(array $values, $message = '') { $allValues = \count($values); $uniqueValues = \count(\array_unique($values)); if ($allValues !== $uniqueValues) { $difference = $allValues - $uniqueValues; static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array of unique values, but %s of them %s duplicated', $difference, (1 === $difference ? 'is' : 'are') )); } } /** * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function eq($value, $expect, $message = '') { if ($expect != $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value equal to %2$s. Got: %s', static::valueToString($value), static::valueToString($expect) )); } } /** * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function notEq($value, $expect, $message = '') { if ($expect == $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a different value than %s.', static::valueToString($expect) )); } } /** * @psalm-pure * * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function same($value, $expect, $message = '') { if ($expect !== $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value identical to %2$s. Got: %s', static::valueToString($value), static::valueToString($expect) )); } } /** * @psalm-pure * * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function notSame($value, $expect, $message = '') { if ($expect === $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value not identical to %s.', static::valueToString($expect) )); } } /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function greaterThan($value, $limit, $message = '') { if ($value <= $limit) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value greater than %2$s. Got: %s', static::valueToString($value), static::valueToString($limit) )); } } /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function greaterThanEq($value, $limit, $message = '') { if ($value < $limit) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', static::valueToString($value), static::valueToString($limit) )); } } /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function lessThan($value, $limit, $message = '') { if ($value >= $limit) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value less than %2$s. Got: %s', static::valueToString($value), static::valueToString($limit) )); } } /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function lessThanEq($value, $limit, $message = '') { if ($value > $limit) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value less than or equal to %2$s. Got: %s', static::valueToString($value), static::valueToString($limit) )); } } /** * Inclusive range, so Assert::(3, 3, 5) passes. * * @psalm-pure * * @param mixed $value * @param mixed $min * @param mixed $max * @param string $message * * @throws InvalidArgumentException */ public static function range($value, $min, $max, $message = '') { if ($value < $min || $value > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value between %2$s and %3$s. Got: %s', static::valueToString($value), static::valueToString($min), static::valueToString($max) )); } } /** * A more human-readable alias of Assert::inArray(). * * @psalm-pure * * @param mixed $value * @param array $values * @param string $message * * @throws InvalidArgumentException */ public static function oneOf($value, array $values, $message = '') { static::inArray($value, $values, $message); } /** * Does strict comparison, so Assert::inArray(3, ['3']) does not pass the assertion. * * @psalm-pure * * @param mixed $value * @param array $values * @param string $message * * @throws InvalidArgumentException */ public static function inArray($value, array $values, $message = '') { if (!\in_array($value, $values, true)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected one of: %2$s. Got: %s', static::valueToString($value), \implode(', ', \array_map(array('static', 'valueToString'), $values)) )); } } /** * @psalm-pure * * @param string $value * @param string $subString * @param string $message * * @throws InvalidArgumentException */ public static function contains($value, $subString, $message = '') { if (false === \strpos($value, $subString)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain %2$s. Got: %s', static::valueToString($value), static::valueToString($subString) )); } } /** * @psalm-pure * * @param string $value * @param string $subString * @param string $message * * @throws InvalidArgumentException */ public static function notContains($value, $subString, $message = '') { if (false !== \strpos($value, $subString)) { static::reportInvalidArgument(\sprintf( $message ?: '%2$s was not expected to be contained in a value. Got: %s', static::valueToString($value), static::valueToString($subString) )); } } /** * @psalm-pure * * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function notWhitespaceOnly($value, $message = '') { if (\preg_match('/^\s*$/', $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a non-whitespace string. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * * @param string $value * @param string $prefix * @param string $message * * @throws InvalidArgumentException */ public static function startsWith($value, $prefix, $message = '') { if (0 !== \strpos($value, $prefix)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to start with %2$s. Got: %s', static::valueToString($value), static::valueToString($prefix) )); } } /** * @psalm-pure * * @param string $value * @param string $prefix * @param string $message * * @throws InvalidArgumentException */ public static function notStartsWith($value, $prefix, $message = '') { if (0 === \strpos($value, $prefix)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value not to start with %2$s. Got: %s', static::valueToString($value), static::valueToString($prefix) )); } } /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function startsWithLetter($value, $message = '') { static::string($value); $valid = isset($value[0]); if ($valid) { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = \ctype_alpha($value[0]); \setlocale(LC_CTYPE, $locale); } if (!$valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to start with a letter. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * * @param string $value * @param string $suffix * @param string $message * * @throws InvalidArgumentException */ public static function endsWith($value, $suffix, $message = '') { if ($suffix !== \substr($value, -\strlen($suffix))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to end with %2$s. Got: %s', static::valueToString($value), static::valueToString($suffix) )); } } /** * @psalm-pure * * @param string $value * @param string $suffix * @param string $message * * @throws InvalidArgumentException */ public static function notEndsWith($value, $suffix, $message = '') { if ($suffix === \substr($value, -\strlen($suffix))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value not to end with %2$s. Got: %s', static::valueToString($value), static::valueToString($suffix) )); } } /** * @psalm-pure * * @param string $value * @param string $pattern * @param string $message * * @throws InvalidArgumentException */ public static function regex($value, $pattern, $message = '') { if (!\preg_match($pattern, $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The value %s does not match the expected pattern.', static::valueToString($value) )); } } /** * @psalm-pure * * @param string $value * @param string $pattern * @param string $message * * @throws InvalidArgumentException */ public static function notRegex($value, $pattern, $message = '') { if (\preg_match($pattern, $value, $matches, PREG_OFFSET_CAPTURE)) { static::reportInvalidArgument(\sprintf( $message ?: 'The value %s matches the pattern %s (at offset %d).', static::valueToString($value), static::valueToString($pattern), $matches[0][1] )); } } /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function unicodeLetters($value, $message = '') { static::string($value); if (!\preg_match('/^\p{L}+$/u', $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain only Unicode letters. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function alpha($value, $message = '') { static::string($value); $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_alpha($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain only letters. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function digits($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_digit($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain digits only. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function alnum($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_alnum($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain letters and digits only. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert lowercase-string $value * * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function lower($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_lower($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain lowercase characters only. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-assert !lowercase-string $value * * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function upper($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_upper($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain uppercase characters only. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * * @param string $value * @param int $length * @param string $message * * @throws InvalidArgumentException */ public static function length($value, $length, $message = '') { if ($length !== static::strlen($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain %2$s characters. Got: %s', static::valueToString($value), $length )); } } /** * Inclusive min. * * @psalm-pure * * @param string $value * @param int|float $min * @param string $message * * @throws InvalidArgumentException */ public static function minLength($value, $min, $message = '') { if (static::strlen($value) < $min) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', static::valueToString($value), $min )); } } /** * Inclusive max. * * @psalm-pure * * @param string $value * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function maxLength($value, $max, $message = '') { if (static::strlen($value) > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', static::valueToString($value), $max )); } } /** * Inclusive , so Assert::lengthBetween('asd', 3, 5); passes the assertion. * * @psalm-pure * * @param string $value * @param int|float $min * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function lengthBetween($value, $min, $max, $message = '') { $length = static::strlen($value); if ($length < $min || $length > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain between %2$s and %3$s characters. Got: %s', static::valueToString($value), $min, $max )); } } /** * Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function fileExists($value, $message = '') { static::string($value); if (!\file_exists($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The file %s does not exist.', static::valueToString($value) )); } } /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function file($value, $message = '') { static::fileExists($value, $message); if (!\is_file($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is not a file.', static::valueToString($value) )); } } /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function directory($value, $message = '') { static::fileExists($value, $message); if (!\is_dir($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is no directory.', static::valueToString($value) )); } } /** * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function readable($value, $message = '') { if (!\is_readable($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is not readable.', static::valueToString($value) )); } } /** * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function writable($value, $message = '') { if (!\is_writable($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is not writable.', static::valueToString($value) )); } } /** * @psalm-assert class-string $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function classExists($value, $message = '') { if (!\class_exists($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an existing class name. Got: %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert class-string|ExpectedType $value * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function subclassOf($value, $class, $message = '') { if (!\is_subclass_of($value, $class)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a sub-class of %2$s. Got: %s', static::valueToString($value), static::valueToString($class) )); } } /** * @psalm-assert class-string $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function interfaceExists($value, $message = '') { if (!\interface_exists($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an existing interface name. got %s', static::valueToString($value) )); } } /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $interface * @psalm-assert class-string $value * * @param mixed $value * @param mixed $interface * @param string $message * * @throws InvalidArgumentException */ public static function implementsInterface($value, $interface, $message = '') { if (!\in_array($interface, \class_implements($value))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an implementation of %2$s. Got: %s', static::valueToString($value), static::valueToString($interface) )); } } /** * @psalm-pure * @psalm-param class-string|object $classOrObject * * @param string|object $classOrObject * @param mixed $property * @param string $message * * @throws InvalidArgumentException */ public static function propertyExists($classOrObject, $property, $message = '') { if (!\property_exists($classOrObject, $property)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the property %s to exist.', static::valueToString($property) )); } } /** * @psalm-pure * @psalm-param class-string|object $classOrObject * * @param string|object $classOrObject * @param mixed $property * @param string $message * * @throws InvalidArgumentException */ public static function propertyNotExists($classOrObject, $property, $message = '') { if (\property_exists($classOrObject, $property)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the property %s to not exist.', static::valueToString($property) )); } } /** * @psalm-pure * @psalm-param class-string|object $classOrObject * * @param string|object $classOrObject * @param mixed $method * @param string $message * * @throws InvalidArgumentException */ public static function methodExists($classOrObject, $method, $message = '') { if (!(\is_string($classOrObject) || \is_object($classOrObject)) || !\method_exists($classOrObject, $method)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the method %s to exist.', static::valueToString($method) )); } } /** * @psalm-pure * @psalm-param class-string|object $classOrObject * * @param string|object $classOrObject * @param mixed $method * @param string $message * * @throws InvalidArgumentException */ public static function methodNotExists($classOrObject, $method, $message = '') { if ((\is_string($classOrObject) || \is_object($classOrObject)) && \method_exists($classOrObject, $method)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the method %s to not exist.', static::valueToString($method) )); } } /** * @psalm-pure * * @param array $array * @param string|int $key * @param string $message * * @throws InvalidArgumentException */ public static function keyExists($array, $key, $message = '') { if (!(isset($array[$key]) || \array_key_exists($key, $array))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the key %s to exist.', static::valueToString($key) )); } } /** * @psalm-pure * * @param array $array * @param string|int $key * @param string $message * * @throws InvalidArgumentException */ public static function keyNotExists($array, $key, $message = '') { if (isset($array[$key]) || \array_key_exists($key, $array)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the key %s to not exist.', static::valueToString($key) )); } } /** * Checks if a value is a valid array key (int or string). * * @psalm-pure * @psalm-assert array-key $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function validArrayKey($value, $message = '') { if (!(\is_int($value) || \is_string($value))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected string or integer. Got: %s', static::typeToString($value) )); } } /** * Does not check if $array is countable, this can generate a warning on php versions after 7.2. * * @param Countable|array $array * @param int $number * @param string $message * * @throws InvalidArgumentException */ public static function count($array, $number, $message = '') { static::eq( \count($array), $number, \sprintf( $message ?: 'Expected an array to contain %d elements. Got: %d.', $number, \count($array) ) ); } /** * Does not check if $array is countable, this can generate a warning on php versions after 7.2. * * @param Countable|array $array * @param int|float $min * @param string $message * * @throws InvalidArgumentException */ public static function minCount($array, $min, $message = '') { if (\count($array) < $min) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array to contain at least %2$d elements. Got: %d', \count($array), $min )); } } /** * Does not check if $array is countable, this can generate a warning on php versions after 7.2. * * @param Countable|array $array * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function maxCount($array, $max, $message = '') { if (\count($array) > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array to contain at most %2$d elements. Got: %d', \count($array), $max )); } } /** * Does not check if $array is countable, this can generate a warning on php versions after 7.2. * * @param Countable|array $array * @param int|float $min * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function countBetween($array, $min, $max, $message = '') { $count = \count($array); if ($count < $min || $count > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array to contain between %2$d and %3$d elements. Got: %d', $count, $min, $max )); } } /** * @psalm-pure * @psalm-assert list $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function isList($array, $message = '') { if (!\is_array($array) || $array !== \array_values($array)) { static::reportInvalidArgument( $message ?: 'Expected list - non-associative array.' ); } } /** * @psalm-pure * @psalm-assert non-empty-list $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function isNonEmptyList($array, $message = '') { static::isList($array, $message); static::notEmpty($array, $message); } /** * @psalm-pure * @psalm-template T * @psalm-param mixed|array $array * @psalm-assert array $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function isMap($array, $message = '') { if ( !\is_array($array) || \array_keys($array) !== \array_filter(\array_keys($array), '\is_string') ) { static::reportInvalidArgument( $message ?: 'Expected map - associative array with string keys.' ); } } /** * @psalm-pure * @psalm-template T * @psalm-param mixed|array $array * @psalm-assert array $array * @psalm-assert !empty $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function isNonEmptyMap($array, $message = '') { static::isMap($array, $message); static::notEmpty($array, $message); } /** * @psalm-pure * * @param string $value * @param string $message * * @throws InvalidArgumentException */ public static function uuid($value, $message = '') { $value = \str_replace(array('urn:', 'uuid:', '{', '}'), '', $value); // The nil UUID is special form of UUID that is specified to have all // 128 bits set to zero. if ('00000000-0000-0000-0000-000000000000' === $value) { return; } if (!\preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Value %s is not a valid UUID.', static::valueToString($value) )); } } /** * @psalm-param class-string $class * * @param Closure $expression * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function throws(Closure $expression, $class = 'Exception', $message = '') { static::string($class); $actual = 'none'; try { $expression(); } catch (Exception $e) { $actual = \get_class($e); if ($e instanceof $class) { return; } } catch (Throwable $e) { $actual = \get_class($e); if ($e instanceof $class) { return; } } static::reportInvalidArgument($message ?: \sprintf( 'Expected to throw "%s", got "%s"', $class, $actual )); } /** * @throws BadMethodCallException */ public static function __callStatic($name, $arguments) { if ('nullOr' === \substr($name, 0, 6)) { if (null !== $arguments[0]) { $method = \lcfirst(\substr($name, 6)); \call_user_func_array(array('static', $method), $arguments); } return; } if ('all' === \substr($name, 0, 3)) { static::isIterable($arguments[0]); $method = \lcfirst(\substr($name, 3)); $args = $arguments; foreach ($arguments[0] as $entry) { $args[0] = $entry; \call_user_func_array(array('static', $method), $args); } return; } throw new BadMethodCallException('No such method: '.$name); } /** * @param mixed $value * * @return string */ protected static function valueToString($value) { if (null === $value) { return 'null'; } if (true === $value) { return 'true'; } if (false === $value) { return 'false'; } if (\is_array($value)) { return 'array'; } if (\is_object($value)) { if (\method_exists($value, '__toString')) { return \get_class($value).': '.self::valueToString($value->__toString()); } if ($value instanceof DateTime || $value instanceof DateTimeImmutable) { return \get_class($value).': '.self::valueToString($value->format('c')); } return \get_class($value); } if (\is_resource($value)) { return 'resource'; } if (\is_string($value)) { return '"'.$value.'"'; } return (string) $value; } /** * @param mixed $value * * @return string */ protected static function typeToString($value) { return \is_object($value) ? \get_class($value) : \gettype($value); } protected static function strlen($value) { if (!\function_exists('mb_detect_encoding')) { return \strlen($value); } if (false === $encoding = \mb_detect_encoding($value)) { return \strlen($value); } return \mb_strlen($value, $encoding); } /** * @param string $message * * @throws InvalidArgumentException * * @psalm-pure this method is not supposed to perform side-effects */ protected static function reportInvalidArgument($message) { throw new InvalidArgumentException($message); } private function __construct() { } } php-webmozart-assert-1.9.1/src/Mixin.php000066400000000000000000001406021370262643300202150ustar00rootroot00000000000000 $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allString($value, $message = ''); /** * @psalm-pure * @psalm-assert null|non-empty-string $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrStringNotEmpty($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allStringNotEmpty($value, $message = ''); /** * @psalm-pure * @psalm-assert null|int $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrInteger($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allInteger($value, $message = ''); /** * @psalm-pure * @psalm-assert null|numeric $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIntegerish($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIntegerish($value, $message = ''); /** * @psalm-pure * @psalm-assert null|float $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrFloat($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allFloat($value, $message = ''); /** * @psalm-pure * @psalm-assert null|numeric $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNumeric($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allNumeric($value, $message = ''); /** * @psalm-pure * @psalm-assert null|int $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNatural($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allNatural($value, $message = ''); /** * @psalm-pure * @psalm-assert null|bool $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrBoolean($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allBoolean($value, $message = ''); /** * @psalm-pure * @psalm-assert null|scalar $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrScalar($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allScalar($value, $message = ''); /** * @psalm-pure * @psalm-assert null|object $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrObject($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allObject($value, $message = ''); /** * @psalm-pure * @psalm-assert null|resource $value * * @param mixed $value * @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php * @param string $message * * @throws InvalidArgumentException */ public static function nullOrResource($value, $type = null, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php * @param string $message * * @throws InvalidArgumentException */ public static function allResource($value, $type = null, $message = ''); /** * @psalm-pure * @psalm-assert null|callable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsCallable($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIsCallable($value, $message = ''); /** * @psalm-pure * @psalm-assert null|array $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsArray($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIsArray($value, $message = ''); /** * @psalm-pure * @psalm-assert null|iterable $value * * @deprecated use "isIterable" or "isInstanceOf" instead * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsTraversable($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @deprecated use "isIterable" or "isInstanceOf" instead * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIsTraversable($value, $message = ''); /** * @psalm-pure * @psalm-assert null|array|ArrayAccess $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsArrayAccessible($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIsArrayAccessible($value, $message = ''); /** * @psalm-pure * @psalm-assert null|countable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsCountable($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIsCountable($value, $message = ''); /** * @psalm-pure * @psalm-assert null|iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsIterable($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIsIterable($value, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert null|ExpectedType $value * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsInstanceOf($value, $class, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert iterable $value * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function allIsInstanceOf($value, $class, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotInstanceOf($value, $class, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function allNotInstanceOf($value, $class, $message = ''); /** * @psalm-pure * @psalm-param array $classes * * @param mixed $value * @param array $classes * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsInstanceOfAny($value, $classes, $message = ''); /** * @psalm-pure * @psalm-param array $classes * * @param mixed $value * @param array $classes * @param string $message * * @throws InvalidArgumentException */ public static function allIsInstanceOfAny($value, $classes, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert null|ExpectedType|class-string $value * * @param null|object|string $value * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsAOf($value, $class, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert iterable> $value * * @param iterable $value * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function allIsAOf($value, $class, $message = ''); /** * @psalm-pure * @psalm-template UnexpectedType of object * @psalm-param class-string $class * * @param null|object|string $value * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsNotA($value, $class, $message = ''); /** * @psalm-pure * @psalm-template UnexpectedType of object * @psalm-param class-string $class * * @param iterable $value * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function allIsNotA($value, $class, $message = ''); /** * @psalm-pure * @psalm-param array $classes * * @param null|object|string $value * @param string[] $classes * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsAnyOf($value, $classes, $message = ''); /** * @psalm-pure * @psalm-param array $classes * * @param iterable $value * @param string[] $classes * @param string $message * * @throws InvalidArgumentException */ public static function allIsAnyOf($value, $classes, $message = ''); /** * @psalm-pure * @psalm-assert empty $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsEmpty($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIsEmpty($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotEmpty($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allNotEmpty($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allNull($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allNotNull($value, $message = ''); /** * @psalm-pure * @psalm-assert null|true $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrTrue($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allTrue($value, $message = ''); /** * @psalm-pure * @psalm-assert null|false $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrFalse($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allFalse($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotFalse($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allNotFalse($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIp($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIp($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIpv4($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIpv4($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIpv6($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allIpv6($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrEmail($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allEmail($value, $message = ''); /** * @param null|array $values * @param string $message * * @throws InvalidArgumentException */ public static function nullOrUniqueValues($values, $message = ''); /** * @param iterable $values * @param string $message * * @throws InvalidArgumentException */ public static function allUniqueValues($values, $message = ''); /** * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function nullOrEq($value, $expect, $message = ''); /** * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function allEq($value, $expect, $message = ''); /** * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotEq($value, $expect, $message = ''); /** * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function allNotEq($value, $expect, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function nullOrSame($value, $expect, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function allSame($value, $expect, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotSame($value, $expect, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $expect * @param string $message * * @throws InvalidArgumentException */ public static function allNotSame($value, $expect, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function nullOrGreaterThan($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function allGreaterThan($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function nullOrGreaterThanEq($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function allGreaterThanEq($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function nullOrLessThan($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function allLessThan($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function nullOrLessThanEq($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $limit * @param string $message * * @throws InvalidArgumentException */ public static function allLessThanEq($value, $limit, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $min * @param mixed $max * @param string $message * * @throws InvalidArgumentException */ public static function nullOrRange($value, $min, $max, $message = ''); /** * @psalm-pure * * @param mixed $value * @param mixed $min * @param mixed $max * @param string $message * * @throws InvalidArgumentException */ public static function allRange($value, $min, $max, $message = ''); /** * @psalm-pure * * @param mixed $value * @param array $values * @param string $message * * @throws InvalidArgumentException */ public static function nullOrOneOf($value, $values, $message = ''); /** * @psalm-pure * * @param mixed $value * @param array $values * @param string $message * * @throws InvalidArgumentException */ public static function allOneOf($value, $values, $message = ''); /** * @psalm-pure * * @param mixed $value * @param array $values * @param string $message * * @throws InvalidArgumentException */ public static function nullOrInArray($value, $values, $message = ''); /** * @psalm-pure * * @param mixed $value * @param array $values * @param string $message * * @throws InvalidArgumentException */ public static function allInArray($value, $values, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $subString * @param string $message * * @throws InvalidArgumentException */ public static function nullOrContains($value, $subString, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $subString * @param string $message * * @throws InvalidArgumentException */ public static function allContains($value, $subString, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $subString * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotContains($value, $subString, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $subString * @param string $message * * @throws InvalidArgumentException */ public static function allNotContains($value, $subString, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotWhitespaceOnly($value, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allNotWhitespaceOnly($value, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $prefix * @param string $message * * @throws InvalidArgumentException */ public static function nullOrStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $prefix * @param string $message * * @throws InvalidArgumentException */ public static function allStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $prefix * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $prefix * @param string $message * * @throws InvalidArgumentException */ public static function allNotStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrStartsWithLetter($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allStartsWithLetter($value, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $suffix * @param string $message * * @throws InvalidArgumentException */ public static function nullOrEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $suffix * @param string $message * * @throws InvalidArgumentException */ public static function allEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $suffix * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $suffix * @param string $message * * @throws InvalidArgumentException */ public static function allNotEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $pattern * @param string $message * * @throws InvalidArgumentException */ public static function nullOrRegex($value, $pattern, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $pattern * @param string $message * * @throws InvalidArgumentException */ public static function allRegex($value, $pattern, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $pattern * @param string $message * * @throws InvalidArgumentException */ public static function nullOrNotRegex($value, $pattern, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $pattern * @param string $message * * @throws InvalidArgumentException */ public static function allNotRegex($value, $pattern, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrUnicodeLetters($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allUnicodeLetters($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrAlpha($value, $message = ''); /** * @psalm-pure * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allAlpha($value, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrDigits($value, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allDigits($value, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrAlnum($value, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allAlnum($value, $message = ''); /** * @psalm-pure * @psalm-assert null|lowercase-string $value * * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrLower($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allLower($value, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrUpper($value, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allUpper($value, $message = ''); /** * @psalm-pure * * @param null|string $value * @param int $length * @param string $message * * @throws InvalidArgumentException */ public static function nullOrLength($value, $length, $message = ''); /** * @psalm-pure * * @param iterable $value * @param int $length * @param string $message * * @throws InvalidArgumentException */ public static function allLength($value, $length, $message = ''); /** * @psalm-pure * * @param null|string $value * @param int|float $min * @param string $message * * @throws InvalidArgumentException */ public static function nullOrMinLength($value, $min, $message = ''); /** * @psalm-pure * * @param iterable $value * @param int|float $min * @param string $message * * @throws InvalidArgumentException */ public static function allMinLength($value, $min, $message = ''); /** * @psalm-pure * * @param null|string $value * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function nullOrMaxLength($value, $max, $message = ''); /** * @psalm-pure * * @param iterable $value * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function allMaxLength($value, $max, $message = ''); /** * @psalm-pure * * @param null|string $value * @param int|float $min * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function nullOrLengthBetween($value, $min, $max, $message = ''); /** * @psalm-pure * * @param iterable $value * @param int|float $min * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function allLengthBetween($value, $min, $max, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrFileExists($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allFileExists($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrFile($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allFile($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrDirectory($value, $message = ''); /** * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allDirectory($value, $message = ''); /** * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrReadable($value, $message = ''); /** * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allReadable($value, $message = ''); /** * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrWritable($value, $message = ''); /** * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allWritable($value, $message = ''); /** * @psalm-assert null|class-string $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrClassExists($value, $message = ''); /** * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allClassExists($value, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert null|class-string|ExpectedType $value * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function nullOrSubclassOf($value, $class, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $class * @psalm-assert iterable|ExpectedType> $value * * @param mixed $value * @param string|object $class * @param string $message * * @throws InvalidArgumentException */ public static function allSubclassOf($value, $class, $message = ''); /** * @psalm-assert null|class-string $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrInterfaceExists($value, $message = ''); /** * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allInterfaceExists($value, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $interface * @psalm-assert null|class-string $value * * @param mixed $value * @param mixed $interface * @param string $message * * @throws InvalidArgumentException */ public static function nullOrImplementsInterface($value, $interface, $message = ''); /** * @psalm-pure * @psalm-template ExpectedType of object * @psalm-param class-string $interface * @psalm-assert iterable> $value * * @param mixed $value * @param mixed $interface * @param string $message * * @throws InvalidArgumentException */ public static function allImplementsInterface($value, $interface, $message = ''); /** * @psalm-pure * @psalm-param null|class-string|object $classOrObject * * @param null|string|object $classOrObject * @param mixed $property * @param string $message * * @throws InvalidArgumentException */ public static function nullOrPropertyExists($classOrObject, $property, $message = ''); /** * @psalm-pure * @psalm-param iterable $classOrObject * * @param iterable $classOrObject * @param mixed $property * @param string $message * * @throws InvalidArgumentException */ public static function allPropertyExists($classOrObject, $property, $message = ''); /** * @psalm-pure * @psalm-param null|class-string|object $classOrObject * * @param null|string|object $classOrObject * @param mixed $property * @param string $message * * @throws InvalidArgumentException */ public static function nullOrPropertyNotExists($classOrObject, $property, $message = ''); /** * @psalm-pure * @psalm-param iterable $classOrObject * * @param iterable $classOrObject * @param mixed $property * @param string $message * * @throws InvalidArgumentException */ public static function allPropertyNotExists($classOrObject, $property, $message = ''); /** * @psalm-pure * @psalm-param null|class-string|object $classOrObject * * @param null|string|object $classOrObject * @param mixed $method * @param string $message * * @throws InvalidArgumentException */ public static function nullOrMethodExists($classOrObject, $method, $message = ''); /** * @psalm-pure * @psalm-param iterable $classOrObject * * @param iterable $classOrObject * @param mixed $method * @param string $message * * @throws InvalidArgumentException */ public static function allMethodExists($classOrObject, $method, $message = ''); /** * @psalm-pure * @psalm-param null|class-string|object $classOrObject * * @param null|string|object $classOrObject * @param mixed $method * @param string $message * * @throws InvalidArgumentException */ public static function nullOrMethodNotExists($classOrObject, $method, $message = ''); /** * @psalm-pure * @psalm-param iterable $classOrObject * * @param iterable $classOrObject * @param mixed $method * @param string $message * * @throws InvalidArgumentException */ public static function allMethodNotExists($classOrObject, $method, $message = ''); /** * @psalm-pure * * @param null|array $array * @param string|int $key * @param string $message * * @throws InvalidArgumentException */ public static function nullOrKeyExists($array, $key, $message = ''); /** * @psalm-pure * * @param iterable $array * @param string|int $key * @param string $message * * @throws InvalidArgumentException */ public static function allKeyExists($array, $key, $message = ''); /** * @psalm-pure * * @param null|array $array * @param string|int $key * @param string $message * * @throws InvalidArgumentException */ public static function nullOrKeyNotExists($array, $key, $message = ''); /** * @psalm-pure * * @param iterable $array * @param string|int $key * @param string $message * * @throws InvalidArgumentException */ public static function allKeyNotExists($array, $key, $message = ''); /** * @psalm-pure * @psalm-assert null|array-key $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrValidArrayKey($value, $message = ''); /** * @psalm-pure * @psalm-assert iterable $value * * @param mixed $value * @param string $message * * @throws InvalidArgumentException */ public static function allValidArrayKey($value, $message = ''); /** * @param null|Countable|array $array * @param int $number * @param string $message * * @throws InvalidArgumentException */ public static function nullOrCount($array, $number, $message = ''); /** * @param iterable $array * @param int $number * @param string $message * * @throws InvalidArgumentException */ public static function allCount($array, $number, $message = ''); /** * @param null|Countable|array $array * @param int|float $min * @param string $message * * @throws InvalidArgumentException */ public static function nullOrMinCount($array, $min, $message = ''); /** * @param iterable $array * @param int|float $min * @param string $message * * @throws InvalidArgumentException */ public static function allMinCount($array, $min, $message = ''); /** * @param null|Countable|array $array * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function nullOrMaxCount($array, $max, $message = ''); /** * @param iterable $array * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function allMaxCount($array, $max, $message = ''); /** * @param null|Countable|array $array * @param int|float $min * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function nullOrCountBetween($array, $min, $max, $message = ''); /** * @param iterable $array * @param int|float $min * @param int|float $max * @param string $message * * @throws InvalidArgumentException */ public static function allCountBetween($array, $min, $max, $message = ''); /** * @psalm-pure * @psalm-assert null|list $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsList($array, $message = ''); /** * @psalm-pure * @psalm-assert iterable $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function allIsList($array, $message = ''); /** * @psalm-pure * @psalm-assert null|non-empty-list $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsNonEmptyList($array, $message = ''); /** * @psalm-pure * @psalm-assert iterable $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function allIsNonEmptyList($array, $message = ''); /** * @psalm-pure * @psalm-template T * @psalm-param null|mixed|array $array * @psalm-assert null|array $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsMap($array, $message = ''); /** * @psalm-pure * @psalm-template T * @psalm-param iterable> $array * @psalm-assert iterable> $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function allIsMap($array, $message = ''); /** * @psalm-pure * @psalm-template T * @psalm-param null|mixed|array $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function nullOrIsNonEmptyMap($array, $message = ''); /** * @psalm-pure * @psalm-template T * @psalm-param iterable> $array * * @param mixed $array * @param string $message * * @throws InvalidArgumentException */ public static function allIsNonEmptyMap($array, $message = ''); /** * @psalm-pure * * @param null|string $value * @param string $message * * @throws InvalidArgumentException */ public static function nullOrUuid($value, $message = ''); /** * @psalm-pure * * @param iterable $value * @param string $message * * @throws InvalidArgumentException */ public static function allUuid($value, $message = ''); /** * @psalm-param class-string $class * * @param null|Closure $expression * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function nullOrThrows($expression, $class = 'Exception', $message = ''); /** * @psalm-param class-string $class * * @param iterable $expression * @param string $class * @param string $message * * @throws InvalidArgumentException */ public static function allThrows($expression, $class = 'Exception', $message = ''); } php-webmozart-assert-1.9.1/tests/000077500000000000000000000000001370262643300167705ustar00rootroot00000000000000php-webmozart-assert-1.9.1/tests/AssertTest.php000066400000000000000000001147641370262643300216170ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Webmozart\Assert\Tests; use ArrayIterator; use ArrayObject; use Exception; use Error; use LogicException; use RuntimeException; use stdClass; use Webmozart\Assert\Assert; /** * @since 1.0 * * @author Bernhard Schussek */ class AssertTest extends BaseTestCase { private static $resource; public static function getResource() { if (!static::$resource) { static::$resource = fopen(__FILE__, 'r'); } return static::$resource; } public static function tearDownAfterClass() { @fclose(self::$resource); } public function getTests() { $resource = self::getResource(); return array( array('string', array('value'), true), array('string', array(''), true), array('string', array(1234), false), array('stringNotEmpty', array('value'), true), array('stringNotEmpty', array('0'), true), array('stringNotEmpty', array(''), false), array('stringNotEmpty', array(1234), false), array('integer', array(123), true), array('integer', array('123'), false), array('integer', array(1.0), false), array('integer', array(1.23), false), array('integerish', array(1.0), true), array('integerish', array(1.23), false), array('integerish', array(123), true), array('integerish', array('123'), true), array('float', array(1.0), true), array('float', array(1.23), true), array('float', array(123), false), array('float', array('123'), false), array('numeric', array(1.0), true), array('numeric', array(1.23), true), array('numeric', array(123), true), array('numeric', array('123'), true), array('numeric', array('foo'), false), array('natural', array(0), true), array('natural', array(1), true), array('natural', array(-1), false), array('natural', array('1'), false), array('natural', array(1.0), false), array('natural', array(1.23), false), array('boolean', array(true), true), array('boolean', array(false), true), array('boolean', array(1), false), array('boolean', array('1'), false), array('scalar', array('1'), true), array('scalar', array(123), true), array('scalar', array(true), true), array('scalar', array(null), false), array('scalar', array(array()), false), array('scalar', array(new stdClass()), false), array('object', array(new stdClass()), true), array('object', array(new RuntimeException()), true), array('object', array(null), false), array('object', array(true), false), array('object', array(1), false), array('object', array(array()), false), array('resource', array($resource), true), array('resource', array($resource, 'stream'), true), array('resource', array($resource, 'other'), false), array('resource', array(1), false), array('isCallable', array('strlen'), true), array('isCallable', array(array($this, 'getTests')), true), array('isCallable', array(function () {}), true), array('isCallable', array(1234), false), array('isCallable', array('foobar'), false), array('isArray', array(array()), true), array('isArray', array(array(1, 2, 3)), true), array('isArray', array(new ArrayIterator(array())), false), array('isArray', array(123), false), array('isArray', array(new stdClass()), false), array('isTraversable', array(array()), true), array('isTraversable', array(array(1, 2, 3)), true), array('isTraversable', array(new ArrayIterator(array())), true), array('isTraversable', array(123), false), array('isTraversable', array(new stdClass()), false), array('isArrayAccessible', array(array()), true), array('isArrayAccessible', array(array(1, 2, 3)), true), array('isArrayAccessible', array(new ArrayObject(array())), true), array('isArrayAccessible', array(123), false), array('isArrayAccessible', array(new stdClass()), false), array('isCountable', array(array()), true), array('isCountable', array(array(1, 2)), true), array('isCountable', array(new ArrayIterator(array())), true), array('isCountable', array(new stdClass()), false), array('isCountable', array(new \SimpleXMLElement('bar')), true), array('isCountable', array('abcd'), false), array('isCountable', array(123), false), array('isIterable', array(array()), true), array('isIterable', array(array(1, 2, 3)), true), array('isIterable', array(new ArrayIterator(array())), true), array('isIterable', array(123), false), array('isIterable', array(new stdClass()), false), array('isInstanceOf', array(new stdClass(), 'stdClass'), true), array('isInstanceOf', array(new Exception(), 'stdClass'), false), array('isInstanceOf', array(123, 'stdClass'), false), array('isInstanceOf', array(array(), 'stdClass'), false), array('isInstanceOf', array(null, 'stdClass'), false), array('notInstanceOf', array(new stdClass(), 'stdClass'), false), array('notInstanceOf', array(new Exception(), 'stdClass'), true), array('notInstanceOf', array(123, 'stdClass'), true), array('notInstanceOf', array(array(), 'stdClass'), true), array('isInstanceOfAny', array(new ArrayIterator(), array('Iterator', 'ArrayAccess')), true), array('isInstanceOfAny', array(new Exception(), array('Exception', 'Countable')), true), array('isInstanceOfAny', array(new Exception(), array('ArrayAccess', 'Countable')), false), array('isInstanceOfAny', array(123, array('stdClass')), false), array('isInstanceOfAny', array(array(), array('stdClass')), false), array('isAOf', array('stdClass', 'stdClass'), true), array('isAOf', array('stdClass', 123), false), array('isAOf', array('Iterator', 'ArrayIterator'), false), array('isAOf', array(123, 'Iterator'), false), array('isAOf', array(array(), 'Iterator'), false), array('isAnyOf', array('ArrayIterator', array('Iterator', 'ArrayAccess')), true), array('isAnyOf', array('ArrayIterator', array(123)), false), array('isAnyOf', array('Exception', array('Exception', 'Countable')), true), array('isAnyOf', array('Exception', array('ArrayAccess', 'Countable')), false), array('isAnyOf', array(123, array('stdClass')), false), array('isAnyOf', array(array(), array('stdClass')), false), array('isNotA', array('stdClass', 'stdClass'), false), array('isNotA', array('stdClass', 123), false), array('isNotA', array('Iterator', 'ArrayIterator'), true), array('isNotA', array(123, 'Iterator'), true), array('isNotA', array(array(), 'Iterator'), true), array('true', array(true), true), array('true', array(false), false), array('true', array(1), false), array('true', array(null), false), array('false', array(false), true), array('false', array(true), false), array('false', array(1), false), array('false', array(0), false), array('false', array(null), false), array('notFalse', array(false), false), array('notFalse', array(true), true), array('notFalse', array(1), true), array('notFalse', array(0), true), array('notFalse', array(null), true), array('null', array(null), true), array('null', array(false), false), array('null', array(0), false), array('notNull', array(false), true), array('notNull', array(0), true), array('notNull', array(null), false), array('isEmpty', array(null), true), array('isEmpty', array(false), true), array('isEmpty', array(0), true), array('isEmpty', array(''), true), array('isEmpty', array(1), false), array('isEmpty', array('a'), false), array('notEmpty', array(1), true), array('notEmpty', array('a'), true), array('notEmpty', array(null), false), array('notEmpty', array(false), false), array('notEmpty', array(0), false), array('notEmpty', array(''), false), array('eq', array(1, 1), true), array('eq', array(1, '1'), true), array('eq', array(1, true), true), array('eq', array(1, 0), false), array('notEq', array(1, 0), true), array('notEq', array(1, 1), false), array('notEq', array(1, '1'), false), array('notEq', array(1, true), false), array('same', array(1, 1), true), array('same', array(1, '1'), false), array('same', array(1, true), false), array('same', array(1, 0), false), array('notSame', array(1, 0), true), array('notSame', array(1, 1), false), array('notSame', array(1, '1'), true), array('notSame', array(1, true), true), array('greaterThan', array(1, 0), true), array('greaterThan', array(0, 0), false), array('greaterThanEq', array(2, 1), true), array('greaterThanEq', array(1, 1), true), array('greaterThanEq', array(0, 1), false), array('lessThan', array(0, 1), true), array('lessThan', array(1, 1), false), array('lessThanEq', array(0, 1), true), array('lessThanEq', array(1, 1), true), array('lessThanEq', array(2, 1), false), array('range', array(1, 1, 2), true), array('range', array(2, 1, 2), true), array('range', array(0, 1, 2), false), array('range', array(3, 1, 2), false), array('oneOf', array(1, array(1, 2, 3)), true), array('oneOf', array(1, array('1', '2', '3')), false), array('inArray', array(1, array(1, 2, 3)), true), array('inArray', array(1, array('1', '2', '3')), false), array('contains', array('abcd', 'ab'), true), array('contains', array('abcd', 'bc'), true), array('contains', array('abcd', 'cd'), true), array('contains', array('abcd', 'de'), false), array('contains', array('', 'de'), false), array('contains', array('äþçð', 'äþ'), true), array('contains', array('äþçð', 'þç'), true), array('contains', array('äþçð', 'çð'), true), array('contains', array('äþçð', 'ðé'), false), array('contains', array('', 'ðé'), false), array('contains', array('あいうえ', 'あい'), true), array('contains', array('あいうえ', 'いう'), true), array('contains', array('あいうえ', 'うえ'), true), array('contains', array('あいうえ', 'えお'), false), array('contains', array('', 'えお'), false), array('contains', array('😄😑☹️', '😄'), true), array('contains', array('😄😑☹️', '😑'), true), array('contains', array('😄😑☹️', '☹️'), true), array('contains', array('😄😑☹️', '😄☹️'), false), array('contains', array('', '😑'), false), array('notContains', array('abcd', 'ab'), false), array('notContains', array('abcd', 'bc'), false), array('notContains', array('abcd', 'cd'), false), array('notContains', array('abcd', 'de'), true), array('notContains', array('', 'de'), true), array('notContains', array('äþçð', 'äþ'), false), array('notContains', array('äþçð', 'þç'), false), array('notContains', array('äþçð', 'çð'), false), array('notContains', array('äþçð', 'ðé'), true), array('notContains', array('', 'ðé'), true), array('notContains', array('あいうえ', 'あい'), false), array('notContains', array('あいうえ', 'いう'), false), array('notContains', array('あいうえ', 'うえ'), false), array('notContains', array('あいうえ', 'えお'), true), array('notContains', array('', 'えお'), true), array('notContains', array('😄😑☹️', '😄'), false), array('notContains', array('😄😑☹️', '😑'), false), array('notContains', array('😄😑☹️', '☹️'), false), array('notContains', array('😄😑☹️', '😄☹️'), true), array('notContains', array('', '😑'), true), array('notWhitespaceOnly', array('abc'), true), array('notWhitespaceOnly', array('123'), true), array('notWhitespaceOnly', array(' abc '), true), array('notWhitespaceOnly', array('a b c'), true), array('notWhitespaceOnly', array(''), false), array('notWhitespaceOnly', array(' '), false), array('notWhitespaceOnly', array("\t"), false), array('notWhitespaceOnly', array("\n"), false), array('notWhitespaceOnly', array("\r"), false), array('notWhitespaceOnly', array("\r\n\t "), false), array('startsWith', array('abcd', 'ab'), true), array('startsWith', array('abcd', 'bc'), false), array('startsWith', array('', 'bc'), false), array('startsWith', array('äþçð', 'äþ'), true), array('startsWith', array('äþçð', 'þç'), false), array('startsWith', array('', 'þç'), false), array('startsWith', array('あいうえ', 'あい'), true), array('startsWith', array('あいうえ', 'いう'), false), array('startsWith', array('', 'いう'), false), array('startsWith', array('😄😑☹️', '😄'), true), array('startsWith', array('😄😑☹️', '😑'), false), array('startsWith', array('', '😑'), false), array('startsWithLetter', array('abcd'), true), array('startsWithLetter', array(array(66)), false), array('startsWithLetter', array('a'), true), array('startsWithLetter', array('a1'), true), array('startsWithLetter', array('1abcd'), false), array('startsWithLetter', array('1'), false), array('startsWithLetter', array(''), false), array('startsWithLetter', array(null), false), array('startsWithLetter', array(66), false), array('notStartsWith', array('abcd', 'ab'), false), array('notStartsWith', array('abcd', 'bc'), true), array('notStartsWith', array('', 'bc'), true), array('notStartsWith', array('äþçð', 'äþ'), false), array('notStartsWith', array('äþçð', 'þç'), true), array('notStartsWith', array('', 'þç'), true), array('notStartsWith', array('あいうえ', 'あい'), false), array('notStartsWith', array('あいうえ', 'いう'), true), array('notStartsWith', array('', 'いう'), true), array('notStartsWith', array('😄😑☹️', '😄'), false), array('notStartsWith', array('😄😑☹️', '😑'), true), array('notStartsWith', array('', '😑'), true), array('endsWith', array('abcd', 'cd'), true), array('endsWith', array('abcd', 'bc'), false), array('endsWith', array('', 'bc'), false), array('endsWith', array('äþçð', 'çð'), true), array('endsWith', array('äþçð', 'þç'), false), array('endsWith', array('', 'þç'), false), array('endsWith', array('あいうえ', 'うえ'), true), array('endsWith', array('あいうえ', 'いう'), false), array('endsWith', array('', 'いう'), false), array('endsWith', array('😄😑☹️', '☹️'), true), array('endsWith', array('😄😑☹️', '😑'), false), array('endsWith', array('', '😑'), false), array('notEndsWith', array('abcd', 'cd'), false), array('notEndsWith', array('abcd', 'bc'), true), array('notEndsWith', array('', 'bc'), true), array('notEndsWith', array('äþçð', 'çð'), false), array('notEndsWith', array('äþçð', 'þç'), true), array('notEndsWith', array('', 'þç'), true), array('notEndsWith', array('あいうえ', 'うえ'), false), array('notEndsWith', array('あいうえ', 'いう'), true), array('notEndsWith', array('', 'いう'), true), array('notEndsWith', array('😄😑☹️', '☹️'), false), array('notEndsWith', array('😄😑☹️', '😑'), true), array('notEndsWith', array('', '😑'), true), array('regex', array('abcd', '~^ab~'), true), array('regex', array('abcd', '~^bc~'), false), array('regex', array('', '~^bc~'), false), array('notRegex', array('abcd', '{^ab}'), false), array('notRegex', array('abcd', '{^bc}'), true), array('notRegex', array('', '{^bc}'), true), array('unicodeLetters', array('abcd'), true), array('unicodeLetters', array('ᴁڅਘธブ乶'), true), array('unicodeLetters', array('ȁȄ'), true), array('unicodeLetters', array('ȁ1Ȅ'), false), array('unicodeLetters', array('©'), false), array('unicodeLetters', array('🙁'), false), array('unicodeLetters', array(''), false), array('alpha', array('abcd'), true), array('alpha', array('ab1cd'), false), array('alpha', array(''), false), array('alpha', array(66), false), array('alpha', array(array()), false), array('digits', array('1234'), true), array('digits', array('12a34'), false), array('digits', array(''), false), array('alnum', array('ab12'), true), array('alnum', array('ab12$'), false), array('alnum', array(''), false), array('lower', array('abcd'), true), array('lower', array('abCd'), false), array('lower', array('ab_d'), false), array('lower', array(''), false), array('upper', array('ABCD'), true), array('upper', array('ABcD'), false), array('upper', array('AB_D'), false), array('upper', array(''), false), array('length', array('abcd', 4), true), array('length', array('abc', 4), false), array('length', array('abcde', 4), false), array('length', array('äbcd', 4), true, true), array('length', array('äbc', 4), false, true), array('length', array('äbcde', 4), false, true), array('length', array('あbcd', 4), true, true), // 'HIRAGANA LETTER A' (U+3042) array('length', array('あbc', 4), false, true), array('length', array('あbcde', 4), false, true), array('minLength', array('abcd', 4), true), array('minLength', array('abcde', 4), true), array('minLength', array('abc', 4), false), array('minLength', array('äbcd', 4), true, true), array('minLength', array('äbcde', 4), true, true), array('minLength', array('äbc', 4), false, true), array('minLength', array('あbcd', 4), true, true), array('minLength', array('あbcde', 4), true, true), array('minLength', array('あbc', 4), false, true), array('maxLength', array('abcd', 4), true), array('maxLength', array('abc', 4), true), array('maxLength', array('abcde', 4), false), array('maxLength', array('äbcd', 4), true, true), array('maxLength', array('äbc', 4), true, true), array('maxLength', array('äbcde', 4), false, true), array('maxLength', array('あbcd', 4), true, true), array('maxLength', array('あbc', 4), true, true), array('maxLength', array('あbcde', 4), false, true), array('lengthBetween', array('abcd', 3, 5), true), array('lengthBetween', array('abc', 3, 5), true), array('lengthBetween', array('abcde', 3, 5), true), array('lengthBetween', array('ab', 3, 5), false), array('lengthBetween', array('abcdef', 3, 5), false), array('lengthBetween', array('äbcd', 3, 5), true, true), array('lengthBetween', array('äbc', 3, 5), true, true), array('lengthBetween', array('äbcde', 3, 5), true, true), array('lengthBetween', array('äb', 3, 5), false, true), array('lengthBetween', array('äbcdef', 3, 5), false, true), array('lengthBetween', array('あbcd', 3, 5), true, true), array('lengthBetween', array('あbc', 3, 5), true, true), array('lengthBetween', array('あbcde', 3, 5), true, true), array('lengthBetween', array('あb', 3, 5), false, true), array('lengthBetween', array('あbcdef', 3, 5), false, true), array('fileExists', array(__FILE__), true), array('fileExists', array(__DIR__), true), array('fileExists', array(__DIR__.'/foobar'), false), array('file', array(__FILE__), true), array('file', array(__DIR__), false), array('file', array(__DIR__.'/foobar'), false), array('directory', array(__DIR__), true), array('directory', array(__FILE__), false), array('directory', array(__DIR__.'/foobar'), false), // no tests for readable()/writable() for now array('classExists', array(__CLASS__), true), array('classExists', array(__NAMESPACE__.'\Foobar'), false), array('subclassOf', array(__CLASS__, 'Webmozart\Assert\Tests\BaseTestCase'), true), array('subclassOf', array(__CLASS__, 'stdClass'), false), array('interfaceExists', array('\Countable'), true), array('interfaceExists', array(__CLASS__), false), array('implementsInterface', array('ArrayIterator', 'Traversable'), true), array('implementsInterface', array(__CLASS__, 'Traversable'), false), array('propertyExists', array((object) array('property' => 0), 'property'), true), array('propertyExists', array((object) array('property' => null), 'property'), true), array('propertyExists', array((object) array('property' => null), 'foo'), false), array('propertyNotExists', array((object) array('property' => 0), 'property'), false), array('propertyNotExists', array((object) array('property' => null), 'property'), false), array('propertyNotExists', array((object) array('property' => null), 'foo'), true), array('methodExists', array('RuntimeException', 'getMessage'), true), array('methodExists', array(new RuntimeException(), 'getMessage'), true), array('methodExists', array('stdClass', 'getMessage'), false), array('methodExists', array(new stdClass(), 'getMessage'), false), array('methodExists', array(null, 'getMessage'), false), array('methodExists', array(true, 'getMessage'), false), array('methodExists', array(1, 'getMessage'), false), array('methodNotExists', array('RuntimeException', 'getMessage'), false), array('methodNotExists', array(new RuntimeException(), 'getMessage'), false), array('methodNotExists', array('stdClass', 'getMessage'), true), array('methodNotExists', array(new stdClass(), 'getMessage'), true), array('methodNotExists', array(null, 'getMessage'), true), array('methodNotExists', array(true, 'getMessage'), true), array('methodNotExists', array(1, 'getMessage'), true), array('keyExists', array(array('key' => 0), 'key'), true), array('keyExists', array(array('key' => null), 'key'), true), array('keyExists', array(array('key' => null), 'foo'), false), array('keyNotExists', array(array('key' => 0), 'key'), false), array('keyNotExists', array(array('key' => null), 'key'), false), array('keyNotExists', array(array('key' => null), 'foo'), true), array('validArrayKey', array('abcd'), true), array('validArrayKey', array(1), true), array('validArrayKey', array(false), false), array('validArrayKey', array(true), false), array('validArrayKey', array(new stdClass()), false), array('validArrayKey', array(new ToStringClass('testString')), false), array('validArrayKey', array(self::getResource()), false), array('count', array(array(0, 1, 2), 3), true), array('count', array(array(0, 1, 2), 2), false), array('minCount', array(array(0), 2), false), array('minCount', array(array(0, 1), 2), true), array('minCount', array(array(0, 1, 2), 2), true), array('maxCount', array(array(0, 1, 2), 2), false), array('maxCount', array(array(0, 1), 2), true), array('maxCount', array(array(0), 2), true), array('countBetween', array(array(0, 1, 2), 4, 5), false), array('countBetween', array(array(0, 1, 2), 3, 5), true), array('countBetween', array(array(0, 1, 2), 1, 2), false), array('countBetween', array(array(0, 1, 2), 2, 5), true), array('countBetween', array(array(0, 1, 2), 2, 3), true), array('isList', array(array(1, 2, 3)), true), array('isList', array(array()), true), array('isList', array(array(0 => 1, 2 => 3)), false), array('isList', array(array('key' => 1, 'foo' => 2)), false), array('isList', array(true), false), array('isList', array(false), false), array('isList', array(array(true)), true), array('isList', array(array(false)), true), array('isList', array(array(array(1), array(2))), true), array('isList', array(array(array('foo' => 'bar'), array('baz' => 'tab'))), true), array('isNonEmptyList', array(array(1, 2, 3)), true), array('isNonEmptyList', array(array()), false), array('isNonEmptyList', array(array(0 => 1, 2 => 3)), false), array('isNonEmptyList', array(array('key' => 1, 'foo' => 2)), false), array('isNonEmptyList', array(true), false), array('isNonEmptyList', array(false), false), array('isNonEmptyList', array(array(true)), true), array('isNonEmptyList', array(array(false)), true), array('isNonEmptyList', array(array(array(1), array(2))), true), array('isNonEmptyList', array(array(array('foo' => 'bar'), array('baz' => 'tab'))), true), array('isMap', array(array('key' => 1, 'foo' => 2)), true), array('isMap', array(array()), true), array('isMap', array(array(1, 2, 3)), false), array('isMap', array(array(0 => 1, 2 => 3)), false), array('isNonEmptyMap', array(array('key' => 1, 'foo' => 2)), true), array('isNonEmptyMap', array(array()), false), array('isNonEmptyMap', array(array(1, 2, 3)), false), array('isNonEmptyMap', array(array(0 => 1, 2 => 3)), false), array('uuid', array('00000000-0000-0000-0000-000000000000'), true), array('uuid', array('urn:ff6f8cb0-c57d-21e1-9b21-0800200c9a66'), true), array('uuid', array('uuid:{ff6f8cb0-c57d-21e1-9b21-0800200c9a66}'), true), array('uuid', array('ff6f8cb0-c57d-21e1-9b21-0800200c9a66'), true), array('uuid', array('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'), true), array('uuid', array('ff6f8cb0-c57d-31e1-9b21-0800200c9a66'), true), array('uuid', array('ff6f8cb0-c57d-41e1-9b21-0800200c9a66'), true), array('uuid', array('ff6f8cb0-c57d-51e1-9b21-0800200c9a66'), true), array('uuid', array('FF6F8CB0-C57D-11E1-9B21-0800200C9A66'), true), array('uuid', array('zf6f8cb0-c57d-11e1-9b21-0800200c9a66'), false), array('uuid', array('af6f8cb0c57d11e19b210800200c9a66'), false), array('uuid', array('ff6f8cb0-c57da-51e1-9b21-0800200c9a66'), false), array('uuid', array('af6f8cb-c57d-11e1-9b21-0800200c9a66'), false), array('uuid', array('3f6f8cb0-c57d-11e1-9b21-0800200c9a6'), false), array('throws', array(function() { throw new LogicException('test'); }, 'LogicException'), true), array('throws', array(function() { throw new LogicException('test'); }, 'IllogicException'), false), array('throws', array(function() { throw new Exception('test'); }), true), array('throws', array(function() { trigger_error('test'); }, 'Throwable'), true, false, 70000), array('throws', array(function() { trigger_error('test'); }, 'Unthrowable'), false, false, 70000), array('throws', array(function() { throw new Error(); }, 'Throwable'), true, true, 70000), array('ip', array('192.168.0.1'), true), array('ip', array(new ToStringClass('192.168.0.1')), true), array('ip', array('255.255.255.255'), true), array('ip', array('0.0.0.0'), true), array('ip', array('2001:0db8:0000:0042:0000:8a2e:0370:7334'), true), array('ip', array('::ffff:192.0.2.1'), true), array('ip', array('::1'), true), array('ip', array('::'), true), array('ip', array('foo'), false), array('ip', array(123), false), array('ip', array(array()), false), array('ip', array(null), false), array('ip', array(false), false), array('ipv4', array('192.168.0.1'), true), array('ipv4', array(new ToStringClass('192.168.0.1')), true), array('ipv4', array('255.255.255.255'), true), array('ipv4', array('0.0.0.0'), true), array('ipv4', array('2001:0db8:0000:0042:0000:8a2e:0370:7334'), false), array('ipv4', array('::ffff:192.0.2.1'), false), array('ipv4', array('::1'), false), array('ipv4', array('::'), false), array('ipv4', array('foo'), false), array('ipv4', array(123), false), array('ipv4', array(array()), false), array('ipv4', array(null), false), array('ipv4', array(false), false), array('ipv6', array('192.168.0.1'), false), array('ipv6', array('255.255.255.255'), false), array('ipv6', array('0.0.0.0'), false), array('ipv6', array('2001:0db8:0000:0042:0000:8a2e:0370:7334'), true), array('ipv6', array(new ToStringClass('2001:0db8:0000:0042:0000:8a2e:0370:7334')), true), array('ipv6', array('::ffff:192.0.2.1'), true), array('ipv6', array('::1'), true), array('ipv6', array('::'), true), array('ipv6', array('foo'), false), array('ipv6', array(123), false), array('ipv6', array(array()), false), array('ipv6', array(null), false), array('ipv6', array(false), false), array('email', array('foo'), false), array('email', array(123), false), array('email', array('foo.com'), false), array('email', array('foo@bar.com'), true), array('email', array(new ToStringClass('foo@bar.com')), true), array('uniqueValues', array(array('qwerty', 'qwerty')), false), array('uniqueValues', array(array('asdfg', 'qwerty')), true), array('uniqueValues', array(array(123, '123')), false), ); } public function getMethods() { $methods = array(); foreach ($this->getTests() as $params) { $methods[$params[0]] = array($params[0]); } return array_values($methods); } /** * @dataProvider getTests */ public function testAssert($method, $args, $success, $multibyte = false, $minVersion = null) { if ($minVersion && PHP_VERSION_ID < $minVersion) { $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); return; } if ($multibyte && !function_exists('mb_strlen')) { $this->markTestSkipped('The function mb_strlen() is not available'); } if (!$success) { $this->setExpectedException('\InvalidArgumentException'); } call_user_func_array(array('Webmozart\Assert\Assert', $method), $args); $this->addToAssertionCount(1); } /** * @dataProvider getTests */ public function testNullOr($method, $args, $success, $multibyte = false, $minVersion = null) { if ($minVersion && PHP_VERSION_ID < $minVersion) { $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); return; } if ($multibyte && !function_exists('mb_strlen')) { $this->markTestSkipped('The function mb_strlen() is not available'); } if (!$success && null !== reset($args)) { $this->setExpectedException('\InvalidArgumentException'); } call_user_func_array(array('Webmozart\Assert\Assert', 'nullOr'.ucfirst($method)), $args); $this->addToAssertionCount(1); } /** * @dataProvider getMethods */ public function testNullOrAcceptsNull($method) { call_user_func(array('Webmozart\Assert\Assert', 'nullOr'.ucfirst($method)), null); $this->addToAssertionCount(1); } /** * @dataProvider getTests */ public function testAllArray($method, $args, $success, $multibyte = false, $minVersion = null) { if ($minVersion && PHP_VERSION_ID < $minVersion) { $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); return; } if ($multibyte && !function_exists('mb_strlen')) { $this->markTestSkipped('The function mb_strlen() is not available'); } if (!$success) { $this->setExpectedException('\InvalidArgumentException'); } $arg = array_shift($args); array_unshift($args, array($arg)); call_user_func_array(array('Webmozart\Assert\Assert', 'all'.ucfirst($method)), $args); $this->addToAssertionCount(1); } /** * @dataProvider getTests */ public function testAllTraversable($method, $args, $success, $multibyte = false, $minVersion = null) { if ($minVersion && PHP_VERSION_ID < $minVersion) { $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); return; } if ($multibyte && !function_exists('mb_strlen')) { $this->markTestSkipped('The function mb_strlen() is not available'); } if (!$success) { $this->setExpectedException('\InvalidArgumentException'); } $arg = array_shift($args); array_unshift($args, new ArrayIterator(array($arg))); call_user_func_array(array('Webmozart\Assert\Assert', 'all'.ucfirst($method)), $args); $this->addToAssertionCount(1); } public function getStringConversions() { return array( array('integer', array('foobar'), 'Expected an integer. Got: string'), array('string', array(1), 'Expected a string. Got: integer'), array('string', array(true), 'Expected a string. Got: boolean'), array('string', array(null), 'Expected a string. Got: NULL'), array('string', array(array()), 'Expected a string. Got: array'), array('string', array(new stdClass()), 'Expected a string. Got: stdClass'), array('string', array(self::getResource()), 'Expected a string. Got: resource'), array('eq', array('1', '2'), 'Expected a value equal to "2". Got: "1"'), array('eq', array(new ToStringClass("XXX"), new ToStringClass("YYY")), 'Expected a value equal to Webmozart\Assert\Tests\ToStringClass: "YYY". Got: Webmozart\Assert\Tests\ToStringClass: "XXX"'), array('eq', array(1, 2), 'Expected a value equal to 2. Got: 1'), array('eq', array(true, false), 'Expected a value equal to false. Got: true'), array('eq', array(true, null), 'Expected a value equal to null. Got: true'), array('eq', array(null, true), 'Expected a value equal to true. Got: null'), array('eq', array(array(1), array(2)), 'Expected a value equal to array. Got: array'), array('eq', array(new ArrayIterator(array()), new stdClass()), 'Expected a value equal to stdClass. Got: ArrayIterator'), array('eq', array(1, self::getResource()), 'Expected a value equal to resource. Got: 1'), array('lessThan', array(new \DateTime('2020-01-01 00:00:00'), new \DateTime('1999-01-01 00:00:00')), 'Expected a value less than DateTime: "1999-01-01T00:00:00+00:00". Got: DateTime: "2020-01-01T00:00:00+00:00"'), ); } /** * @dataProvider getStringConversions */ public function testConvertValuesToStrings($method, $args, $exceptionMessage) { $this->setExpectedException('\InvalidArgumentException', $exceptionMessage); call_user_func_array(array('Webmozart\Assert\Assert', $method), $args); } public function testAnUnknownMethodThrowsABadMethodCall() { $this->setExpectedException('\BadMethodCallException'); Assert::nonExistentMethod(); } } /** * @ignore */ class ToStringClass { /** * @var string */ private $value; public function __construct($value) { $this->value = $value; } public function __toString() { return $this->value; } } php-webmozart-assert-1.9.1/tests/BaseTestCase.php000066400000000000000000000021731370262643300220120ustar00rootroot00000000000000expectException($exceptionName); if($exceptionMessage) { $this->expectExceptionMessage($exceptionMessage); } if( $exceptionCode) { $this->expectExceptionCode($exceptionCode); } return; } parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode); } } php-webmozart-assert-1.9.1/tests/ProjectCodeTest.php000066400000000000000000000126161370262643300225500ustar00rootroot00000000000000getDocComment(); self::$mixinMethodNames = array(); foreach ($rc->getMethods() as $method) { self::$mixinMethodNames[] = $method->name; } } /** * @dataProvider providesMethodNames * * @param string $method */ public function testHasNullOr($method) { $fullMethodName = 'nullOr' . ucfirst($method); if ($method === 'notNull' || $method === 'null') { $this->addToAssertionCount(1); return; } $correct = strpos( (string)self::$assertDocComment,'@method static void ' . $fullMethodName); if (!$correct) { $correct = in_array($fullMethodName, self::$mixinMethodNames, true); } if ($correct === false) { $this->fail(sprintf( 'All methods have a corresponding "nullOr" method, please add the "%s" method to the class level doc comment.', $fullMethodName )); } $this->addToAssertionCount(1); } /** * @dataProvider providesMethodNames * * @param string $method */ public function testHasAll($method) { $fullMethodName = 'all' . ucfirst($method); $correct = strpos((string) self::$assertDocComment,'@method static void ' . $fullMethodName); if (!$correct) { $correct = in_array($fullMethodName, self::$mixinMethodNames, true); } if ($correct === false) { $this->fail(sprintf( 'All methods have a corresponding "all" method, please add the "%s" method to the class level doc comment.', $fullMethodName )); } $this->addToAssertionCount(1); } /** * @dataProvider providesMethodNames * * @param string $method */ public function testIsInReadme($method) { $correct = strpos((string) self::$readmeContent,$method); if($correct === false) { $this->fail(sprintf( 'All methods must be documented in the README.md, please add the "%s" method.', $method )); } $this->addToAssertionCount(1); } /** * @dataProvider provideMethods * * @param ReflectionMethod $method */ public function testHasThrowsAnnotation($method) { $doc = $method->getDocComment(); $this->assertNotFalse( $doc, sprintf( 'Expected a doc comment on the "%s" method, but none found', $method->getName() ) ); $this->assertContains( '@throws InvalidArgumentException', $doc, sprintf( 'Expected method "%s" to have an @throws InvalidArgumentException annotation, but none found', $method->getName() ) ); } /** * @dataProvider provideMethods * * @param ReflectionMethod $method */ public function testHasCorrespondingStaticAnalysisFile($method) { $doc = $method->getDocComment(); if($doc === false || strpos($doc, '@psalm-assert') === false) { $this->addToAssertionCount(1); return; } $this->assertFileExists( __DIR__ . '/static-analysis/assert-'. $method->getName() . '.php' ); } public function testMixinIsUpToDateVersion() { if (version_compare(PHP_VERSION, '7.2.0') < 0) { $this->markTestSkipped('mixin generator is implemented using php 7.2 features'); return; } require_once __DIR__ . '/../bin/src/MixinGenerator.php'; $generator = new MixinGenerator(); $actual = file_get_contents(__DIR__ . '/../src/Mixin.php'); $this->assertEquals($generator->generate(), $actual, 'please regenerate Mixin with `php bin/generate.php` command in the project root'); } /** * @return array */ public function providesMethodNames() { return array_map(function($value) { return array($value->getName()); }, $this->getMethods()); } /** * @return array */ public function provideMethods() { return array_map(function($value) { return array($value); }, $this->getMethods()); } /** * @return array */ private function getMethods() { static $methods; if ($methods !== null) { return $methods; } $rc = new ReflectionClass('\Webmozart\Assert\Assert'); $methods = array(); $rcMethods = $rc->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($rcMethods as $rcMethod) { $methodName = $rcMethod->getName(); if (strpos($methodName, '__') === 0) { continue; } $methods[] = $rcMethod; } return $methods; } } php-webmozart-assert-1.9.1/tests/static-analysis/000077500000000000000000000000001370262643300221005ustar00rootroot00000000000000php-webmozart-assert-1.9.1/tests/static-analysis/assert-alnum.php000066400000000000000000000010061370262643300252210ustar00rootroot00000000000000 $value * * @return iterable */ function allAllnum(iterable $value): iterable { Assert::allAlnum($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-alpha.php000066400000000000000000000010301370262643300251670ustar00rootroot00000000000000 */ function allBoolean($value): iterable { Assert::allBoolean($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-classExists.php000066400000000000000000000011051370262643300264120ustar00rootroot00000000000000 */ function allClassExists($value): iterable { Assert::allClassExists($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-contains.php000066400000000000000000000011641370262643300257300ustar00rootroot00000000000000 $value * * @return iterable */ function allContains(iterable $value, string $subString): iterable { Assert::allContains($value, $subString); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-count.php000066400000000000000000000012401370262643300252350ustar00rootroot00000000000000 $value * * @return iterable */ function allCount(iterable $value, int $number): iterable { Assert::allCount($value, $number); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-countBetween.php000066400000000000000000000015461370262643300265600ustar00rootroot00000000000000 $value * @param int|float $min * @param int|float $max * * @return iterable */ function allCountBetween(iterable $value, $min, $max): iterable { Assert::allCountBetween($value, $min, $max); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-digits.php000066400000000000000000000010131370262643300253660ustar00rootroot00000000000000 $value * * @return iterable */ function allDigits(iterable $value): iterable { Assert::allDigits($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-directory.php000066400000000000000000000007721370262643300261220ustar00rootroot00000000000000 $value * * @return iterable */ function allEndsWith(iterable $value, string $suffix): iterable { Assert::allEndsWith($value, $suffix); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-eq.php000066400000000000000000000011161370262643300245140ustar00rootroot00000000000000 */ function allFalse($value): iterable { Assert::allFalse($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-file.php000066400000000000000000000007341370262643300250330ustar00rootroot00000000000000 */ function allFloat($value): iterable { Assert::allFloat($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-greaterThan.php000066400000000000000000000012611370262643300263540ustar00rootroot00000000000000 */ function implementsInterface($value): string { Assert::implementsInterface($value, Serializable::class); return $value; } /** * @psalm-pure * * @param mixed $value * * @return null|class-string */ function nullOrImplementsInterface($value): ?string { Assert::nullOrImplementsInterface($value, Serializable::class); return $value; } /** * @psalm-pure * * @param mixed $value * * @return iterable> */ function allImplementsInterface($value): iterable { Assert::allImplementsInterface($value, Serializable::class); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-inArray.php000066400000000000000000000011541370262643300255160ustar00rootroot00000000000000 */ function allInteger($value): iterable { Assert::allInteger($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-integerish.php000066400000000000000000000011251370262643300262500ustar00rootroot00000000000000 */ function allIntegerish($value): iterable { Assert::allIntegerish($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-interfaceExists.php000066400000000000000000000011351370262643300272500ustar00rootroot00000000000000 */ function allInterfaceExists($value): iterable { Assert::allInterfaceExists($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-ip.php000066400000000000000000000007201370262643300245170ustar00rootroot00000000000000|Serializable */ function isAOf($value) { Assert::isAOf($value, Serializable::class); return $value; } /** * @psalm-pure * * @param null|object|string $value * * @psalm-return null|class-string|Serializable */ function nullOrIsAOf($value) { Assert::nullOrIsAOf($value, Serializable::class); return $value; } /** * @psalm-pure * * @param iterable $value * * @return iterable|Serializable> */ function allIsAOf($value) { Assert::allIsAOf($value, Serializable::class); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isAnyOf.php000066400000000000000000000014771370262643300254710ustar00rootroot00000000000000 $classes * * @return object|string */ function isAnyOf($value, array $classes) { Assert::isAnyOf($value, $classes); return $value; } /** * @psalm-pure * * @param null|object|string $value * @param array $classes * * @return null|object|string */ function nullOrIsAnyOf($value, array $classes) { Assert::nullOrIsAnyOf($value, $classes); return $value; } /** * @psalm-pure * * @param iterable $value * @param array $classes * * @return iterable */ function allIsAnyOf($value, array $classes): iterable { Assert::allIsAnyOf($value, $classes); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isArray.php000066400000000000000000000010371370262643300255230ustar00rootroot00000000000000 */ function allIsArray($value): iterable { Assert::allIsArray($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isArrayAccessible.php000066400000000000000000000012561370262643300275040ustar00rootroot00000000000000 */ function allIsArrayAccessible($value): iterable { Assert::allIsArrayAccessible($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isCallable.php000066400000000000000000000010721370262643300261430ustar00rootroot00000000000000 */ function allIsCallable($value): iterable { Assert::allIsCallable($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isCountable.php000066400000000000000000000011461370262643300263620ustar00rootroot00000000000000 */ function allIsCountable($value) { Assert::allIsCountable($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isEmpty.php000066400000000000000000000021031370262643300255360ustar00rootroot00000000000000 */ function isEmptyArray(array $value) { Assert::isEmpty($value); return $value; } /** * @psalm-pure * * @return null|empty */ function nullOrIsEmpty(?object $value) { Assert::nullOrIsEmpty($value); return $value; } /** * @psalm-pure * * @param mixed $value * * @return iterable */ function allIsEmpty($value): iterable { Assert::allIsEmpty($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isInstanceOf.php000066400000000000000000000012431370262643300264750ustar00rootroot00000000000000 */ function allIsInstanceOf($value): iterable { Assert::allIsInstanceOf($value, Serializable::class); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isInstanceOfAny.php000066400000000000000000000014271370262643300271510ustar00rootroot00000000000000 $classes * * @return mixed */ function isInstanceOfAny($value, array $classes) { Assert::isInstanceOfAny($value, $classes); return $value; } /** * @psalm-pure * * @param mixed $value * @param array $classes * * @return mixed */ function nullOrIsInstanceOfAny($value, array $classes) { Assert::nullOrIsInstanceOfAny($value, $classes); return $value; } /** * @psalm-pure * * @param mixed $value * @param array $classes * * @return mixed */ function allIsInstanceOfAny($value, array $classes) { Assert::allIsInstanceOfAny($value, $classes); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isIterable.php000066400000000000000000000010721370262643300261730ustar00rootroot00000000000000 */ function allIsIterable($value): iterable { Assert::allIsIterable($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isList.php000066400000000000000000000014311370262643300253560ustar00rootroot00000000000000 */ function isList($value): array { Assert::isList($value); return $value; } /** * @psalm-pure * * @param array<\stdClass> $value * * @return list<\stdClass> */ function isListWithKnownType(array $value): array { Assert::isList($value); return $value; } /** * @psalm-pure * * @param mixed $value * * @return null|list */ function nullOrIsList($value): ?array { Assert::nullOrIsList($value); return $value; } /** * @psalm-pure * * @param mixed $value * * @return iterable> */ function allIsList($value): iterable { Assert::allIsList($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isMap.php000066400000000000000000000022431370262643300251620ustar00rootroot00000000000000 */ function isMap($value): array { Assert::isMap($value); return $value; } /** * Verifying that the type of the elements in the array is preserved by the assertion * * @psalm-pure * * @param array $value * * @return array */ function isMapWithKnownType(array $value): array { Assert::isMap($value); return $value; } /** * @psalm-pure * * @param array $value * * @return array */ function isMapWithEmptyArray(array $value): array { Assert::isMap($value); Assert::isEmpty($value); return $value; } /** * @psalm-pure * * @param mixed $value * * @return null|array */ function nullOrIsMap($value): ?array { Assert::nullOrIsMap($value); return $value; } /** * @psalm-pure * * @param iterable> $value * * @return iterable> */ function allIsMap(iterable $value): iterable { Assert::allIsMap($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isNonEmptyList.php000066400000000000000000000012461370262643300270540ustar00rootroot00000000000000 */ function isNonEmptyList($value): array { Assert::isNonEmptyList($value); return $value; } /** * @psalm-pure * * @param mixed $value * * @return null|non-empty-list */ function nullOrIsNonEmptyList($value): ?array { Assert::nullOrIsNonEmptyList($value); return $value; } /** * @psalm-pure * * @param mixed $value * * @return iterable> */ function allIsNonEmptyList($value): iterable { Assert::allIsNonEmptyList($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isNonEmptyMap.php000066400000000000000000000017461370262643300266630ustar00rootroot00000000000000 */ function isNonEmptyMap($value): array { Assert::isNonEmptyMap($value); return $value; } /** * Verifying that the type of the elements in the array is preserved by the assertion * * @psalm-pure * * @param array $value * * @return array */ function isNonEmptyMapWithKnownType(array $value): array { Assert::isNonEmptyMap($value); return $value; } /** * @psalm-pure * * @param mixed $value * * @return mixed */ function nullOrIsNonEmptyMap($value) { Assert::nullOrIsNonEmptyMap($value); return $value; } /** * @psalm-pure * * @param iterable> $value * * @return iterable> */ function allIsNonEmptyMap(iterable $value): iterable { Assert::allIsNonEmptyMap($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isNotA.php000066400000000000000000000013701370262643300253060ustar00rootroot00000000000000 $value * @param class-string $class * * @return iterable */ function allIsNotA($value, $class): iterable { Assert::allIsNotA($value, $class); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-isTraversable.php000066400000000000000000000013201370262643300267120ustar00rootroot00000000000000 */ function allIsTraversable($value): iterable { /** @psalm-suppress DeprecatedMethod */ Assert::allIsTraversable($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-keyExists.php000066400000000000000000000012141370262643300260760ustar00rootroot00000000000000 $array * @param array-key $key * * @return iterable */ function allKeyExists(iterable $array, $key): iterable { Assert::allKeyExists($array, $key); return $array; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-keyNotExists.php000066400000000000000000000012411370262643300265570ustar00rootroot00000000000000 $array * * @param array-key $key * * @return iterable */ function allKeyNotExists(iterable $array, $key): iterable { Assert::allKeyNotExists($array, $key); return $array; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-length.php000066400000000000000000000011151370262643300253670ustar00rootroot00000000000000 $value * * @return iterable */ function allLength(iterable $value, int $length): iterable { Assert::allLength($value, $length); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-lengthBetween.php000066400000000000000000000014311370262643300267020ustar00rootroot00000000000000 $value * @param int|float $min * @param int|float $max * * @return iterable */ function allLengthBetween(iterable $value, $min, $max): iterable { Assert::allLengthBetween($value, $min, $max); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-lessThan.php000066400000000000000000000012371370262643300256740ustar00rootroot00000000000000 $value * * @return iterable */ function allLower(iterable $value): iterable { Assert::allLower($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-maxCount.php000066400000000000000000000013371370262643300257120ustar00rootroot00000000000000 $array * @param int|float $max * * @return iterable */ function allMaxCount(iterable $array, $max): iterable { Assert::allMaxCount($array, $max); return $array; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-maxLength.php000066400000000000000000000012221370262643300260340ustar00rootroot00000000000000 $value * @param int|float $max * * @return iterable */ function allMaxLength(iterable $value, $max): iterable { Assert::allMaxLength($value, $max); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-methodExists.php000066400000000000000000000016451370262643300265760ustar00rootroot00000000000000 $classOrObject * @param mixed $method * * @return iterable */ function allMethodExists(iterable $classOrObject, $method): iterable { Assert::allMethodExists($classOrObject, $method); return $classOrObject; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-methodNotExists.php000066400000000000000000000016671370262643300272630ustar00rootroot00000000000000 $classOrObject * @param mixed $method * * @return iterable */ function allMethodNotExists(iterable $classOrObject, $method): iterable { Assert::allMethodNotExists($classOrObject, $method); return $classOrObject; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-minCount.php000066400000000000000000000013141370262643300257030ustar00rootroot00000000000000 $array * @param int|float $min * * @return iterable */ function allMinCount($array, $min) { Assert::allMinCount($array, $min); return $array; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-minLength.php000066400000000000000000000012221370262643300260320ustar00rootroot00000000000000 $value * @param int|float $min * * @return iterable */ function allMinLength(iterable $value, $min): iterable { Assert::allMinLength($value, $min); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-natural.php000066400000000000000000000010311370262643300255510ustar00rootroot00000000000000 */ function allNatural($value): iterable { Assert::allNatural($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-notContains.php000066400000000000000000000012061370262643300264060ustar00rootroot00000000000000 $value * * @return iterable */ function allNotContains(iterable $value, string $subString): iterable { Assert::allNotContains($value, $subString); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-notEmpty.php000066400000000000000000000017041370262643300257310ustar00rootroot00000000000000 $class * * @return mixed */ function nullOrNotInstanceOf($value, $class) { Assert::nullOrNotInstanceOf($value, $class); return $value; } /** * @psalm-pure * @psalm-template T of object * * @param mixed $value * @param class-string $class * * @return mixed */ function allNotInstanceOf($value, $class) { Assert::allNotInstanceOf($value, $class); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-notNull.php000066400000000000000000000005461370262643300255500ustar00rootroot00000000000000 $value * * @return iterable */ function allNotRegex(iterable $value, string $pattern): iterable { Assert::allNotRegex($value, $pattern); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-notSame.php000066400000000000000000000012421370262643300255150ustar00rootroot00000000000000 $value * * @return iterable */ function allNotWhitespaceOnly(iterable $value): iterable { Assert::allNotWhitespaceOnly($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-null.php000066400000000000000000000006121370262643300250610ustar00rootroot00000000000000 */ function allNull($value): iterable { Assert::allNull($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-numeric.php000066400000000000000000000011031370262643300255450ustar00rootroot00000000000000 */ function allNumeric($value): iterable { Assert::allNumeric($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-object.php000066400000000000000000000010341370262643300253540ustar00rootroot00000000000000 */ function allObject($value): iterable { Assert::allObject($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-oneOf.php000066400000000000000000000011401370262643300251520ustar00rootroot00000000000000 $classOrObject * @param mixed $property * * @return iterable */ function allPropertyExists(iterable $classOrObject, $property): iterable { Assert::allPropertyExists($classOrObject, $property); return $classOrObject; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-propertyNotExists.php000066400000000000000000000017251370262643300276620ustar00rootroot00000000000000 $classOrObject * @param mixed $property * * @return iterable */ function allPropertyNotExists(iterable $classOrObject, $property): iterable { Assert::allPropertyNotExists($classOrObject, $property); return $classOrObject; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-psalm-notRedundant.php000066400000000000000000000007371370262643300276760ustar00rootroot00000000000000 $value * * @return ArrayIterator */ function preserveContainerAllArrayIterator($value) { Assert::allString($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-psalm-preserveStringType.php000066400000000000000000000004311370262643300311040ustar00rootroot00000000000000 $value * * @return iterable */ function allReadable(iterable $value): iterable { Assert::allReadable($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-regex.php000066400000000000000000000011261370262643300252220ustar00rootroot00000000000000 $value * * @return iterable */ function allRegex(iterable $value, string $pattern): iterable { Assert::allRegex($value, $pattern); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-resource.php000066400000000000000000000013121370262643300257340ustar00rootroot00000000000000 */ function allResource($value, $type): iterable { Assert::allResource($value, $type); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-same.php000066400000000000000000000012201370262643300250300ustar00rootroot00000000000000 */ function allScalar($value): iterable { Assert::allScalar($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-startsWith.php000066400000000000000000000011561370262643300262670ustar00rootroot00000000000000 $value * * @return iterable */ function allStartsWith(iterable $value, string $prefix): iterable { Assert::allStartsWith($value, $prefix); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-startsWithLetter.php000066400000000000000000000012451370262643300274460ustar00rootroot00000000000000 */ function allString($value): iterable { Assert::allString($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-stringNotEmpty.php000066400000000000000000000012311370262643300271130ustar00rootroot00000000000000 */ function allStringNotEmpty($value): iterable { Assert::allStringNotEmpty($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-subclassOf.php000066400000000000000000000013361370262643300262170ustar00rootroot00000000000000|stdClass */ function subclassOf($value) { Assert::subclassOf($value, stdClass::class); return $value; } /** * @psalm-pure * * @param mixed $value * * @return null|class-string|stdClass */ function nullOrSubclassOf($value) { Assert::nullOrSubclassOf($value, stdClass::class); return $value; } /** * @psalm-pure * * @param mixed $value * * @return iterable|stdClass> */ function allSubclassOf($value): iterable { Assert::allSubclassOf($value, stdClass::class); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-throws.php000066400000000000000000000012501370262643300254340ustar00rootroot00000000000000 $class */ function throws(Closure $value, $class): Closure { Assert::throws($value, $class); return $value; } /** * @param class-string $class */ function nullOrThrows(?Closure $value, $class): ?Closure { Assert::nullOrThrows($value, $class); return $value; } /** * @param iterable $value * @param class-string $class * * @return iterable */ function allThrows(iterable $value, $class): iterable { Assert::allThrows($value, $class); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-true.php000066400000000000000000000010651370262643300250710ustar00rootroot00000000000000 */ function allTrue($value): iterable { Assert::allTrue($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-unicodeLetters.php000066400000000000000000000011161370262643300271000ustar00rootroot00000000000000 $values * * @return iterable */ function allUniqueValues(iterable $values): iterable { Assert::allUniqueValues($values); return $values; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-upper.php000066400000000000000000000010051370262643300252370ustar00rootroot00000000000000 $value * * @return iterable */ function allUpper(iterable $value): iterable { Assert::allUpper($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-uuid.php000066400000000000000000000007771370262643300250710ustar00rootroot00000000000000 $value * * @return iterable */ function allUuid(iterable $value): iterable { Assert::allUuid($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-validArrayKey.php000066400000000000000000000011551370262643300266610ustar00rootroot00000000000000 */ function allValidArrayKey($value): iterable { Assert::allValidArrayKey($value); return $value; } php-webmozart-assert-1.9.1/tests/static-analysis/assert-writable.php000066400000000000000000000007271370262643300257270ustar00rootroot00000000000000 $value * * @return iterable */ function allWritable(iterable $value): iterable { Assert::allWritable($value); return $value; }