Returns Create Errors

@param *array $data
@param array  $errors

@return array
178871
public static function getCreateErrors(array $data, array $errors = [])
    {
        $schema = Schema::i('auth');

        //auth_slug        Required
        if (!isset($data['auth_slug']) || empty($data['auth_slug'])) {
            $errors['auth_slug'] = 'Cannot be empty';
        } else if ($schema->model()->service('sql')->exists('auth_slug', $data['auth_slug'])) {
            $errors['auth_slug'] = 'Email Already Exists';
        }

        //auth_password        Required
        if (!isset($data['auth_password']) || empty($data['auth_password'])) {
            $errors['auth_password'] = 'Cannot be empty';
        }

        //confirm        NOT IN SCHEMA
        if (!isset($data['confirm']) || empty($data['confirm'])) {
            $errors['confirm'] = 'Cannot be empty';
        } else if ($data['confirm'] !== $data['auth_password']) {
            $errors['confirm'] = 'Passwords do not match';
        }

        //also add optional errors
        return self::getOptionalErrors($data, $errors);
    }
954202
public function createConditions(array $data): array
    {
        return array_map(function ($data) {
            if ($data instanceof self) {
                return $data;
            }

            return self::createFromData((array) $data);
        }, $data);
    }
1101347
public static function createFromArray(array $data): RetryMap
    {
        $retryMap = new RetryMap();
        foreach ($data as $entry) {
            $retryMap->addRetry(Retry::createFromArray($entry));
        }

        return $retryMap;
    }
695265
public function validation($data, $files) {
        $errors = [];
        if (isset($data['purgeselectedcaches']) && empty(array_filter($data['purgeselectedoptions']))) {
            $errors['purgeselectedoptions'] = get_string('purgecachesnoneselected', 'admin');
        }
        return $errors;
    }
658894
public static function createFailure($message, $errors = array()) {
	    $report = new static(self::TYPE_ERROR, $message);
	    foreach ($errors as $error) {
	        $report->add($error);
	    }
	    return $report;
	}
211708
private function getErrorMessages(array $errors)
    {
        $content = [];
        foreach ($errors as $error) {
            $property = $error->getProperty();
            if ($property instanceof JsonPointer && $this->constraintUtils instanceof ConstraintUtils) {
                $property = $this->constraintUtils->getNormalizedPathFromPointer($property);
            }
            $content[] = [
                'propertyPath' => $property,
                'message' => $error->getMessage(),
            ];
        }
        return $content;
    }
