Clean invalid properties.

@param array $attributes attributes input
@param string[] $validKeys  keys that are allowed

@return array
975577
protected function cleanProperties($attributes = [], $validKeys = [])
    {
        $array = [];

        foreach ($attributes as $attribute => $value) {
            if (in_array($attribute, $validKeys)) {
                $array[$attribute] = $value;
            }
        }

        return $array;
    }
54030
private function extractKeys($attributes, $keys)
    {
        if (!$keys) {
            $keys = array_keys($attributes);
        }

        if (!is_array($keys)) {
            $keys = (array) $keys;

            return $keys;
        }

        return $keys;
    }
943653
private function fill($attributes)
    {
        // json
        if (is_string($attributes)) {
            $attributes = json_decode($attributes, true);
        }

        // check if attributes are valid
        if (!is_array($attributes)) {
            throw new \InvalidArgumentException('Attributes must be of type array or a valid json string');
        }

        foreach ($attributes as $key => $value) {
            $this->setAttribute($key, $value);
        }
    }
1328270
public function listInvalidProperties()
    {
        $invalidProperties = [];

        if (!is_null($this->container['sender']) && (strlen($this->container['sender']) > 11)) {
            $invalidProperties[] = "invalid value for 'sender', the character length must be smaller than or equal to 11.";
        }

        return $invalidProperties;
    }
1290389
protected function validateAttributesToLdap(array $attributes)
    {
        if (!$this->schema) {
            return;
        }
        $missing = [];

        foreach ($this->schema->getRequiredAttributes() as $attribute) {
            if (!array_key_exists(strtolower($attribute), array_change_key_case($attributes))) {
                $missing[] = $attribute;
            }
        }

        if (!empty($missing)) {
            throw new LogicException(
                sprintf('The following required attributes are missing: %s', implode(', ', $missing))
            );
        }
    }
983671
def remove_invalid_keys(solr_doc)
      valid_keys = schema_keys
      solr_doc.delete_if { |key, _| !key.in? valid_keys }
    end
850696
public function setAttributes($attributes)
    {
        $attributes = self::prepareAttributes($attributes);
        $watched    = array();
        foreach ($this->watchedAttributes as $watchedKey) {
            if (isset($attributes[$watchedKey])) {
                $this->setAttribute($watchedKey, $attributes[$watchedKey]);
                unset($attributes[$watchedKey]);
            } else {
                $this->removeAttribute($watchedKey);
            }
            if (isset($this->attributes[$watchedKey])) {
                $watched[$watchedKey] = $this->attributes[$watchedKey];
            }
        }
        $this->attributes = array_merge($watched, $attributes);
        return $this;
    }
1048522
def _validateAttrs(self, keys):
        """"""
        badAttrs = []
        for k in keys:
            if k not in self.__dict__:
                badAttrs.append("Attribute key '%s' is not a valid attribute"%(k))
        badAttrsMsg = os.linesep.join(badAttrs)
        if not keys: return # is iterable, but didn't contain any keys
        if badAttrsMsg:
            raise ValueError("Encountered invalid attributes.  ALLOWED: %s%s%s"\
                %(list(self.__dict__), os.linesep, badAttrsMsg))
101640
protected function normalizeUserAttributes($attributes)
    {
        foreach ($this->getNormalizeUserAttributeMap() as $normalizedName => $actualName) {
            if (is_scalar($actualName)) {
                if (array_key_exists($actualName, $attributes)) {
                    $attributes[$normalizedName] = $attributes[$actualName];
                }
            } else {
                if (is_callable($actualName)) {
                    $attributes[$normalizedName] = call_user_func($actualName, $attributes);
                } elseif (is_array($actualName)) {
                    $haystack = $attributes;
                    $searchKeys = $actualName;
                    $isFound = true;
                    while (($key = array_shift($searchKeys)) !== null) {
                        if (is_array($haystack) && array_key_exists($key, $haystack)) {
                            $haystack = $haystack[$key];
                        } else {
                            $isFound = false;
                            break;
                        }
                    }
                    if ($isFound) {
                        $attributes[$normalizedName] = $haystack;
                    }
                } else {
                    throw new InvalidConfigException('Invalid actual name "' . gettype($actualName) . '" specified at "' . get_class($this) . '::normalizeUserAttributeMap"');
                }
            }
        }

        return $attributes;
    }
