Fetch and clear message queue.

@param string $scope
@return array
345435
public function fetch($scope = null)
    {
        $messages = $this->all($scope);
        $this->clear($scope);

        return $messages;
    }
627065
protected function formatScopes($unformatted = [])
    {
        if (is_null($unformatted)) {
            return [];
        }

        $scopes = [];
        foreach ($unformatted as $scope) {
            if ($scope instanceof ScopeEntity) {
                $scopes[$scope->getId()] = $scope;
            }
        }

        return $scopes;
    }
45599
public function processNode(Node $node, Scope $scope): array
	{
		$functionReflection = $this->broker->getCustomFunction(new Node\Name($node->name->name), $scope);

		$messages = [];

		foreach (ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getParameters() as $parameterReflection) {
			$message = $this->checkFunctionParameter($functionReflection, $parameterReflection);
			if ($message === null) {
				continue;
			}

			$messages[] = $message;
		}

		return $messages;
	}
373442
public function processNode(Node $node, Scope $scope): array
    {
        $messages = [];

        $parameters = [];
        foreach ($node->getParams() as $parameter) {
            $variable = $parameter->var;
            if ($variable instanceof Variable && \is_string($variable->name)) {
                $parameters[$variable->name] = true;
            }
        }
        if ($node instanceof Closure) {
            foreach ($node->uses as $use) {
                if (\is_string($use->var->name)) {
                    $parameters[$use->var->name] = true;
                }
            }
        }

        $unusedVariables = [];
        $usedVariables   = [];
        $this->gatherVariablesUsage($node, $unusedVariables, $usedVariables, $parameters, $node);

        foreach ($unusedVariables as $varName => $var) {
            if (! isset($usedVariables[$varName])) {
                $messages[] = \sprintf('[Line %3s] %s has an unused variable $%s.',
                    $var->getAttribute('startLine'),
                    \in_array('name', $node->getSubNodeNames(), true) && isset($node->name)
                        ? \sprintf('Function %s()', $node->name)
                        : 'Closure function',
                    $varName
                );
            }
        }

        return $messages;
    }
566674
public function scope(Scope $scope)
    {
        $callable = $scope->getQuery();

        if (is_string($callable)) {
            /*
             * Adds a Class "ClassName::class" syntax.
             *
             * @note In this case Query class should implement Contracts\Module\Queryable interface.
             * @example: (new Scope('name'))->setQuery(Queryable::class);
             */
            if (class_exists($callable)) {
                $object = app($callable);

                if (!method_exists($object, 'query')) {
                    throw new \Terranet\Administrator\Exception(
                        sprintf(
                            'Query object %s should implement %s interface',
                            get_class($object),
                            \Terranet\Administrator\Contracts\Module\Queryable::class
                        )
                    );
                }

                $this->query = $object->query($this->query);

                return $this;
            }

            /*
             * Allows "SomeClass@method" syntax.
             *
             * @example: (new Scope('name'))->addQuery("User@active")
             */
            if (str_contains($callable, '@')) {
                list($object, $method) = explode('@', $callable);

                $this->query = app($object)->$method($this->query);

                return $this;
            }
        }

        /*
         * Allows adding a \Closure as a query;
         *
         * @example: (new Scope('name'))->setQuery(function($query) { return $this->modify(); })
         */
        if ($callable instanceof Closure) {
            $this->query = $callable($this->query);

            return $this;
        }

        /*
         * Accepts callable builder
         *
         * @example: (new Scope('name'))->setQuery([SomeClass::class, "queryMethod"]);
         */
        if (is_callable($callable)) {
            list($object, $method) = $callable;

            if (is_string($object)) {
                $object = app($object);
            }

            // Call Model Scope immediately when detected.
            //
            // @note: We don't use call_user_func_array() here
            // because of missing columns in returned query.
            $this->query = with(
                $this->model->is($object) ? $this->query : $object
            )->{$method}($this->query);
        }

        return $this;
    }
391400
public function purge($scope = null)
    {
        // Get scope if not passed
        if (null === $scope) {
            $scope = $this->getScope();
        }

        // Return result of purge
        return $this->getContainer()->purge($scope);
    }
30379
public function processNode(Node $node, Scope $scope): array
    {
        if (!isset($node->namespacedName) || !$node->getReturnType() instanceof Node\NullableType) {
            return [];
        }

        return [
            \sprintf(
                'Function %s() has a nullable return type declaration.',
                $node->namespacedName
            ),
        ];
    }