1346213
public function getOptionalErrors(array $data, array &$errors = [], $fieldset = null)
    {
        $schema = $this->schema;

        if (!is_null($fieldset)) {
            $schema = $fieldset;
        }

        $fields = $schema->getFields();
        $table = $schema->getName();
        $primary = $schema->getPrimaryFieldName();

        foreach ($fields as $field) {
            $name = $table . '_' . $field['name'];
            //if there is no data
            if (!isset($data[$name])) {
                //no need to validate
                continue;
            }

            if (!isset($field['validation']) || !is_array($field['validation'])) {
                continue;
            }

            foreach ($field['validation'] as $validation) {
                switch (true) {
                    case in_array($validation['method'], ['column_gt', 'column_gte', 'column_lt', 'column_lte'])
                        && !isset($data[$validation['parameters']]):
                        $errors[$name] = cradle('global')
                            ->translate('Column compared against does not exist. Please check schema.');
                        break;
                    case $validation['method'] === 'column_gt'
                        && !($data[$name] > $data[$validation['parameters']]):
                    case $validation['method'] === 'column_gte'
                        && !($data[$name] >= $data[$validation['parameters']]):
                    case $validation['method'] === 'column_lt'
                        && !($data[$name] < $data[$validation['parameters']]):
                    case $validation['method'] === 'column_lte'
                        && !($data[$name] <= $data[$validation['parameters']]):
                    case $validation['method'] === 'empty'
                        && empty($data[$name]):
                    case $validation['method'] === 'number'
                        && !is_numeric($data[$name]):
                    case $validation['method'] === 'float'
                        && !preg_match('/^[-+]?(\d*)?\.\d+$/', $data[$name]):
                    case $validation['method'] === 'price'
                        && !preg_match('/^[-+]?(\d*)?\.\d{2}$/', $data[$name]):
                    case $validation['method'] === 'price'
                        && !is_numeric($data[$name]):
                    case $validation['method'] === 'regexp'
                        && !preg_match($validation['parameters'], $data[$name]):
                    case $validation['method'] === 'gt'
                        && !($data[$name] > $validation['parameters']):
                    case $validation['method'] === 'gte'
                        && !($data[$name] >= $validation['parameters']):
                    case $validation['method'] === 'lt'
                        && !($data[$name] < $validation['parameters']):
                    case $validation['method'] === 'lte'
                        && !($data[$name] <= $validation['parameters']):
                    case $validation['method'] === 'char_gt'
                        && !(strlen($data[$name]) > $validation['parameters']):
                    case $validation['method'] === 'char_gte'
                        && !(strlen($data[$name]) >= $validation['parameters']):
                    case $validation['method'] === 'char_lt'
                        && !(strlen($data[$name]) < $validation['parameters']):
                    case $validation['method'] === 'char_lte'
                        && !(strlen($data[$name]) <= $validation['parameters']):
                    case $validation['method'] === 'word_gt'
                        && !(str_word_count($data[$name]) > $validation['parameters']):
                    case $validation['method'] === 'word_gte'
                        && !(str_word_count($data[$name]) >= $validation['parameters']):
                    case $validation['method'] === 'word_lt'
                        && !(str_word_count($data[$name]) < $validation['parameters']):
                    case $validation['method'] === 'word_lte'
                        && !(str_word_count($data[$name]) <= $validation['parameters']):
                    case $validation['method'] === 'date'
                        && !preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/', $data[$name]):
                    case $validation['method'] === 'time'
                        && !preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $data[$name]):
                    case $validation['method'] === 'datetime'
                        && !preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $data[$name]):
                    case $validation['method'] === 'futuredate'
                        && !(strtotime($data[$name]) > strtotime(date('Y-m-d'))):
                    case $validation['method'] === 'pastdate'
                        && !(strtotime($data[$name]) < strtotime(date('Y-m-d'))):
                    case $validation['method'] === 'presentdate'
                        && !(strtotime($data[$name]) == strtotime(date('Y-m-d'))):
                    case $validation['method'] === 'email'
                        && !preg_match('/^(?:(?:(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|\x5c(?=[@,"\[\]'.
                        '\x5c\x00-\x20\x7f-\xff]))(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]'.
                        '\x5c\x00-\x20\x7f-\xff]|\x5c(?=[@,"\[\]\x5c\x00-\x20\x7f-\xff])|\.(?=[^\.])){1,62'.
                        '}(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]\x5c\x00-\x20\x7f-\xff])|'.
                        '[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]{1,2})|"(?:[^"]|(?<=\x5c)"){1,62}")@(?:(?!.{64})'.
                        '(?:[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.?|[a-zA-Z0-9]\.?)+\.(?:xn--[a-zA-Z0-9]'.
                        '+|[a-zA-Z]{2,6})|\[(?:[0-1]?\d?\d|2[0-4]\d|25[0-5])(?:\.(?:[0-1]?\d?\d|2[0-4]\d|25'.
                        '[0-5])){3}\])$/', $data[$name]):
                    case $validation['method'] === 'url'
                        && !preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0'.
                        '-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?\/?/i', $data[$name]):
                    case $validation['method'] === 'hex'
                        && preg_match('/^[0-9a-fA-F]{6}$/', $data[$name]):
                    case $validation['method'] === 'cc'
                        && !preg_match('/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]'.
                        '{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-'.
                        '5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/', $data[$name]):
                        $errors[$name] = $validation['message'];
                        break;
                    case $validation['method'] === 'one':
                        if (!in_array($data[$name], $validation['parameters'])) {
                            $errors[$name] = $validation['message'];
                        }
                        break;
                    case $validation['method'] === 'unique':
                        $search = Service::get('sql')
                            ->getResource()
                            ->search($table)
                            ->addFilter($name . '= %s', $data[$name]);

                        if (isset($data[$primary])) {
                            $search->addFilter($primary . ' != %s', $data[$primary]);
                        }

                        if ($search->getTotal()) {
                            $errors[$name] = $validation['message'];
                        }
                        break;
                }
            }
        }

        return $errors;
    }
