Skip to content

Commit

Permalink
unify AssertNoLoop-Validators
Browse files Browse the repository at this point in the history
  • Loading branch information
pmattmann committed Jul 9, 2024
1 parent cb9fa18 commit e0f65ff
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 68 deletions.
8 changes: 6 additions & 2 deletions api/src/Entity/ChecklistItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use App\InputFilter;
use App\Repository\ChecklistItemRepository;
use App\Util\EntityMap;
use App\Validator\AssertNoLoop;
use App\Validator\ChecklistItem\AssertBelongsToChecklist;
use App\Validator\ChecklistItem\AssertNoLoop;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
Expand Down Expand Up @@ -67,7 +67,7 @@
)]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['checklist'])]
#[ORM\Entity(repositoryClass: ChecklistItemRepository::class)]
class ChecklistItem extends BaseEntity implements BelongsToCampInterface, CopyFromPrototypeInterface {
class ChecklistItem extends BaseEntity implements BelongsToCampInterface, CopyFromPrototypeInterface, HasParentInterface {
public const CHECKLIST_SUBRESOURCE_URI_TEMPLATE = '/checklists/{checklistId}/checklist_items.{_format}';

/**
Expand Down Expand Up @@ -140,6 +140,10 @@ public function getCamp(): ?Camp {
return $this->checklist?->getCamp();
}

public function getParent(): ?HasParentInterface {
return $this->parent;
}

/**
* @return ChecklistItem[]
*/
Expand Down
8 changes: 6 additions & 2 deletions api/src/Entity/ContentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use App\Util\ClassInfoTrait;
use App\Util\EntityMap;
use App\Util\JsonMergePatch;
use App\Validator\AssertNoLoop;
use App\Validator\ContentNode\AssertAttachedToRoot;
use App\Validator\ContentNode\AssertContentTypeCompatible;
use App\Validator\ContentNode\AssertNoLoop;
use App\Validator\ContentNode\AssertNoRootChange;
use App\Validator\ContentNode\AssertSlotSupportedByParent;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -49,7 +49,7 @@
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'strategy', type: 'string')]
#[ORM\UniqueConstraint(name: 'contentnode_parentid_slot_position_unique', columns: ['parentid', 'slot', 'position'])]
abstract class ContentNode extends BaseEntity implements BelongsToContentNodeTreeInterface, CopyFromPrototypeInterface {
abstract class ContentNode extends BaseEntity implements BelongsToContentNodeTreeInterface, CopyFromPrototypeInterface, HasParentInterface {
use ClassInfoTrait;

/**
Expand Down Expand Up @@ -180,6 +180,10 @@ public function getRoot(): ?ColumnLayout {
return $this->root;
}

public function getParent(): ?HasParentInterface {
return $this->parent;
}

/**
* Holds the actual data of the content node.
*/
Expand Down
7 changes: 7 additions & 0 deletions api/src/Entity/HasParentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace App\Entity;

interface HasParentInterface extends HasId {
public function getParent(): ?HasParentInterface;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Validator\ContentNode;
namespace App\Validator;

use Symfony\Component\Validator\Constraint;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Validator\ContentNode;
namespace App\Validator;

use App\Entity\ContentNode;
use App\Entity\HasParentInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
Expand All @@ -19,7 +19,7 @@ public function validate($value, Constraint $constraint): void {

$object = $this->context->getObject();

/** @var ContentNode $parent */
/** @var HasParentInterface $parent */
$parent = $value;

// $seen keeps track of all parents that we have visited. This is for a safety
Expand All @@ -36,7 +36,7 @@ public function validate($value, Constraint $constraint): void {
}

$seen[] = $parent->getId();
$parent = $parent->parent;
$parent = $parent->getParent();
}
}
}
10 changes: 0 additions & 10 deletions api/src/Validator/ChecklistItem/AssertNoLoop.php

This file was deleted.

46 changes: 0 additions & 46 deletions api/src/Validator/ChecklistItem/AssertNoLoopValidator.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace App\Tests\Validator\ContentNode;
namespace App\Tests\Validator;

use App\Entity\ContentNode;
use App\Validator\ContentNode\AssertNoLoop;
use App\Validator\ContentNode\AssertNoLoopValidator;
use App\Validator\AssertNoLoop;
use App\Validator\AssertNoLoopValidator;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
Expand Down

0 comments on commit e0f65ff

Please sign in to comment.