Skip to content

Commit

Permalink
Renamed some Rule & Serializer params
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaplet committed Apr 22, 2024
1 parent 03558e0 commit 5d004ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/Collection/WriteBuilder/Rule/UniqueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
class UniqueRule extends BaseRule
{
/**
* @param class-string $entityClassName
* @param class-string $targetEntity
* @param string $columnName
* @param string $primaryKey
* @param string|null $message
*/
public function __construct(
protected string $entityClassName,
protected string $targetEntity,
protected string $columnName,
protected string $primaryKey = 'id',
protected string|null $message = null
Expand Down Expand Up @@ -45,7 +45,7 @@ public function validate(): bool
return false;
}

$repo = $this->getEntityManager()->getRepository($this->entityClassName);
$repo = $this->getEntityManager()->getRepository($this->targetEntity);

$row = $repo->createQueryBuilder('e')
->select('e')
Expand All @@ -59,7 +59,7 @@ public function validate(): bool
}

if (!array_key_exists($this->primaryKey, $row)) {
throw new InvalidArgumentException("Property '{$this->primaryKey}' not found in entity '{$this->entityClassName}'");
throw new InvalidArgumentException("Property '{$this->primaryKey}' not found in entity '{$this->targetEntity}'");
}

if (
Expand Down
11 changes: 5 additions & 6 deletions src/Collection/WriteBuilder/Serializer/ToManySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
use Megio\Collection\Exception\SerializerException;
use Megio\Collection\WriteBuilder\Field\Base\IField;
use Megio\Collection\WriteBuilder\Serializer\Base\BaseSerializer;
use Tracy\Debugger;

class ToManySerializer extends BaseSerializer
{
/**
* @param class-string $entityClassName
* @param class-string $targetEntity
*/
public function __construct(
protected string $entityClassName,
protected string $primaryKey = 'id',
protected string $targetEntity,
protected string $columnKey = 'id',
)
{
}
Expand All @@ -36,8 +35,8 @@ public function serialize(IField $field): mixed
$em = $this->getBuilder()->getEntityManager();

$rows = $em
->getRepository($this->entityClassName)
->findBy([$this->primaryKey => $value]);
->getRepository($this->targetEntity)
->findBy([$this->columnKey => $value]);

return new ArrayCollection($rows);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Collection/WriteBuilder/Serializer/ToOneSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
class ToOneSerializer extends BaseSerializer
{
/**
* @param class-string $entityClassName
* @param class-string $targetEntity
*/
public function __construct(
protected string $entityClassName,
protected string $primaryKey = 'id',
protected string $targetEntity,
protected string $columnKey = 'id',
)
{
}
Expand All @@ -34,8 +34,8 @@ public function serialize(IField $field): mixed
$em = $this->getBuilder()->getEntityManager();

$row = $em
->getRepository($this->entityClassName)
->findOneBy([$this->primaryKey => $value]);
->getRepository($this->targetEntity)
->findOneBy([$this->columnKey => $value]);

if ($row) {
return $row;
Expand Down

0 comments on commit 5d004ad

Please sign in to comment.