1109744
public function messages($reset = true)
    {
        $messages = $this->_messages;
        if ($reset) {
            $this->_messages = array();
        }

        return $messages;
    }
360625
protected function getAvailableOptions($scope, $searchQuery = null)
    {
        if ($scope->options) {
            return $this->getOptionsFromArray($scope, $searchQuery);
        }

        $available = [];
        $nameColumn = $this->getScopeNameFrom($scope);
        $options = $this->getOptionsFromModel($scope, $searchQuery);
        foreach ($options as $option) {
            $available[$option->getKey()] = $option->{$nameColumn};
        }

        return $available;
    }
733210
public function retrieve($domain)
	{
		if (!($messages = Monster::eat($this->key($domain))))
		{
			$messages = array();
		}

		if (count($messages))
		{
			$this->clear($domain);
		}

		return $messages;
	}
1325851
public function to($scope)
    {
        if (isset($this->paths[$scope])) {
            return $this->paths[$scope];
        }

        throw new OutOfBoundsException("Path of '$scope' was not mapped");
    }
651816
protected function _files($category, $locale, $scope) {
		$path = $this->_config['path'];
		$scope = $scope ?: 'default';

		if (($pos = strpos($category, 'Template')) !== false) {
			$category = substr($category, 0, $pos);
			return ["{$path}/{$category}_{$scope}.pot"];
		}

		if ($category === 'message') {
			$category = 'messages';
		}
		$category = strtoupper($category);

		return [
			"{$path}/{$locale}/LC_{$category}/{$scope}.mo",
			"{$path}/{$locale}/LC_{$category}/{$scope}.po"
		];
	}
1052363
public static function getGlobalScope($scope)
    {
        if (! is_string($scope)) {
            $scope = get_class($scope);
        }

        return array_get(static::$globalScopes, static::class.'.'.$scope);
    }
416686
public static function getGlobalScope($scope)
    {
        return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope)
        {
            return $scope instanceof $value;
        });
    }
829059
public function processNode(Node $node, Scope $scope): array
    {
        $messages   = [];
        $docComment = $node->getDocComment();
        if (empty($docComment)) {
            return $messages;
        }
        $hash = \sha1(\sprintf('%s:%s:%s:%s',
            $scope->getFile(),
            $docComment->getLine(),
            $docComment->getFilePos(),
            $docComment->getText()
        ));
        if (isset($this->alreadyParsedDocComments[$hash])) {
            return $messages;
        }
        $this->alreadyParsedDocComments[$hash] = true;

        $lines = \preg_split('/\R/u', $docComment->getText());
        if (false === $lines) {
            return $messages;
        }
        foreach ($lines as $lineNumber => $lineContent) {
            $matches = [];
            if (! \preg_match('/^(?:\s*\*\s*@(?:expectedException|covers|coversDefaultClass|uses)\h+)\\\\?(?<className>\w[^:\s]*)(?:::\S+)?\s*$/u', $lineContent, $matches)) {
                continue;
            }
            if (! $this->broker->hasClass($matches['className'])) {
                $messages[] = \sprintf('Class %s does not exist (line: %s).', $matches['className'], $docComment->getLine() + $lineNumber);
            }
        }

        return $messages;
    }
338935
public function restoreSorting(array $scope = []): void
    {
        $records = $this->_table->find()
            ->select([$this->_table->getPrimaryKey(), $this->getConfig('sortField')])
            ->select($this->getConfig('columnScope'))
            ->order($this->getConfig('defaultOrder'));

        if (!empty($scope)) {
            $records->where($scope);
        }

        $sorts = [];
        foreach ($records as $entity) {
            $individualScope = '';
            foreach ($this->getConfig('columnScope') as $column) {
                $individualScope .= $entity->get($column);
            }

            if (!isset($sorts[$individualScope])) {
                $sorts[$individualScope] = 0;
            }

            $sort = ++$sorts[$individualScope];
            $this->_table->updateAll([
                $this->getConfig('sortField') => $sort,
            ], [
                $this->_table->getPrimaryKey() => $entity->get($this->_table->getPrimaryKey()),
            ]);
        }
    }
1090056
public function setScope($scope)
    {
        if (empty($scope)) {
            return $this->clearScope();
        }

        session()->put($this->getSessionKey(static::TYPE_SCOPE), $scope);

        return $this;
    }