34 lines
857 B
PHP
34 lines
857 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Application\Article;
|
||
|
|
|
||
|
|
use App\Domain\Article\Article;
|
||
|
|
|
||
|
|
final class ArticleValidator
|
||
|
|
{
|
||
|
|
/** @return list<string> missing attribute names */
|
||
|
|
public function getMissingAttributes(Article $article): array
|
||
|
|
{
|
||
|
|
$setValue = [];
|
||
|
|
foreach ($article->getAttributeValues() as $value) {
|
||
|
|
$setValue[] = $value->getAttributeDefinition()->getId()->toRfc4122();
|
||
|
|
}
|
||
|
|
|
||
|
|
$missing = [];
|
||
|
|
foreach ($article->getArticleType()->getAttributeDefinitions() as $def) {
|
||
|
|
if (!\in_array($def->getId()->toRfc4122(), $setValue, strict: true)) {
|
||
|
|
$missing[] = $def->getName();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $missing;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isValid(Article $article): bool
|
||
|
|
{
|
||
|
|
return [] === $this->getMissingAttributes($article);
|
||
|
|
}
|
||
|
|
}
|