Skip to content

Commit

Permalink
Updated codebase to PHP 8.0 (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-eugone authored Feb 28, 2022
1 parent a0b377a commit 1a27b42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
36 changes: 13 additions & 23 deletions src/SkipInvalidItemProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,23 @@
*/
final class SkipInvalidItemProcessor implements ItemProcessorInterface
{
private ValidatorInterface $validator;

/**
* @var Constraint[]|null
*/
private ?array $contraints;

/**
* @var string[]|null
*/
private ?array $groups;

/**
* @param Constraint[]|null $contraints
* @param string[]|null $groups
*/
public function __construct(ValidatorInterface $validator, array $contraints = null, array $groups = null)
{
$this->validator = $validator;
$this->contraints = $contraints;
$this->groups = $groups;
public function __construct(
private ValidatorInterface $validator,
/**
* @var Constraint[]|null
*/
private ?array $contraints = null,
/**
* @var string[]|null
*/
private ?array $groups = null,
) {
}

/**
* @inheritDoc
*/
public function process($item)
public function process(mixed $item): mixed
{
$violations = $this->validator->validate($item, $this->contraints, $this->groups);
if (\count($violations) === 0) {
Expand All @@ -63,7 +53,7 @@ public function process($item)
private function normalizeConstraints(?array $constraints): Iterator
{
foreach ($constraints ?? [] as $constraint) {
yield \get_class($constraint);
yield $constraint::class;
}
}
}
26 changes: 9 additions & 17 deletions src/SkipItemOnViolations.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@
*/
final class SkipItemOnViolations implements SkipItemCauseInterface
{
/**
* @phpstan-var ConstraintViolationListInterface<ConstraintViolationInterface>
*/
private ConstraintViolationListInterface $violations;

/**
* @phpstan-param ConstraintViolationListInterface<ConstraintViolationInterface> $violations
*/
public function __construct(ConstraintViolationListInterface $violations)
{
$this->violations = $violations;
public function __construct(
/**
* @phpstan-var ConstraintViolationListInterface<ConstraintViolationInterface>
*/
private ConstraintViolationListInterface $violations
) {
}

/**
* @inheritdoc
*/
public function report(JobExecution $execution, $index, $item): void
public function report(JobExecution $execution, int|string $index, mixed $item): void
{
$execution->getSummary()->increment('invalid');
$violations = [];
Expand Down Expand Up @@ -63,10 +58,7 @@ public function getViolations(): ConstraintViolationListInterface
return $this->violations;
}

/**
* @param mixed $invalidValue
*/
private function normalizeInvalidValue($invalidValue): string
private function normalizeInvalidValue(mixed $invalidValue): string
{
if ($invalidValue === '') {
return '""';
Expand Down Expand Up @@ -96,7 +88,7 @@ private function normalizeInvalidValue($invalidValue): string
return (string)$invalidValue;
}

return \get_class($invalidValue);
return $invalidValue::class;
}

return \gettype($invalidValue);
Expand Down

0 comments on commit 1a27b42

Please sign in to comment.