update phpstan to 1.1.2; update php-qrcode to 3.4.1

This commit is contained in:
Andrew Dolgov 2021-11-15 18:33:35 +03:00
parent 109b702ed0
commit 4c37fa4b41
29 changed files with 1397 additions and 1750 deletions

View File

@ -19,6 +19,17 @@
"assertion",
"validation"
],
"config": {
"sort-packages": true
},
"require": {
"php": "^7"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"phpstan/phpstan-shim": "*",
"phpunit/phpunit": ">=6.0.0 <8"
},
"autoload": {
"psr-4": {
"Assert\\": "lib/Assert"
@ -35,29 +46,11 @@
"tests/Assert/Tests/Fixtures/functions.php"
]
},
"config": {
"sort-packages": true
},
"require": {
"php": "^7",
"ext-simplexml": "*",
"ext-mbstring": "*",
"ext-ctype": "*",
"ext-json": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"phpstan/phpstan-shim": "*",
"phpunit/phpunit": ">=6.0.0 <8"
},
"scripts": {
"assert:generate-docs": "php bin/generate_method_docs.php",
"assert:cs-lint": "php-cs-fixer fix --diff -vvv --dry-run",
"assert:cs-fix": "php-cs-fixer fix . -vvv || true",
"assert:sa-code": "vendor/bin/phpstan analyse --configuration=phpstan-code.neon --no-progress --ansi -l 7 bin lib",
"assert:sa-tests": "vendor/bin/phpstan analyse --configuration=phpstan-tests.neon --no-progress --ansi -l 7 tests"
},
"suggest": {
"ext-intl": "Needed to allow Assertion::count(), Assertion::isCountable(), Assertion::minCount(), and Assertion::maxCount() to operate on ResourceBundles"
}
}

View File

