Skip to content

Commit

Permalink
Added argument $reason for InvalidValueException's constructor and …
Browse files Browse the repository at this point in the history
…methods `::setEntity()`, `::getReason()` and `::create()`
  • Loading branch information
tg666 committed Feb 15, 2021
1 parent ac02958 commit 1576251
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions src/Exception/Persistence/InvalidValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,54 @@

final class InvalidValueException extends AbstractInvalidValueException
{
/** @var string|NULL */
private $reason;

/** @var mixed|object|NULL */
private $entity;

/**
* @param string $entityClassName
* @param string $columnName
* @param mixed $value
* @param object|NULL $entity
* @param string|NULL $reason
* @param int $code
* @param \Throwable|NULL $previous
*/
public function __construct(string $entityClassName, string $columnName, $value, ?object $entity = NULL, int $code = 0, Throwable $previous = NULL)
public function __construct(string $entityClassName, string $columnName, $value, ?string $reason = NULL, int $code = 0, Throwable $previous = NULL)
{
parent::__construct(sprintf(
'Invalid value %s for column %s::$%s',
'Invalid value %s for column %s::$%s.%s',
json_encode($value, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE),
$entityClassName,
$columnName
$columnName,
empty($reason) ? '' : ' ' . $reason
), $entityClassName, $columnName, $value, $code, $previous);

$this->entity = $entity;
$this->reason = $reason;
}

/**
* @param string $entityClassName
* @param string $columnName
* @param mixed $value
* @param string|NULL $reason
* @param int $code
* @param \Throwable|NULL $previous
*
* @return static
*/
public static function create(string $entityClassName, string $columnName, $value, ?string $reason = NULL, int $code = 0, Throwable $previous = NULL): self
{
return new self($entityClassName, $columnName, $value, $reason, $code, $previous);
}

/**
* @return NULL|string
*/
public function getReason(): ?string
{
return $this->reason;
}

/**
Expand All @@ -38,4 +65,16 @@ public function getEntity()
{
return $this->entity;
}

/**
* @param $entity
*
* @return \SixtyEightPublishers\DoctrinePersistence\Exception\Persistence\InvalidValueException
*/
public function setEntity($entity): self
{
$this->entity = $entity;

return $this;
}
}

0 comments on commit 1576251

Please sign in to comment.