wol-soft/php-json-schema-model-generator

View on GitHub
src/Model/Validator/RequiredPropertyValidator.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

declare(strict_types = 1);

namespace PHPModelGenerator\Model\Validator;

use PHPModelGenerator\Exception\Object\RequiredValueException;
use PHPModelGenerator\Model\Property\PropertyInterface;

/**
 * Class RequiredPropertyValidator
 *
 * @package PHPModelGenerator\Model\Validator
 */
class RequiredPropertyValidator extends PropertyValidator
{
    /**
     * RequiredPropertyValidator constructor.
     *
     * @param PropertyInterface $property
     */
    public function __construct(PropertyInterface $property)
    {
        parent::__construct($property, '', RequiredValueException::class);
    }

    public function getCheck(): string
    {
        return "!array_key_exists('{$this->property->getName()}', \$modelData)";
    }
}