@ -31,12 +31,6 @@ abstract class Assert
* The invocation of this method starts an assertion chain
* that is happening on the passed value.
*
* @param mixed $value
* @param string|callable|null $defaultMessage
* @param string|null $defaultPropertyPath
*
* @return AssertionChain
*
* @example
*
* Assert::that($value)->notEmpty()->integer();
@ -44,8 +38,14 @@ abstract class Assert
*
* The assertion chain can be stateful, that means be careful when you reuse
* it. You should never pass around the chain.
*
* @param mixed $value
* @param string $defaultMessage
* @param string $defaultPropertyPath
*
* @return \Assert\AssertionChain
*/
public static function that($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
public static function that($value, $defaultMessage = null, $defaultPropertyPath = null)
{
$assertionChain = new AssertionChain($value, $defaultMessage, $defaultPropertyPath);
@ -55,13 +55,13 @@ abstract class Assert
/**
* Start validation on a set of values, returns {@link AssertionChain}.
*
* @param mixed $values
* @param string|callable|null $defaultMessage
* @param string|null $defaultPropertyPath
* @param mixed $values
* @param string $defaultMessage
* @param string $defaultPropertyPath
*
* @return AssertionChain
* @return \Assert\AssertionChain
*/
public static function thatAll($values, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
public static function thatAll($values, $defaultMessage = null, $defaultPropertyPath = null)
{
return static::that($values, $defaultMessage, $defaultPropertyPath)->all();
}
@ -69,13 +69,13 @@ abstract class Assert
/**
* Start validation and allow NULL, returns {@link AssertionChain}.
*
* @param mixed $value
* @param string|callable|null $defaultMessage
* @param string|null $defaultPropertyPath
* @param mixed $value
* @param string $defaultMessage
* @param string $defaultPropertyPath
*
* @return AssertionChain
* @return \Assert\AssertionChain
*/
public static function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
public static function thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null)
{
return static::that($value, $defaultMessage, $defaultPropertyPath)->nullOr();
}
@ -83,14 +83,15 @@ abstract class Assert
/**
* Create a lazy assertion object.
*
* @return LazyAssertion
* @return \Assert\LazyAssertion
*/
public static function lazy(): LazyAssertion
public static function lazy()
{
$lazyAssertion = new LazyAssertion();
return $lazyAssertion
->setAssertClass(\get_called_class())
->setExceptionClass(static::$lazyAssertionExceptionClass);
->setExceptionClass(static::$lazyAssertionExceptionClass)
;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -24,15 +24,15 @@ use ReflectionClass;
*
* @method AssertionChain alnum(string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric.
* @method AssertionChain base64(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined.
* @method AssertionChain between(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit.
* @method AssertionChain betweenExclusive(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit.
* @method AssertionChain between(mixed $lowerLimit, mixed $upperLimit, string $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit.
* @method AssertionChain betweenExclusive(mixed $lowerLimit, mixed $upperLimit, string $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit.
* @method AssertionChain betweenLength(int $minLength, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string length is between min and max lengths.
* @method AssertionChain boolean(string|callable $message = null, string $propertyPath = null) Assert that value is php boolean.
* @method AssertionChain choice(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices.
* @method AssertionChain choicesNotEmpty(array $choices, string|callable $message = null, string $propertyPath = null) Determines if the values array has every choice as key and that this choice has content.
* @method AssertionChain classExists(string|callable $message = null, string $propertyPath = null) Assert that the class exists.
* @method AssertionChain contains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars.
* @method AssertionChain count(int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count.
* @method AssertionChain count(int $count, string $message = null, string $propertyPath = null) Assert that the count of countable is equal to count.
* @method AssertionChain date(string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format.
* @method AssertionChain defined(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined.
* @method AssertionChain digit(string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit.
@ -73,23 +73,23 @@ use ReflectionClass;
* @method AssertionChain lessOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit.
* @method AssertionChain lessThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit.
* @method AssertionChain max(mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit.
* @method AssertionChain maxCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements.
* @method AssertionChain maxCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable have at most $count elements.
* @method AssertionChain maxLength(int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars.
* @method AssertionChain methodExists(mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object.
* @method AssertionChain min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit.
* @method AssertionChain minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements.
* @method AssertionChain minCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable have at least $count elements.
* @method AssertionChain minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long.
* @method AssertionChain noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty.
* @method AssertionChain notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank.
* @method AssertionChain notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars.
* @method AssertionChain notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty.
* @method AssertionChain notEmptyKey(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object and its value is not empty.
* @method AssertionChain notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==).
* @method AssertionChain notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using == ).
* @method AssertionChain notInArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices.
* @method AssertionChain notIsInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name.
* @method AssertionChain notNull(string|callable $message = null, string $propertyPath = null) Assert that value is not null.
* @method AssertionChain notRegex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex.
* @method AssertionChain notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===).
* @method AssertionChain notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using === ).
* @method AssertionChain null(string|callable $message = null, string $propertyPath = null) Assert that value is null.
* @method AssertionChain numeric(string|callable $message = null, string $propertyPath = null) Assert that value is numeric.
* @method AssertionChain objectOrClass(string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists.
@ -113,19 +113,8 @@ use ReflectionClass;
*/
class AssertionChain
{
/**
* @var mixed
*/
private $value;
/**
* @var string|callable|null
*/
private $defaultMessage;
/**
* @var string|null
*/
private $defaultPropertyPath;
/**
@ -145,14 +134,7 @@ class AssertionChain
/** @var string|Assertion Class to use for assertion calls */
private $assertionClassName = 'Assert\Assertion';
/**
* AssertionChain constructor.
*
* @param mixed $value
* @param string|callable|null $defaultMessage
* @param string|null $defaultPropertyPath
*/
public function __construct($value, $defaultMessage = null, string $defaultPropertyPath = null)
public function __construct($value, $defaultMessage = null, $defaultPropertyPath = null)
{
$this->value = $value;
$this->defaultMessage = $defaultMessage;
@ -163,11 +145,11 @@ class AssertionChain
* Call assertion on the current value in the chain.
*
* @param string $methodName
* @param array $args
* @param array $args
*
* @return AssertionChain
* @return \Assert\AssertionChain
*/
public function __call($methodName, $args): AssertionChain
public function __call($methodName, $args)
{
if (true === $this->alwaysValid) {
return $this;
@ -209,9 +191,9 @@ class AssertionChain
/**
* Switch chain into validation mode for an array of values.
*
* @return AssertionChain
* @return \Assert\AssertionChain
*/
public function all(): AssertionChain
public function all()
{
$this->all = true;
@ -221,9 +203,9 @@ class AssertionChain
/**
* Switch chain into mode allowing nulls, ignoring further assertions.
*
* @return AssertionChain
* @return \Assert\AssertionChain
*/
public function nullOr(): AssertionChain
public function nullOr()
{
if (null === $this->value) {
$this->alwaysValid = true;
@ -237,7 +219,7 @@ class AssertionChain
*
* @return $this
*/
public function setAssertionClassName($className): AssertionChain
public function setAssertionClassName($className)
{
if (!\is_string($className)) {
throw new LogicException('Exception class name must be passed as a string');

View File

@ -18,18 +18,9 @@ use Throwable;
interface AssertionFailedException extends Throwable
{
/**
* @return string|null
*/
public function getPropertyPath();
/**
* @return mixed
*/
public function getValue();
/**
* @return array
*/
public function getConstraints(): array;
public function getConstraints();
}

View File

@ -16,22 +16,11 @@ namespace Assert;
class InvalidArgumentException extends \InvalidArgumentException implements AssertionFailedException
{
/**
* @var string|null
*/
private $propertyPath;
/**
* @var mixed
*/
private $value;
/**
* @var array
*/
private $constraints;
public function __construct($message, $code, string $propertyPath = null, $value = null, array $constraints = [])
public function __construct($message, $code, $propertyPath, $value, array $constraints = [])
{
parent::__construct($message, $code);
@ -47,7 +36,7 @@ class InvalidArgumentException extends \InvalidArgumentException implements Asse
* Useful to transport information about the nature of the error
* back to higher layers.
*
* @return string|null
* @return string
*/
public function getPropertyPath()
{
@ -69,7 +58,7 @@ class InvalidArgumentException extends \InvalidArgumentException implements Asse
*
* @return array
*/
public function getConstraints(): array
public function getConstraints()
{
return $this->constraints;
}

View File

@ -21,96 +21,96 @@ use LogicException;
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*
* @method LazyAssertion alnum(string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric.
* @method LazyAssertion base64(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined.
* @method LazyAssertion between(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit.
* @method LazyAssertion betweenExclusive(mixed $lowerLimit, mixed $upperLimit, string|callable $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit.
* @method LazyAssertion betweenLength(int $minLength, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string length is between min and max lengths.
* @method LazyAssertion boolean(string|callable $message = null, string $propertyPath = null) Assert that value is php boolean.
* @method LazyAssertion choice(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices.
* @method LazyAssertion choicesNotEmpty(array $choices, string|callable $message = null, string $propertyPath = null) Determines if the values array has every choice as key and that this choice has content.
* @method LazyAssertion classExists(string|callable $message = null, string $propertyPath = null) Assert that the class exists.
* @method LazyAssertion contains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars.
* @method LazyAssertion count(int $count, string|callable $message = null, string $propertyPath = null) Assert that the count of countable is equal to count.
* @method LazyAssertion date(string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format.
* @method LazyAssertion defined(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined.
* @method LazyAssertion digit(string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit.
* @method LazyAssertion directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists.
* @method LazyAssertion e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number.
* @method LazyAssertion email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL).
* @method LazyAssertion endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars.
* @method LazyAssertion eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==).
* @method LazyAssertion eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset.
* @method LazyAssertion extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded.
* @method LazyAssertion extensionVersion(string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed.
* @method LazyAssertion false(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False.
* @method LazyAssertion file(string|callable $message = null, string $propertyPath = null) Assert that a file exists.
* @method LazyAssertion float(string|callable $message = null, string $propertyPath = null) Assert that value is a php float.
* @method LazyAssertion greaterOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit.
* @method LazyAssertion greaterThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit.
* @method LazyAssertion implementsInterface(string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface.
* @method LazyAssertion inArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. This is an alias of Assertion::choice().
* @method LazyAssertion integer(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer.
* @method LazyAssertion integerish(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish.
* @method LazyAssertion interfaceExists(string|callable $message = null, string $propertyPath = null) Assert that the interface exists.
* @method LazyAssertion ip(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address.
* @method LazyAssertion ipv4(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address.
* @method LazyAssertion ipv6(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address.
* @method LazyAssertion isArray(string|callable $message = null, string $propertyPath = null) Assert that value is an array.
* @method LazyAssertion isArrayAccessible(string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object.
* @method LazyAssertion isCallable(string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable.
* @method LazyAssertion isCountable(string|callable $message = null, string $propertyPath = null) Assert that value is countable.
* @method LazyAssertion isInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name.
* @method LazyAssertion isJsonString(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string.
* @method LazyAssertion isObject(string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object.
* @method LazyAssertion isResource(string|callable $message = null, string $propertyPath = null) Assert that value is a resource.
* @method LazyAssertion isTraversable(string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object.
* @method LazyAssertion keyExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array.
* @method LazyAssertion keyIsset(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset().
* @method LazyAssertion keyNotExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array.
* @method LazyAssertion length(int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length.
* @method LazyAssertion lessOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit.
* @method LazyAssertion lessThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit.
* @method LazyAssertion max(mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit.
* @method LazyAssertion maxCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at most $count elements.
* @method LazyAssertion maxLength(int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars.
* @method LazyAssertion methodExists(mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object.
* @method LazyAssertion min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit.
* @method LazyAssertion minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements.
* @method LazyAssertion minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long.
* @method LazyAssertion noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty.
* @method LazyAssertion notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank.
* @method LazyAssertion notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars.
* @method LazyAssertion notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty.
* @method LazyAssertion notEmptyKey(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object and its value is not empty.
* @method LazyAssertion notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using ==).
* @method LazyAssertion notInArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices.
* @method LazyAssertion notIsInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name.
* @method LazyAssertion notNull(string|callable $message = null, string $propertyPath = null) Assert that value is not null.
* @method LazyAssertion notRegex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex.
* @method LazyAssertion notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using ===).
* @method LazyAssertion null(string|callable $message = null, string $propertyPath = null) Assert that value is null.
* @method LazyAssertion numeric(string|callable $message = null, string $propertyPath = null) Assert that value is numeric.
* @method LazyAssertion objectOrClass(string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists.
* @method LazyAssertion phpVersion(mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version.
* @method LazyAssertion propertiesExist(array $properties, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the properties all exist.
* @method LazyAssertion propertyExists(string $property, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the property exists.
* @method LazyAssertion range(mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers.
* @method LazyAssertion readable(string|callable $message = null, string $propertyPath = null) Assert that the value is something readable.
* @method LazyAssertion regex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex.
* @method LazyAssertion same(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===).
* @method LazyAssertion satisfy(callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback.
* @method LazyAssertion scalar(string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar.
* @method LazyAssertion startsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars.
* @method LazyAssertion string(string|callable $message = null, string $propertyPath = null) Assert that value is a string.
* @method LazyAssertion subclassOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name.
* @method LazyAssertion true(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True.
* @method LazyAssertion url(string|callable $message = null, string $propertyPath = null) Assert that value is an URL.
* @method LazyAssertion uuid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID.
* @method LazyAssertion version(string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions.
* @method LazyAssertion writeable(string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable.
* @method LazyAssertion all() Switch chain into validation mode for an array of values.
* @method LazyAssertion nullOr() Switch chain into mode allowing nulls, ignoring further assertions.
* @method $this alnum(string|callable $message = null, string $propertyPath = null) Assert that value is alphanumeric.
* @method $this base64(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined.
* @method $this between(mixed $lowerLimit, mixed $upperLimit, string $message = null, string $propertyPath = null) Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit.
* @method $this betweenExclusive(mixed $lowerLimit, mixed $upperLimit, string $message = null, string $propertyPath = null) Assert that a value is greater than a lower limit, and less than an upper limit.
* @method $this betweenLength(int $minLength, int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string length is between min and max lengths.
* @method $this boolean(string|callable $message = null, string $propertyPath = null) Assert that value is php boolean.
* @method $this choice(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices.
* @method $this choicesNotEmpty(array $choices, string|callable $message = null, string $propertyPath = null) Determines if the values array has every choice as key and that this choice has content.
* @method $this classExists(string|callable $message = null, string $propertyPath = null) Assert that the class exists.
* @method $this contains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string contains a sequence of chars.
* @method $this count(int $count, string $message = null, string $propertyPath = null) Assert that the count of countable is equal to count.
* @method $this date(string $format, string|callable $message = null, string $propertyPath = null) Assert that date is valid and corresponds to the given format.
* @method $this defined(string|callable $message = null, string $propertyPath = null) Assert that a constant is defined.
* @method $this digit(string|callable $message = null, string $propertyPath = null) Validates if an integer or integerish is a digit.
* @method $this directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists.
* @method $this e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number.
* @method $this email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL).
* @method $this endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars.
* @method $this eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==).
* @method $this eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset.
* @method $this extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded.
* @method $this extensionVersion(string $operator, mixed $version, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded and a specific version is installed.
* @method $this false(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean False.
* @method $this file(string|callable $message = null, string $propertyPath = null) Assert that a file exists.
* @method $this float(string|callable $message = null, string $propertyPath = null) Assert that value is a php float.
* @method $this greaterOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater or equal than given limit.
* @method $this greaterThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is greater than given limit.
* @method $this implementsInterface(string $interfaceName, string|callable $message = null, string $propertyPath = null) Assert that the class implements the interface.
* @method $this inArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is in array of choices. This is an alias of Assertion::choice().
* @method $this integer(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer.
* @method $this integerish(string|callable $message = null, string $propertyPath = null) Assert that value is a php integer'ish.
* @method $this interfaceExists(string|callable $message = null, string $propertyPath = null) Assert that the interface exists.
* @method $this ip(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 or IPv6 address.
* @method $this ipv4(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv4 address.
* @method $this ipv6(int $flag = null, string|callable $message = null, string $propertyPath = null) Assert that value is an IPv6 address.
* @method $this isArray(string|callable $message = null, string $propertyPath = null) Assert that value is an array.
* @method $this isArrayAccessible(string|callable $message = null, string $propertyPath = null) Assert that value is an array or an array-accessible object.
* @method $this isCallable(string|callable $message = null, string $propertyPath = null) Determines that the provided value is callable.
* @method $this isCountable(string|callable $message = null, string $propertyPath = null) Assert that value is countable.
* @method $this isInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is instance of given class-name.
* @method $this isJsonString(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid json string.
* @method $this isObject(string|callable $message = null, string $propertyPath = null) Determines that the provided value is an object.
* @method $this isResource(string|callable $message = null, string $propertyPath = null) Assert that value is a resource.
* @method $this isTraversable(string|callable $message = null, string $propertyPath = null) Assert that value is an array or a traversable object.
* @method $this keyExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array.
* @method $this keyIsset(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object using isset().
* @method $this keyNotExists(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key does not exist in an array.
* @method $this length(int $length, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string has a given length.
* @method $this lessOrEqualThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less or equal than given limit.
* @method $this lessThan(mixed $limit, string|callable $message = null, string $propertyPath = null) Determines if the value is less than given limit.
* @method $this max(mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that a number is smaller as a given limit.
* @method $this maxCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable have at most $count elements.
* @method $this maxLength(int $maxLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string value is not longer than $maxLength chars.
* @method $this methodExists(mixed $object, string|callable $message = null, string $propertyPath = null) Determines that the named method is defined in the provided object.
* @method $this min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit.
* @method $this minCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable have at least $count elements.
* @method $this minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long.
* @method $this noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty.
* @method $this notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank.
* @method $this notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars.
* @method $this notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty.
* @method $this notEmptyKey(string|int $key, string|callable $message = null, string $propertyPath = null) Assert that key exists in an array/array-accessible object and its value is not empty.
* @method $this notEq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not equal (using == ).
* @method $this notInArray(array $choices, string|callable $message = null, string $propertyPath = null) Assert that value is not in array of choices.
* @method $this notIsInstanceOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is not instance of given class-name.
* @method $this notNull(string|callable $message = null, string $propertyPath = null) Assert that value is not null.
* @method $this notRegex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value does not match a regex.
* @method $this notSame(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are not the same (using === ).
* @method $this null(string|callable $message = null, string $propertyPath = null) Assert that value is null.
* @method $this numeric(string|callable $message = null, string $propertyPath = null) Assert that value is numeric.
* @method $this objectOrClass(string|callable $message = null, string $propertyPath = null) Assert that the value is an object, or a class that exists.
* @method $this phpVersion(mixed $version, string|callable $message = null, string $propertyPath = null) Assert on PHP version.
* @method $this propertiesExist(array $properties, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the properties all exist.
* @method $this propertyExists(string $property, string|callable $message = null, string $propertyPath = null) Assert that the value is an object or class, and that the property exists.
* @method $this range(mixed $minValue, mixed $maxValue, string|callable $message = null, string $propertyPath = null) Assert that value is in range of numbers.
* @method $this readable(string|callable $message = null, string $propertyPath = null) Assert that the value is something readable.
* @method $this regex(string $pattern, string|callable $message = null, string $propertyPath = null) Assert that value matches a regex.
* @method $this same(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are the same (using ===).
* @method $this satisfy(callable $callback, string|callable $message = null, string $propertyPath = null) Assert that the provided value is valid according to a callback.
* @method $this scalar(string|callable $message = null, string $propertyPath = null) Assert that value is a PHP scalar.
* @method $this startsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string starts with a sequence of chars.
* @method $this string(string|callable $message = null, string $propertyPath = null) Assert that value is a string.
* @method $this subclassOf(string $className, string|callable $message = null, string $propertyPath = null) Assert that value is subclass of given class-name.
* @method $this true(string|callable $message = null, string $propertyPath = null) Assert that the value is boolean True.
* @method $this url(string|callable $message = null, string $propertyPath = null) Assert that value is an URL.
* @method $this uuid(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid UUID.
* @method $this version(string $operator, string $version2, string|callable $message = null, string $propertyPath = null) Assert comparison of two versions.
* @method $this writeable(string|callable $message = null, string $propertyPath = null) Assert that the value is something writeable.
* @method $this all() Switch chain into validation mode for an array of values.
* @method $this nullOr() Switch chain into mode allowing nulls, ignoring further assertions.
*/
class LazyAssertion
{
@ -127,13 +127,9 @@ class LazyAssertion
private $exceptionClass = LazyAssertionException::class;
/**
* @param mixed $value
* @param string|null $propertyPath
* @param string|callable|null $defaultMessage
*
* @return static
* @return $this
*/
public function that($value, string $propertyPath = null, $defaultMessage = null)
public function that($value, $propertyPath, $defaultMessage = null)
{
$this->currentChainFailed = false;
$this->thisChainTryAll = false;
@ -144,7 +140,7 @@ class LazyAssertion
}
/**
* @return static
* @return $this
*/
public function tryAll()
{
@ -157,12 +153,6 @@ class LazyAssertion
return $this;
}
/**
* @param string $method
* @param array $args
*
* @return static
*/
public function __call($method, $args)
{
if (false === $this->alwaysTryAll
@ -183,11 +173,11 @@ class LazyAssertion
}
/**
* @return bool
*
* @throws LazyAssertionException
*
* @return bool
*/
public function verifyNow(): bool
public function verifyNow()
{
if ($this->errors) {
throw \call_user_func([$this->exceptionClass, 'fromErrors'], $this->errors);
@ -199,12 +189,12 @@ class LazyAssertion
/**
* @param string $className
*
* @return static
* @return $this
*/
public function setAssertClass(string $className)
{
if (Assert::class !== $className && !\is_subclass_of($className, Assert::class)) {
throw new LogicException($className.' is not (a subclass of) '.Assert::class);
throw new LogicException($className.' is not (a subclass of) '. Assert::class);
}
$this->assertClass = $className;
@ -215,7 +205,7 @@ class LazyAssertion
/**
* @param string $className
*
* @return static
* @return $this
*/
public function setExceptionClass(string $className)
{

View File

@ -26,7 +26,7 @@ class LazyAssertionException extends InvalidArgumentException
*
* @return self
*/
public static function fromErrors(array $errors): self
public static function fromErrors(array $errors)
{
$message = \sprintf('The following %d assertions failed:', \count($errors))."\n";
@ -45,10 +45,7 @@ class LazyAssertionException extends InvalidArgumentException
$this->errors = $errors;
}
/**
* @return InvalidArgumentException[]
*/
public function getErrorExceptions(): array
public function getErrorExceptions()
{
return $this->errors;
}

View File

@ -20,12 +20,6 @@ namespace Assert;
* The invocation of this method starts an assertion chain
* that is happening on the passed value.
*
* @param mixed $value
* @param string|callable|null $defaultMessage
* @param string $defaultPropertyPath
*
* @return AssertionChain
*
* @example
*
* \Assert\that($value)->notEmpty()->integer();
@ -33,8 +27,14 @@ namespace Assert;
*
* The assertion chain can be stateful, that means be careful when you reuse
* it. You should never pass around the chain.
*
* @param mixed $value
* @param string $defaultMessage
* @param string $defaultPropertyPath
*
* @return \Assert\AssertionChain
*/
function that($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
function that($value, $defaultMessage = null, $defaultPropertyPath = null)
{
return Assert::that($value, $defaultMessage, $defaultPropertyPath);
}
@ -42,13 +42,13 @@ function that($value, $defaultMessage = null, string $defaultPropertyPath = null
/**
* Start validation on a set of values, returns {@link AssertionChain}.
*
* @param mixed $values
* @param string|callable|null $defaultMessage
* @param mixed $values
* @param string $defaultMessage
* @param string $defaultPropertyPath
*
* @return AssertionChain
* @return \Assert\AssertionChain
*/
function thatAll($values, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
function thatAll($values, $defaultMessage = null, $defaultPropertyPath = null)
{
return Assert::thatAll($values, $defaultMessage, $defaultPropertyPath);
}
@ -56,15 +56,15 @@ function thatAll($values, $defaultMessage = null, string $defaultPropertyPath =
/**
* Start validation and allow NULL, returns {@link AssertionChain}.
*
* @param mixed $value
* @param string|callable|null $defaultMessage
* @param mixed $value
* @param string $defaultMessage
* @param string $defaultPropertyPath
*
* @return AssertionChain
* @return \Assert\AssertionChain
*
* @deprecated In favour of Assert::thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null)
*/
function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
function thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null)
{
return Assert::thatNullOr($value, $defaultMessage, $defaultPropertyPath);
}
@ -72,9 +72,9 @@ function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath
/**
* Create a lazy assertion object.
*
* @return LazyAssertion
* @return \Assert\LazyAssertion
*/
function lazy(): LazyAssertion
function lazy()
{
return Assert::lazy();
}

View File

@ -1,10 +1,3 @@
parameters:
autoload_files:
- bin/MethodDocGenerator.php
ignoreErrors:
# is_countable() is available only in PHP 7.3+
- '#Function is_countable not found#'
# Calling count() on ResourceBundle and SimpleXMLElement is valid from PHP 7.0+, but does not correctly advertise
# the fact, and so PHPStan has an issue with this. This will be fixed in PHP 7.4+
- '#Call to function count\(\) with argument type array|Countable|ResourceBundle|SimpleXMLElement will always result in number 1#'

View File

@ -1,5 +1,4 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
# https://github.com/localheinz/php-library-template/blob/master/.github/workflows/continuous-integration.yml
# https://github.com/sebastianbergmann/phpunit/blob/master/.github/workflows/ci.yml
on:
@ -10,46 +9,69 @@ name: "Continuous Integration"
jobs:
static-code-analysis:
name: "Static Code Analysis"
runs-on: ubuntu-latest
env:
PHAN_ALLOW_XDEBUG: 0
PHAN_DISABLE_XDEBUG_WARN: 1
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
coverage: none
tools: pecl
extensions: ast, gd, imagick, json, mbstring
- name: "Update dependencies with composer"
run: composer update --no-interaction --no-ansi --no-progress --no-suggest
- name: "Run phan"
run: php vendor/bin/phan
tests:
name: "Unit Tests"
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php-binary:
- php7.2
- php7.3
- php7.4
os:
- ubuntu-latest
# - windows-latest
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
steps:
- name: "Checkout"
uses: actions/checkout@v1.1.0
uses: actions/checkout@v2
- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
tools: pecl
extensions: gd, imagick, json, mbstring
- name: "Install dependencies with composer"
run: ${{ matrix.php-binary }} $(which composer) update --no-interaction --no-progress --no-suggest
run: composer update --no-ansi --no-interaction --no-progress --no-suggest
- name: "Run unit tests with phpunit"
run: ${{ matrix.php-binary }} vendor/bin/phpunit --configuration=phpunit.xml --no-coverage
code-coverage:
name: "Code Coverage"
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v1.1.0
- name: "Install locked dependencies with composer"
run: php7.4 $(which composer) install --no-interaction --no-progress --no-suggest
- name: "Dump Xdebug filter with phpunit/phpunit"
run: php7.4 vendor/bin/phpunit --configuration=phpunit.xml --dump-xdebug-filter=.build/phpunit/xdebug-filter.php
- name: "Collect code coverage with Xdebug and phpunit/phpunit"
run: php7.4 vendor/bin/phpunit --configuration=phpunit.xml --prepend=.build/phpunit/xdebug-filter.php
- name: "Run tests with phpunit"
run: php vendor/phpunit/phpunit/phpunit --configuration=phpunit.xml
- name: "Send code coverage report to Codecov.io"
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: bash <(curl -s https://codecov.io/bash)
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

View File

@ -1,3 +1,8 @@
branches:
only:
- main
- v3.2.x
addons:
apt:
packages:

View File

@ -24,12 +24,13 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"ext-mbstring": "*",
"chillerlan/php-settings-container": "^1.2"
"chillerlan/php-settings-container": "^1.2.2"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phan/phan": "^3.2.2",
"setasign/fpdf": "^1.8.2"
},
"suggest": {

View File

@ -41,9 +41,9 @@ class QRImageWithLogo extends QRImage{
}
$this->matrix->setLogoSpace(
$this->options->logoWidth,
$this->options->logoHeight
// not utilizing the position here
$this->options->logoSpaceWidth,
$this->options->logoSpaceHeight
// not utilizing the position here
);
// there's no need to save the result of dump() into $this->image here
@ -55,9 +55,9 @@ class QRImageWithLogo extends QRImage{
$w = imagesx($im);
$h = imagesy($im);
// set new logo size, leave a border of 1 module
$lw = ($this->options->logoWidth - 2) * $this->options->scale;
$lh = ($this->options->logoHeight - 2) * $this->options->scale;
// set new logo size, leave a border of 1 module (no proportional resize/centering)
$lw = ($this->options->logoSpaceWidth - 2) * $this->options->scale;
$lh = ($this->options->logoSpaceHeight - 2) * $this->options->scale;
// get the qrcode size
$ql = $this->matrix->size() * $this->options->scale;

View File

@ -16,14 +16,15 @@ require_once __DIR__.'/../vendor/autoload.php';
$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
/**
* @property int $logoWidth
* @property int $logoHeight
* @property int $logoSpaceWidth
* @property int $logoSpaceHeight
*
* @noinspection PhpIllegalPsrClassPathInspection
*/
class LogoOptions extends QROptions{
protected $logoWidth;
protected $logoHeight;
// size in QR modules, multiply with QROptions::$scale for pixel size
protected $logoSpaceWidth;
protected $logoSpaceHeight;
}
$options = new LogoOptions;
@ -31,8 +32,8 @@ $options = new LogoOptions;
$options->version = 7;
$options->eccLevel = QRCode::ECC_H;
$options->imageBase64 = false;
$options->logoWidth = 13;
$options->logoHeight = 13;
$options->logoSpaceWidth = 13;
$options->logoSpaceHeight = 13;
$options->scale = 5;
$options->imageTransparent = false;

View File

@ -589,12 +589,12 @@ class QRMatrix{
throw new QRCodeDataException('ECC level "H" required to add logo space');
}
// we need uneven sizes, adjust if needed
if(($width % 2) === 0){
// we need uneven sizes to center the logo space, adjust if needed
if($startX === null && ($width % 2) === 0){
$width++;
}
if(($height % 2) === 0){
if($startY === null && ($height % 2) === 0){
$height++;
}

View File

@ -13,6 +13,7 @@
namespace chillerlan\QRCodeTest\Output;
use chillerlan\QRCode\{QRCode, Output\QRImage};
use const PHP_MAJOR_VERSION;
class QRImageTest extends QROutputTestAbstract{
@ -63,7 +64,14 @@ class QRImageTest extends QROutputTestAbstract{
$this->setOutputInterface();
$this::assertIsResource($this->outputInterface->dump());
$data = $this->outputInterface->dump();
if(PHP_MAJOR_VERSION >= 8){
$this::assertInstanceOf('\\GdImage', $data);
}
else{
$this::assertIsResource($data);
}
}
}

View File

@ -4,10 +4,10 @@ matrix:
include:
- php: 7.2
- php: 7.3
- php: 7.4snapshot
- php: 7.4
- php: 8.0
- php: nightly
allow_failures:
- php: 7.4snapshot
- php: nightly

View File

@ -51,8 +51,8 @@ Profit!
## Usage
The `SettingsContainerInterface` (wrapped in`SettingsContainerAbstract` ) provides plug-in functionality for immutable object variables and adds some fancy, like loading/saving JSON, arrays etc.
It takes iterable as the only constructor argument and calls a method with the trait's name on invocation (`MyTrait::MyTrait()`) for each used trait.
The `SettingsContainerInterface` (wrapped in`SettingsContainerAbstract` ) provides plug-in functionality for immutable object properties and adds some fancy, like loading/saving JSON, arrays etc.
It takes an `iterable` as the only constructor argument and calls a method with the trait's name on invocation (`MyTrait::MyTrait()`) for each used trait.
### Simple usage
```php
@ -61,6 +61,13 @@ class MyContainer extends SettingsContainerAbstract{
protected $bar;
}
```
Typed properties in PHP 7.4+:
```php
class MyContainer extends SettingsContainerAbstract{
protected string $foo;
protected string $bar;
}
```
```php
// use it just like a \stdClass
@ -78,6 +85,8 @@ $container->fromJSON('{"foo": "what", "bar": "foo"}');
$container->toArray(); // -> ['foo' => 'what', 'bar' => 'foo']
// or JSON
$container->toJSON(); // -> {"foo": "what", "bar": "foo"}
// JSON via JsonSerializable
$json = json_encode($container); // -> {"foo": "what", "bar": "foo"}
//non-existing properties will be ignored:
$container->nope = 'what';

View File

@ -20,11 +20,11 @@
"source": "https://github.com/chillerlan/php-settings-container"
},
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.3"
"phpunit/phpunit": "^8.4"
},
"autoload": {
"psr-4": {

View File

@ -37,130 +37,57 @@ namespace Composer\Autoload;
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
/** @var ?string */
private $vendorDir;
// PSR-4
/**
* @var array[]
* @psalm-var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, array<int, string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* @var array[]
* @psalm-var array<string, array<string, string[]>>
*/
private $prefixesPsr0 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var string[]
* @psalm-var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var bool[]
* @psalm-var array<string, bool>
*/
private $missingClasses = array();
/** @var ?string */
private $apcuPrefix;
/**
* @var self[]
*/
private static $registeredLoaders = array();
/**
* @param ?string $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}
/**
* @return string[]
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
/**
* @return array[]
* @psalm-return array<string, array<int, string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return string[] Array of classname => path
* @psalm-var array<string, string>
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param string[] $classMap Class to filename map
* @psalm-param array<string, string> $classMap
*
* @return void
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
@ -175,11 +102,9 @@ class ClassLoader
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
@ -222,13 +147,11 @@ class ClassLoader
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
@ -272,10 +195,8 @@ class ClassLoader
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 base directories
*
* @return void
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
@ -290,12 +211,10 @@ class ClassLoader
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
@ -315,8 +234,6 @@ class ClassLoader
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
@ -339,8 +256,6 @@ class ClassLoader
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
@ -361,8 +276,6 @@ class ClassLoader
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
@ -383,44 +296,25 @@ class ClassLoader
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return true|null True if loaded, null otherwise
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
@ -429,8 +323,6 @@ class ClassLoader
return true;
}
return null;
}
/**
@ -475,21 +367,6 @@ class ClassLoader
return $file;
}
/**
* Returns the currently registered loaders indexed by their corresponding vendor directories.
*
* @return self[]
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
@ -561,10 +438,6 @@ class ClassLoader
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
* @private
*/
function includeFile($file)
{

View File

@ -1,4 +1,3 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -18,4 +17,3 @@ 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.

View File

@ -6,7 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'IdiormMethodMissingException' => $vendorDir . '/j4mie/idiorm/idiorm.php',
'IdiormResultSet' => $vendorDir . '/j4mie/idiorm/idiorm.php',
'IdiormString' => $vendorDir . '/j4mie/idiorm/idiorm.php',

View File

@ -23,12 +23,12 @@ class ComposerAutoloaderInit19fc2ff1c0f9a92279c7979386bb2056
}
spl_autoload_register(array('ComposerAutoloaderInit19fc2ff1c0f9a92279c7979386bb2056', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit19fc2ff1c0f9a92279c7979386bb2056', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit19fc2ff1c0f9a92279c7979386bb2056::getInitializer($loader));
} else {

View File

@ -154,7 +154,6 @@ class ComposerStaticInit19fc2ff1c0f9a92279c7979386bb2056
);
public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'IdiormMethodMissingException' => __DIR__ . '/..' . '/j4mie/idiorm/idiorm.php',
'IdiormResultSet' => __DIR__ . '/..' . '/j4mie/idiorm/idiorm.php',
'IdiormString' => __DIR__ . '/..' . '/j4mie/idiorm/idiorm.php',

File diff suppressed because it is too large Load Diff

View File

@ -51,6 +51,8 @@ can be checked before you run the actual line.
<a href="https://www.shopware.com/en/"><img src="https://i.imgur.com/L4X5w9s.png" alt="Shopware" width="284" height="64"></a>
&nbsp;&nbsp;&nbsp;
<a href="https://craftcms.com/"><img src="https://i.imgur.com/xJWThke.png" alt="Craft CMS" width="283" height="64"></a>
<br>
<a href="https://www.worksome.com/"><img src="https://i.imgur.com/TQKSwOl.png" alt="Worksome" width="283" height="64"></a>
[**You can now sponsor my open-source work on PHPStan through GitHub Sponsors.**](https://github.com/sponsors/ondrejmirtes)

Binary file not shown.

View File

@ -1,16 +1,16 @@
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmF/i1sACgkQzxoQjQ56
5yDALhAAhsbjCJLAUrakUztJRtsze7ka9fdbE9tPzTcY79AauMrFp/YIW5v+FrlE
O7+uvxUcNLbBPB/+v4mOIRmwFvJFjttBEKNZRviX/M3GXx/eeKqccXbkmjn/eYhu
1l34QRdROk5cdB9KD0q47wbSWcZ4TN1JyiBxqCyE+vyBDS8EnNjSOoSf+PaVTVyt
01sDLXZdokPF7TyeHzy0T4ye9nPyPe6//yeZkmpy40+ucJI4Y3VlNCycu5JFXt6v
2fYSFawgkPqpm9Oy3gNSL7qm8xMYI9mi3MqXmu+RYjFl3hTsVTYXiEWGeSHZ9lKO
BtzQfH6vhfeziZKRR7/7hCrzqz2s3v0WLdatkYeG9m2qtMNf6M7I3f0MwdMdCgb8
hZbKFUkHFWq2cFOtz+3ZKlvpbxnXkmnGapdyNVGn5eMkr4HdmrDic/IktHp+XWub
6xZMfHGz/fcuyLAE4XgPuVxx41wYYw2minmsgg2gsx2imTHM4r/ILezftxHIm0zG
Bl4PjxVrXa9WPTibdjd+5Vqat6/9mjCoMc131kDIwqjLmZT2jCXA4SoM8wi6VYkw
UdGumXXklSrN5qdxCpaEMpRMFIdVaiKyhB9MoQfeQ2hnPYA7blgE+htKT26E0vWC
dmtYQm47CKXCWPvrPKQnn0HYgOft655lde1zu2sFjQ5u+QzS9h8=
=PbiR
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmGKbGQACgkQzxoQjQ56
5yAy7BAAgT9+V81RuOMz6F16uqm4gXH1ebioWokEvVb6ZR2fk7p3/m14STmmRkwe
MIkxzWKtx/wSC6VafqAtkBPNxpo2j5QU0pmfMAvkPHh79d2lWmUaJmF71I/DCNnh
pcZNJLe5x+YTDKU6NnwMlyZEvdaWmyJ2MCf2apBZIJ7axefEJRVVin2pshhXwbtN
dHhrT9yFYe/vqOkOLtGDWw+yT1I6he7IpoYZUTyO9b7eadC0ga6Bet7jibNL8JBE
cGcB2MFg9bvif0PgIOio0jQXAWjf0ZBXPvoOwTRCqq/UOPTL8SRtiflAFiFOAzk/
FRQVC0+26NsGx7R8kS5FZNOHYTIElY1ElyzFk8HWgqrYIvzDNLtkJ68178rDJ29f
GyAax4P+gN13biyXQycQHhXDfHN1UytopldiRkitXVFGq92sz6BFgQDLF9yxQOm1
iL5oxWSVf6rM8AOc3DV9Aa1kCpG6FrZPJ66NBgJLzTpKARzt7CM+M8VQNA/KnHB3
8Mt0WmAeRORSnBWQksOlnA4VUkxWDGkZGVBWMRist7gghfG7n7HxTAUAk1oo7j2b
/gTwbeOjv/330uZG31e+hCcaj/EcocHvglegWCPMmIhpXqn25TC+87QkGt2wb6z6
dpzTdy3Pimr5BK2YrN1+Le33CYeHKlc+6XL34BEVebAQ/A9OB/M=
=k3NZ
-----END PGP SIGNATURE-----