429370
public function removeActionErrors(...$keys) {
        $errors = $this->getAttribute(ACTION_ERRORS_KEY);
        $dropped = [];

        foreach ($keys as $key) {
            if (isset($errors[$key]))
                $dropped[$key] = $errors[$key];
            unset($this->attributes[ACTION_ERRORS_KEY][$key]);
        }
        if ($keys)
            return $dropped;

        unset($this->attributes[ACTION_ERRORS_KEY]);
        return $errors;
    }
268833
public function deleteAttributes($attributes = null)
    {
        $url = self::makeAttributeUrl();
        if (!empty($attributes))
        {
            $url .= '?' . Util::query_suffix(array('name' => $attributes));
        }
        return $this->service->prepAndSend($url, array(204), 'DELETE', null, false);
    }
1180411
public function listInvalidProperties()
    {
        $invalidProperties = [];

        if ($this->container['name'] === null) {
            $invalidProperties[] = "'name' can't be null";
        }
        if ((strlen($this->container['name']) > 40)) {
            $invalidProperties[] = "invalid value for 'name', the character length must be smaller than or equal to 40.";
        }

        if ((strlen($this->container['name']) < 1)) {
            $invalidProperties[] = "invalid value for 'name', the character length must be bigger than or equal to 1.";
        }

        $allowedValues = $this->getColorAllowableValues();
        if (!in_array($this->container['color'], $allowedValues)) {
            $invalidProperties[] = sprintf(
                "invalid value for 'color', must be one of '%s'",
                implode("', '", $allowedValues)
            );
        }

        return $invalidProperties;
    }
1032124
protected function highlightErrorElement($key, $attributes)
    {
        $elClass = '';
        if (
            $this->validator instanceof ValidatorInterface &&
            $this->validator->hasError($key)
        ) {
            preg_match_all("#class='([^\s]+)'#", $this->attributes($attributes), $matches);
            $elClass = "class='".implode(' ', array_merge([$this->errorInputClass], $matches[1]))."'";
            unset($attributes['class']);
        }

        return [$elClass, $attributes];
    }
1297320
public static function validateMultiple($keys)
    {
        foreach ($keys as $key) {
            if (!is_string($key) && !is_int($key)) {
                throw InvalidKeyException::forKey($key);
            }
        }
    }
466778
public static function areAttributesValid($attributes)
    {
        if (!is_array($attributes)) {
            return false;
        }

        if (empty($attributes)) {
            return true;
        }
        // At least one key string to be an associative array.
        return count(array_filter(array_keys($attributes), 'is_string')) > 0;
    }
1144839
public function deleteIndex($keys)
    {
        if (is_string($keys)) {
            $indexName = $keys;
            if (! preg_match('#_-?1$#', $indexName)) {
                $indexName .= '_1';
            }
        } elseif (is_array($keys)) {
            $indexName = \MongoDB\generate_index_name($keys);
        } else {
            throw new \InvalidArgumentException();
        }

        try {
            return TypeConverter::toLegacy($this->collection->dropIndex($indexName));
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            return ExceptionConverter::toResultArray($e) + ['nIndexesWas' => count($this->getIndexInfo())];
        }
    }
213987
public function formatAttributes(array $attributes) {
        foreach ($attributes as $key => $attr) {
            if ($attr instanceof Closure) {
                $attributes[$key] = call_user_func($attr, $this);

            } else if ($this->hasKeyword($attr)) {
                $attributes[$key] = $this->getKeyword($attr);

            } else if ($attr === true) {
                $attributes[$key] = $this->getKeyword($key);

            } else {
                $attributes[$key] = (string) $attr;
            }
        }

        return $attributes;
    }