59404
public function validation($data, $files) {
        $errors = parent::validation($data, $files);

        if (!eventlist::validate_event_plugin($data['plugin'], $data['eventname'])) {
            $errors['eventname'] = get_string('errorincorrectevent', 'tool_monitor');
        }

        return $errors;
    }
595440
private function checkFields(array $data)
    {
        $ruleset = $this->validationRules();
        $mismatch = array_diff_key($data, $ruleset);
        $fields = array_keys($mismatch);

        foreach ($fields as $field) {
            $this->errors[] = array(
                'field' => $field,
                'value' => $data[$field],
                'rule' => 'mismatch',
                'param' => null,
            );
        }

        return $this;
    }
65635
public static function makeError($message, array $data = [])
    {
        $res = [
            'success' => false,
            'message' => $message,
        ];

        if (!empty($data)) {
            $res['data'] = $data;
        }

        return $res;
    }
57002
public function setErrors($errors) 
	{
		if(is_array($errors)) {
			$this->errors = $errors;
			return $this;
		}
		
		$args = func_get_args();
		$this->errors[$args[0]] = $args[1];
		
		return $this;
	}
1290752
public function validate(array $data, array $rules, array $messages = [])
	{
		// Build the validator.
		$validator = $this->validationFactory->make($data, $rules, $messages);

		// Return the errors, if any.
		if($validator->fails())
		{
			return new Payload($validator->messages(), 'invalid');
		}

		return new Payload($data, 'valid');
	}
470682
private function mergeErrors($errors)
    {
        if (is_null($errors)) {
            return;
        }

        $errors       = is_array($errors) ? $errors : [$errors];
        $this->errors = array_merge($this->errors, $errors);
    }
598873
public function validate(?array $data): array
    {
        $errorMsgs = [];
        foreach ($this->fieldsRuleProperties as $fieldName => $ruleProperties) {
            // Get value to validate
            if (isset($data[$fieldName])) {
                $value = $data[$fieldName];

                // Trim all values unless explicitly set to not
                if (is_string($value) && (!isset($ruleProperties['trim']) || $ruleProperties['trim'] === true)) {
                    $value = trim($value);
                }
                // allow a nullable value to be added as validated data
            } elseif (!empty($ruleProperties['nullable']) && array_key_exists($fieldName, $data)) {
                $value = null;
                // Don't validate empty values that are not set and not required
            } elseif (empty($ruleProperties['required']) && empty($ruleProperties['nonEmpty'])) {
                continue;
            } else {
                // Empty string as default (not null because that adds complexity to checks)
                $value = '';
            }

            // Validate value against each of the fields' rules
            $errorMsg = $this->validateValue($value, $ruleProperties);

            // If field has any error messages, add to error array, otherwise add value to validated data
            if ($errorMsg) {
                $errorMsgs[$fieldName] = $errorMsg;
            } else {
                $this->validatedData[$fieldName] = $value;
            }
        }

        return $errorMsgs;
    }
132340
public function validation($data, $files) {
        $errors = parent::validation($data, $files);

        if ($this->_form->_submitValues['subject'] == 'none') {
            $errors['subject'] = get_string('mustselectsubject', 'hub');
        }

        return $errors;
    }
897570
public static function createUsingErrors(array $errors)
    {
        $message = "An error was encountered reading an XML document:\n";

        foreach ($errors as $error) {
            switch ($error->level) {
                case LIBXML_ERR_ERROR:
                    $message .= '[Error] ';
                    break;
                case LIBXML_ERR_FATAL:
                    $message .= '[Fatal] ';
                    break;
                case LIBXML_ERR_WARNING:
                    $message .= '[Warning] ';
                    break;
            }

            $message .= sprintf(
                "[line %d] [column %d] %s in \"%s\".\n",
                $error->line,
                $error->column,
                trim($error->message),
                $error->file
            );
        }

        return new self($message);
    }
653902
public function createActions(array $data): array
    {
        return array_map(function ($data) {
            if ($data instanceof RuleAction) {
                return $data;
            }

            return RuleAction::createFromData((array) $data);
        }, $data);
    }