Configuration checker

Ensures recursively that features list is an array or a multi-array of
booleans, indexed by strings.

@param $testedVar
@return void
@throws \InvalidArgumentException
512567
protected function ensureVarIsArrayOrMultiArrayOfBooleans($testedVar)
    {
        // Must be an array
        if (!is_array($testedVar)) {
            throw new \InvalidArgumentException('Features list must be an array or a multi-array of booleans.');
        }

        foreach ($testedVar as $key => $element) {
            // Must be indexed by string
            if (!is_string($key)) {
                throw new \InvalidArgumentException('Features must be indexed by string keys.');
            }

            // Must be boolean or array
            if (!is_bool($element) && !is_array($element)) {
                throw new \InvalidArgumentException('Features list must be an array or a multi-array of booleans.');
            }

            // Recursive check
            if (is_array($element)) {
                $this->ensureVarIsArrayOrMultiArrayOfBooleans($element);
            }
        }
    }
82387
protected function remove_blacklisted_features_from_list($features, $blacklist) {

        // If no blacklist passed then return.
        if (empty($blacklist)) {
            return $features;
        }

        // If there is no feature in suite then just return what was passed.
        if (empty($features)) {
            return $features;
        }

        if (!is_array($blacklist)) {
            $blacklist = array($blacklist);
        }

        // Remove blacklisted features.
        foreach ($blacklist as $blacklistpath) {

            list($key, $featurepath) = $this->get_clean_feature_key_and_path($blacklistpath);

            if (isset($features[$key])) {
                $features[$key] = null;
                unset($features[$key]);
            } else {
                $featurestocheck = $this->get_components_features();
                if (!isset($featurestocheck[$key]) && (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST)) {
                    behat_error(BEHAT_EXITCODE_REQUIREMENT, 'Blacklisted feature "' . $blacklistpath . '" not found.');
                }
            }
        }

        return $features;
    }
409794
public static function assertInstanceOf($variable, $expectedInstanceOf)
    {
        if (!is_string($expectedInstanceOf) && !is_object($expectedInstanceOf)) {
            throw new InvalidArgumentException(
                sprintf(
                    '$expectedInstanceOf should be a string or object, got %s',
                    gettype($expectedInstanceOf)
                )
            );
        }

        if (! $variable instanceof $expectedInstanceOf) {
            throw new InvalidArgumentException(
                sprintf(
                    'The variable is not hold the expected type of instance. [Expected: %s, Given: %s]',
                    $expectedInstanceOf,
                    is_object($variable) ? get_class($variable) : gettype($variable)
                )
            );
        }
    }
1018835
public function pushOnVariableStack($values)
    {
        if (is_array($values) === false) {
            $values = array($values);
        }

        foreach ($values as $value) {
            if (is_string($value) === false) {
                $msg = "The pushOnVariableStack method only accepts non-empty string values.";
                throw new InvalidArgumentException($msg);
            }

            $this->getVariableStack()->push($value);
        }
    }
1294713
public function setAttributes($values){

        if(is_array($values)){
            foreach($values as $name => $value){
                $this->setAttribute($name, $value);
            }
        }else{
            throw new InvalidArgumentException('"values" must be an array');
        }

    }
326928
private function _checkVariableConfiguration() {
		// Check if the canUploadImage is boolean
		if (!is_bool($this->canUploadImage)) {
			throw new InvalidConfigException('$canUploadImage variable only supports a boolean value, if you have a custom function you must return a boolean.');
		}
		// Check if the canRemoveImage is boolean
		if (!is_bool($this->canRemoveImage)) {
			throw new InvalidConfigException('$removeImageAllowed variable only supports a boolean value, if you have a custom function you must return a boolean.');
		}
		// Check if the setBlamableBehavior is boolean
        if (! is_bool($this->setBlameableBehavior))
            throw new InvalidConfigException('$setBlameableBehavior only supports a boolean value, if you have a custom function make sure that you return a boolean.');
        // Check if the deleteOriginalAfterEdit is boolean
        if (! is_bool($this->deleteOriginalAfterEdit))
            throw new InvalidConfigException('$deleteOriginalAfterEdit only supports boolean value, if you have a custom function make sure that your return a boolean.');

		// Check if the blameable behavior is set to true
        if ($this->setBlameableBehavior) {
            // Get the migration record
            $mRecordMigrationRun = Yii::$app->db->createCommand('SELECT * FROM {{%migration}} WHERE `version` = \'m170223_113221_addBlameableBehavior\'')->queryOne();
            if ($mRecordMigrationRun === false) {
                throw new InvalidConfigException('Image Manager: You have not run the latest migration, see the documentation how to do this.');
            }
        }
	}
