Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![CI](https://img.shields.io/github/actions/workflow/status/k2gl/entity-exist/ci.yml?branch=main&label=CI&logo=github)](https://github.com/k2gl/entity-exist/actions/workflows/ci.yml)
[![Latest Stable Version](https://img.shields.io/packagist/v/k2gl/entity-exist?logo=packagist&logoColor=white)](https://packagist.org/packages/k2gl/entity-exist)
[![Total Downloads](https://img.shields.io/packagist/dt/k2gl/entity-exist?logo=packagist&logoColor=white)](https://packagist.org/packages/k2gl/entity-exist)
[![PHPStan Level](https://img.shields.io/badge/PHPStan-level%206-2a5ea7?logo=php&logoColor=white)](https://phpstan.org)
[![PHPStan Level](https://img.shields.io/badge/PHPStan-level%209-2a5ea7?logo=php&logoColor=white)](https://phpstan.org)
[![License](https://img.shields.io/packagist/l/k2gl/entity-exist?color=yellowgreen)](https://packagist.org/packages/k2gl/entity-exist)

## Requirements
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
level: 6
level: 9
paths:
- src
6 changes: 6 additions & 0 deletions src/AssertEntityExistValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use Stringable;

final class AssertEntityExistValidator extends ConstraintValidator
{
Expand All @@ -23,6 +25,10 @@ public function validate(mixed $value, Constraint $constraint): void
return;
}

if (! is_scalar($value) && ! $value instanceof Stringable) {
throw new UnexpectedValueException($value, expectedType: 'string');
}

$data = $this->entityManager->getRepository($constraint->entity)->findOneBy([
$constraint->property => $value,
]);
Expand Down
6 changes: 6 additions & 0 deletions src/AssertEntityNotExistValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use Stringable;

final class AssertEntityNotExistValidator extends ConstraintValidator
{
Expand All @@ -23,6 +25,10 @@ public function validate(mixed $value, Constraint $constraint): void
return;
}

if (! is_scalar($value) && ! $value instanceof Stringable) {
throw new UnexpectedValueException($value, expectedType: 'string');
}

$data = $this->entityManager->getRepository($constraint->entity)->findOneBy([
$constraint->property => $value,
]);
Expand Down