Skip to content

Commit

Permalink
php 8.0 min version
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Mar 6, 2022
1 parent 048c31e commit ab160ac
Show file tree
Hide file tree
Showing 37 changed files with 109 additions and 285 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2021 Dominik Zogg
Copyright (c) 2022 Dominik Zogg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -26,14 +26,14 @@ A simple validation.

## Requirements

* php: ^7.4|^8.0
* psr/log: ^1.0
* php: ^8.0
* psr/log: ^1.1.4|^2.0|^3.0

## Suggest

* chubbyphp/chubbyphp-container: ^1.0
* pimple/pimple: ^3.2.3
* psr/container: ^1.0
* chubbyphp/chubbyphp-container: ^2.1
* pimple/pimple: ^3.5
* psr/container: ^1.1.2|^2.0.2

## Installation

Expand Down Expand Up @@ -223,7 +223,7 @@ $errors = $validator->validate(

## Copyright

Dominik Zogg 2021
Dominik Zogg 2022


[1]: https://packagist.org/packages/chubbyphp/chubbyphp-validation
Expand Down
28 changes: 16 additions & 12 deletions composer.json
Expand Up @@ -13,23 +13,23 @@
"php": "^8.0",
"ext-filter": "*",
"ext-json": "*",
"psr/log": "^1.0"
"psr/log": "^1.1.4|^2.0|^3.0"
},
"require-dev": {
"chubbyphp/chubbyphp-container": "^1.0|^2.0",
"chubbyphp/chubbyphp-container": "^2.1",
"chubbyphp/chubbyphp-dev-helper": "dev-master",
"chubbyphp/chubbyphp-laminas-config-factory": "^1.0",
"chubbyphp/chubbyphp-mock": "^1.6.1",
"doctrine/persistence": "^1.3|^2.0",
"infection/infection": "^0.25.3",
"php-coveralls/php-coveralls": "^2.5.1",
"doctrine/persistence": "^2.3",
"infection/infection": "^0.26.5",
"php-coveralls/php-coveralls": "^2.5.2",
"phploc/phploc": "^7.0.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.1.2",
"phpunit/phpunit": "^9.5.10",
"pimple/pimple": "^3.3",
"psr/container": "^1.0|^2.0",
"symfony/validator": "^5.3.11|^6.0.0"
"phpstan/phpstan": "^1.4.8",
"phpunit/phpunit": "^9.5.17",
"pimple/pimple": "^3.5",
"psr/container": "^2.0.2",
"symfony/validator": "^5.4.5|^6.0"
},
"autoload": {
"psr-4": { "Chubbyphp\\Validation\\": "src/" }
Expand All @@ -38,7 +38,11 @@
"psr-4": { "Chubbyphp\\Tests\\Validation\\": "tests/" }
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true,
"phpstan/extension-installer": true
}
},
"extra": {
"branch-alias": {
Expand All @@ -57,7 +61,7 @@
"@test:cs"
],
"test:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=90 --verbose --coverage=build/phpunit",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=91 --verbose --coverage=build/phpunit",
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/result.cache",
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
"test:loc": "mkdir -p build && vendor/bin/phploc src | tee build/phploc.log",
Expand Down
9 changes: 6 additions & 3 deletions infection.json
Expand Up @@ -6,9 +6,12 @@
},
"timeout": 10,
"logs": {
"text": "build/phpinfection.log",
"badge": {
"branch": "master"
"text": "build/phpinfection/infection.log",
"html": "build/phpinfection/infection.html",
"json": "build/phpinfection/infection.json",
"summary": "build/phpinfection/summary.log",
"stryker": {
"report": "master"
}
},
"mutators": {
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Expand Up @@ -9,3 +9,6 @@ parameters:
-
message: '/PHPDoc tag @var for variable \$parentReflectionClass contains generic class ReflectionClass but does not specify its types\: T/'
path: %currentWorkingDirectory%/src/Mapping/ValidationMappingProviderRegistry.php
-
message: '/Property Chubbyphp\\Validation\\Error\\ErrorMessages\:\:\$errorMessages \(array\<string, array\<string\>\>\|null\) does not accept array\<string, array\>\./'
path: %currentWorkingDirectory%/src/Error/ErrorMessages.php
7 changes: 2 additions & 5 deletions src/Accessor/MethodAccessor.php
Expand Up @@ -8,11 +8,8 @@

final class MethodAccessor implements AccessorInterface
{
private string $property;

public function __construct(string $property)
public function __construct(private string $property)
{
$this->property = $property;
}

/**
Expand All @@ -39,7 +36,7 @@ public function getValue(object $object)
}

throw ValidatorLogicException::createMissingMethod(
\get_class($object),
$object::class,
[$getMethodName, $hasMethodName, $isMethodName]
);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Accessor/PropertyAccessor.php
Expand Up @@ -9,11 +9,8 @@

final class PropertyAccessor implements AccessorInterface
{
private string $property;

public function __construct(string $property)
public function __construct(private string $property)
{
$this->property = $property;
}

/**
Expand Down Expand Up @@ -49,6 +46,6 @@ private function getClass(object $object): string
}
}

return \get_class($object);
return $object::class;
}
}
2 changes: 1 addition & 1 deletion src/Constraint/AllConstraint.php
Expand Up @@ -49,7 +49,7 @@ public function validate(
return [new Error(
$path.'[_all]',
'constraint.all.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

Expand Down
8 changes: 1 addition & 7 deletions src/Constraint/ChoiceConstraint.php
Expand Up @@ -11,17 +11,11 @@

final class ChoiceConstraint implements ConstraintInterface
{
/**
* @var array<int, int|string>
*/
private array $choices = [];

/**
* @param array<int, int|string> $choices
*/
public function __construct(array $choices)
public function __construct(private array $choices)
{
$this->choices = $choices;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Constraint/CoordinateArrayConstraint.php
Expand Up @@ -30,19 +30,19 @@ public function validate(
return [new Error(
$path,
'constraint.coordinatearray.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

if (!isset($value['lat']) || !isset($value['lon'])) {
return [new Error($path, 'constraint.coordinatearray.invalidformat', ['value' => json_encode($value)])];
return [new Error($path, 'constraint.coordinatearray.invalidformat', ['value' => json_encode($value, JSON_THROW_ON_ERROR)])];
}

$lat = $value['lat'];
$lon = $value['lon'];

if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180) {
return [new Error($path, 'constraint.coordinatearray.invalidvalue', ['value' => json_encode($value)])];
return [new Error($path, 'constraint.coordinatearray.invalidvalue', ['value' => json_encode($value, JSON_THROW_ON_ERROR)])];
}

return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/CoordinateConstraint.php
Expand Up @@ -32,7 +32,7 @@ public function validate(
return [new Error(
$path,
'constraint.coordinate.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

Expand Down
10 changes: 2 additions & 8 deletions src/Constraint/CountConstraint.php
Expand Up @@ -11,14 +11,8 @@

final class CountConstraint implements ConstraintInterface
{
private ?int $min = null;

private ?int $max = null;

public function __construct(?int $min = null, ?int $max = null)
public function __construct(private ?int $min = null, private ?int $max = null)
{
$this->min = $min;
$this->max = $max;
}

/**
Expand All @@ -40,7 +34,7 @@ public function validate(
return [new Error(
$path,
'constraint.count.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

Expand Down
7 changes: 2 additions & 5 deletions src/Constraint/DateTimeConstraint.php
Expand Up @@ -11,11 +11,8 @@

final class DateTimeConstraint implements ConstraintInterface
{
private string $format;

public function __construct(string $format = 'Y-m-d H:i:s')
public function __construct(private string $format = 'Y-m-d H:i:s')
{
$this->format = $format;
}

/**
Expand All @@ -41,7 +38,7 @@ public function validate(
return [new Error(
$path,
'constraint.datetime.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

Expand Down
13 changes: 2 additions & 11 deletions src/Constraint/Doctrine/UniqueConstraint.php
Expand Up @@ -14,20 +14,11 @@

final class UniqueConstraint implements ConstraintInterface
{
private ObjectManager $objectManager;

/**
* @var array<int, string>
*/
private array $uniqueProperties;

/**
* @param array<int, string> $uniqueProperties
*/
public function __construct(ObjectManager $objectManager, array $uniqueProperties)
public function __construct(private ObjectManager $objectManager, private array $uniqueProperties)
{
$this->objectManager = $objectManager;
$this->uniqueProperties = $uniqueProperties;
}

/**
Expand All @@ -48,7 +39,7 @@ public function validate(
$criteria = $this->getCriteria($model);

/** @var class-string $modelClass */
$modelClass = \get_class($model);
$modelClass = $model::class;

if (null === $persistedModel = $this->objectManager->getRepository($modelClass)->findOneBy($criteria)) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/EmailConstraint.php
Expand Up @@ -35,7 +35,7 @@ public function validate(
return [new Error(
$path,
'constraint.email.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/MapConstraint.php
Expand Up @@ -62,7 +62,7 @@ public function validate(
return [new Error(
$path,
'constraint.map.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/NumericConstraint.php
Expand Up @@ -30,7 +30,7 @@ public function validate(
return [new Error(
$path,
'constraint.numeric.invalidtype',
['type' => \is_object($value) ? \get_class($value) : \gettype($value)]
['type' => get_debug_type($value)]
)];
}

Expand Down
8 changes: 1 addition & 7 deletions src/Constraint/NumericRangeConstraint.php
Expand Up @@ -11,14 +11,8 @@

final class NumericRangeConstraint implements ConstraintInterface
{
private ?int $min = null;

private ?int $max = null;

public function __construct(?int $min = null, ?int $max = null)
public function __construct(private ?int $min = null, private ?int $max = null)
{
$this->min = $min;
$this->max = $max;
}

/**
Expand Down
12 changes: 3 additions & 9 deletions src/Constraint/SortConstraint.php
Expand Up @@ -14,17 +14,11 @@ final class SortConstraint implements ConstraintInterface
{
private const ALLOWED_ORDERS = ['asc', 'desc'];

/**
* @var array<string>
*/
private array $allowedFields;

/**
* @param array<string> $allowedFields
*/
public function __construct(array $allowedFields)
public function __construct(private array $allowedFields)
{
$this->allowedFields = $allowedFields;
}

/**
Expand All @@ -44,7 +38,7 @@ public function validate(
return [new Error(
$path,
'constraint.sort.invalidtype',
['type' => \is_object($sort) ? \get_class($sort) : \gettype($sort)]
['type' => get_debug_type($sort)]
)];
}

Expand Down Expand Up @@ -78,7 +72,7 @@ private function validateFieldAndOrder(string $path, string $field, $order): arr
$errors[] = new Error(
$path.'.'.$field,
'constraint.sort.order.invalidtype',
['field' => $field, 'type' => \is_object($order) ? \get_class($order) : \gettype($order)]
['field' => $field, 'type' => get_debug_type($order)]
);

return $errors;
Expand Down
8 changes: 1 addition & 7 deletions src/Constraint/Symfony/ConstraintAdapter.php
Expand Up @@ -13,14 +13,8 @@

final class ConstraintAdapter implements ConstraintInterface
{
private Constraint $symfonyConstraint;

private ConstraintValidatorInterface $symfonyConstraintValidator;

public function __construct(Constraint $symfonyConstraint, ConstraintValidatorInterface $symfonyConstraintValidator)
public function __construct(private Constraint $symfonyConstraint, private ConstraintValidatorInterface $symfonyConstraintValidator)
{
$this->symfonyConstraint = $symfonyConstraint;
$this->symfonyConstraintValidator = $symfonyConstraintValidator;
}

/**
Expand Down

0 comments on commit ab160ac

Please sign in to comment.