870381
public function fit(array $values) : void
    {
        if (empty($values)) {
            throw new InvalidArgumentException('Strategy must be fit with'
                . ' at least 1 value.');
        }

        $categories = array_values(array_unique($values));

        $this->categories = $categories;
        $this->k = count($categories);
    }
151400
public static function isArray($value, $message = null)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected array, but got %s',
                Helper::typeToString($value)
            ));
        }
    }
1079163
private function boolToString($var)
    {
        $copy = is_array($var) ? $var : [$var];

        foreach ($copy as $key => $value) {
            if (is_bool($value)) {
                $copy[$key] = $value ? '1' : '0';
            }
        }

        return is_array($var) ? $copy : $copy[0];
    }
1321925
public function search($methodVars)
    {
        // Check for required variables
        if (!empty($methodVars['tag'])) {
            $vars = array(
                'method' => 'tag.search',
                'api_key' => $this->auth->apiKey
            );
            $vars = array_merge($vars, $methodVars);

            if ($call = $this->apiGetCall($vars)) {
                $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/');
                if ($opensearch->totalResults > 0) {
                    $searchResults['totalResults'] = (string) $opensearch->totalResults;
                    $searchResults['startIndex'] = (string) $opensearch->startIndex;
                    $searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage;
                    $i = 0;
                    foreach ($call->results->tagmatches->tag as $tag) {
                        $searchResults['results'][$i]['name'] = (string) $tag->name;
                        $searchResults['results'][$i]['count'] = (string) $tag->count;
                        $searchResults['results'][$i]['url'] = (string) $tag->url;
                        $i++;
                    }
                    return $searchResults;
                } else {
                    throw new NoResultsException('No results');
                }
            } else {
                return false;
            }
        } else {
            throw new InvalidArgumentException('You must include tag variable in the call for this method');
        }
    }
609436
public static function isNullOrArray($value, $message = null)
    {
        if (!is_null($value) && !is_array($value)) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected null or array, but got %s',
                Helper::typeToString($value)
            ));
        }
    }
283035
public function has($value)
    {
        if (!is_string($value) && !is_array($value)) {
            throw new \InvalidArgumentException('The ValueSet\'s "has" method requires the argument to be of type string or array');
        }

        if (is_string($value)) {
            return $this->__isset($value);
        } elseif (is_array($value)) {
            foreach ($value as $name) {
                if (!$this->__isset($value)) {
                    return false;
                }
            }

            return true;
        }
    }
218659
protected function _checkedOptions($value, $selected, array $attrs)
    {
        $attrs['checked'] = false;
        if (is_array($selected)) {
            foreach ($selected as $val) {
                if ($value == $val) {
                    $attrs['checked'] = 'checked';
                    break;
                }
            }
        } else {
            if ($value == $selected) {
                $attrs['checked'] = 'checked';
            }
        }

        return $attrs;
    }
6375
protected function _checkSelected(array $options, $selectedVal)
    {
        if (!empty($selectedVal) && !Arr::key($selectedVal, $options)) {
            $selectedVal = self::KEY_NO_EXITS_VAL;
            $options = array_merge(array(self::KEY_NO_EXITS_VAL => $this->_translate('No exits')), $options);
        }

        return array($options, $selectedVal);
    }
142121
public function has($var)
    {
        if (!is_string($var)) {
            throw new \InvalidArgumentException('Expected a string. Got: ' . (is_object($var) ? get_class($var) : gettype($var)));
        }
        return isset($this->{$var}) && !empty($this->{$var});
    }
1352732
public static function assertIsArray($variable, Throwable $exception): bool
    {
        static::makeAssertion(\is_array($variable), $exception);
        return true;
    }
1191827
public function assertIsArray($value, $message='%s must be an Array', $exception='Asserts')
    {
        if (isset($value) === false || is_array($value) === false) {
            $this->throwException($exception, $message, $value);
        }
    }