Scalr\Tests\Functional\Api\V2\SpecSchema\Constraint\Validator::checkProperty PHP Method

checkProperty() protected method

Check property form spec object
protected checkProperty ( mixed $element, Property $schema )
$element mixed property value
$schema Scalr\Tests\Functional\Api\V2\SpecSchema\DataTypes\Property property schema generated of api specification
    protected function checkProperty($element, Property $schema)
    {
        $propertyName = $schema->getObjectName();
        //TODO:ape: check element don't empty because pagination type is string AND default is NULL
        if (!empty($element)) {
            switch ($schema->type) {
                case 'string':
                    $error = !is_string($element);
                    break;
                case 'integer':
                    $error = !is_numeric($element);
                    break;
                case 'boolean':
                    $error = !(is_bool($element) || 1 == $element || 0 == $element);
                    break;
                case 'array':
                    $error = !is_array($element);
                    break;
                default:
                    $error = false;
            }
            if ($error) {
                $this->appendError($propertyName, sprintf('This type is\'t not consistency with Api. Type should be %s.', $schema->type));
            }
        }
        if (isset($schema->enum)) {
            if ($schema->getObjectName() == 'builtinAutomation' && empty(static::$ignoreEnumVal['builtinAutomation'])) {
                static::$ignoreEnumVal['builtinAutomation'] = array_merge([null], array_flip(ROLE_BEHAVIORS::GetName(null, true)));
            }
            $enumVal = $schema->enum;
            if (isset(static::$ignoreEnumVal[$propertyName])) {
                $enumVal = array_merge($enumVal, static::$ignoreEnumVal[$propertyName]);
            }
            // check enum properties
            if (!in_array($element, $enumVal)) {
                $this->appendError($propertyName, sprintf('[%s] is not valid allowed value %s %s.', $element, ...count($schema->enum) === 1 ? ['is', array_shift($schema->enum)] : ['are', implode(', ', $schema->enum)]));
            }
        }
    }