<commit_before><?php

namespace CatLab\Requirements;

use CatLab\Requirements\Enums\PropertyType;
use CatLab\Requirements\Exceptions\RequirementValidationException;
use CatLab\Requirements\Interfaces\Property;

/**
 * Class IsType
 * @package CatLab\Requirements
 */
class IsType extends Requirement
{
    /**
     * @var string
     */
    private $type;

    /**
     * IsType constructor.
     * @param string $type
     */
    public function __construct(string $type)
    {
        $this->type = $type;
    }

    /**
     * @return string
     */
    function getTemplate() : string
    {
        return 'Property \'%s\' must be of type ' . $this->type . '.';
    }

    /**
     * @param Property $property
     * @param $value
     * @return mixed
     * @throws RequirementValidationException
     */
    public function validate(Property $property, $value)
    {
        if ($value === null) {
            return;
        }

        if ($value === null) {
            return;
        }

        switch ($this->type) {
            case PropertyType::INTEGER:
                $check = is_int($value);
                break;

            case PropertyType::DATETIME:
                $check = $value instanceof \DateTime;
                break;

            case PropertyType::NUMBER:
                $check = is_numeric($value);
                break;

            case PropertyType::STRING:
                $check = is_string($value);
                break;

            case PropertyType::OBJECT:
                $check = is_array($value) || is_object($value);
                break;

            default:<commit_msg>Add bool to type checker.<commit_after><?php

namespace CatLab\Requirements;

use CatLab\Requirements\Enums\PropertyType;
use CatLab\Requirements\Exceptions\RequirementValidationException;
use CatLab\Requirements\Interfaces\Property;

/**
 * Class IsType
 * @package CatLab\Requirements
 */
class IsType extends Requirement
{
    /**
     * @var string
     */
    private $type;

    /**
     * IsType constructor.
     * @param string $type
     */
    public function __construct(string $type)
    {
        $this->type = $type;
    }

    /**
     * @return string
     */
    function getTemplate() : string
    {
        return 'Property \'%s\' must be of type ' . $this->type . '.';
    }

    /**
     * @param Property $property
     * @param $value
     * @return mixed
     * @throws RequirementValidationException
     */
    public function validate(Property $property, $value)
    {
        if ($value === null) {
            return;
        }

        if ($value === null) {
            return;
        }

        switch ($this->type) {
            case PropertyType::INTEGER:
                $check = is_int($value);
                break;

            case PropertyType::DATETIME:
                $check = $value instanceof \DateTime;
                break;

            case PropertyType::NUMBER:
                $check = is_numeric($value);
                break;

            case PropertyType::STRING:
                $check = is_string($value);
                break;

            case PropertyType::OBJECT:
                $check = is_array($value) || is_object($value);
                break;

            case PropertyType::BOOL:
                $check = is_bool($value);
                break;

            default:
{'fraction_non_alphanumeric': 0.11434511434511435, 'fraction_numerical': 0.0, 'mean_word_length': 1.6250974279033514, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4919431', 'n_tokens_mistral': 936, 'n_tokens_neox': 884, 'n_words': 204}