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

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

Summary

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

declare(strict_types = 1);

namespace PHPModelGenerator\Model\Validator;

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

/**
 * Class InstanceOfValidator
 *
 * @package PHPModelGenerator\Model\Validator
 */
class InstanceOfValidator extends PropertyValidator
{
    /**
     * InstanceOfValidator constructor.
     */
    public function __construct(PropertyInterface $property)
    {
        parent::__construct(
            $property,
            sprintf(
                'is_object($value) && !($value instanceof \Exception) && !($value instanceof %s)',
                $property->getType()->getName(),
            ),
            InvalidInstanceOfException::class,
            [$property->getType()->getName()],
        );
    }
}