Figure out which includes we need.

@internal

@param Scope $scope

@return array
351193
private function figureOutWhichIncludes(Scope $scope)
    {
        $includes = $this->getDefaultIncludes();

        foreach ($this->getAvailableIncludes() as $include) {
            if ($scope->isRequested($include)) {
                $includes[] = $include;
            }
        }

        foreach ($includes as $include) {
            if ($scope->isExcluded($include)) {
                $includes = array_diff($includes, [$include]);
            }
        }

        return $includes;
    }
474499
public function addScope($scope)
    {
        $this->validateScopeValue($scope);

        if (false !== $this->getScopeKey($scope)) {
            return $this;
        }

        $this->descriptor['scopes'][] = $scope;
        return $this;
    }
345315
protected function _options(array $defaults, array $scope) {
		$scope += $defaults;
		$options = array_diff_key($scope, $defaults);
		return [$scope, $options];
	}
203552
public function &getScope($scope)
    {
        if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) {
            return $this->parent->tpl_vars;
        } elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) {
            $ptr = $this->parent;
            while (!empty($ptr->parent)) {
                $ptr = $ptr->parent;
            }

            return $ptr->tpl_vars;
        } elseif ($scope == Smarty::SCOPE_GLOBAL) {
            return Smarty::$global_tpl_vars;
        }
        $null = null;

        return $null;
    }
263826
public function checkScope($scope)
  {
      if ($this->OAuthResponse) {
          return $this->OAuthResponse->hasScope($scope);
      }

      return in_array($scope, $this->getScope());
  }
1292053
protected function findScopeSelectors($scope, $depth)
    {
        if ($scope->depth === $depth && $scope->selectors) {
            return $scope->selectors;
        }

        if ($scope->children) {
            foreach (array_reverse($scope->children) as $c) {
                if ($s = $this->findScopeSelectors($c, $depth)) {
                    return $s;
                }
            }
        }

        return [];
    }
815240
public function processNode(Node $node, Scope $scope): array
    {
        if (0 === \count($node->params)) {
            return [];
        }

        $params = \array_filter($node->params, static function (Node\Param $node): bool {
            return $node->type instanceof Node\NullableType;
        });

        if (0 === \count($params)) {
            return [];
        }

        $methodName = $node->name->toString();

        /** @var Reflection\ClassReflection $classReflection */
        $classReflection = $scope->getClassReflection();

        if ($classReflection->isAnonymous()) {
            return \array_map(static function (Node\Param $node) use ($methodName): string {
                /** @var Node\Expr\Variable $variable */
                $variable = $node->var;

                /** @var string $parameterName */
                $parameterName = $variable->name;

                return \sprintf(
                    'Method %s() in anonymous class has parameter $%s with a nullable type declaration.',
                    $methodName,
                    $parameterName
                );
            }, $params);
        }

        $className = $classReflection->getName();

        return \array_map(static function (Node\Param $node) use ($className, $methodName): string {
            /** @var Node\Expr\Variable $variable */
            $variable = $node->var;

            /** @var string $parameterName */
            $parameterName = $variable->name;

            return \sprintf(
                'Method %s::%s() has parameter $%s with a nullable type declaration.',
                $className,
                $methodName,
                $parameterName
            );
        }, $params);
    }
1262163
protected function filterScopeWithout($scope, $without)
    {
        $filteredScopes = [];

        if ($scope->type === TYPE::T_ROOT) {
            return $scope;
        }

        // start from the root
        while ($scope->parent && $scope->parent->type !== TYPE::T_ROOT) {
            $scope = $scope->parent;
        }

        for (;;) {
            if (! $scope) {
                break;
            }

            if (! $this->isWithout($without, $scope)) {
                $s = clone $scope;
                $s->children = [];
                $s->lines = [];
                $s->parent = null;

                if ($s->type !== Type::T_MEDIA && $s->type !== Type::T_DIRECTIVE) {
                    $s->selectors = [];
                }

                $filteredScopes[] = $s;
            }

            if ($scope->children) {
                $scope = end($scope->children);
            } else {
                $scope = null;
            }
        }

        if (!count($filteredScopes)) {
            return $this->rootBlock;
        }

        $newScope = array_shift($filteredScopes);
        $newScope->parent = $this->rootBlock;

        $this->rootBlock->children[] = $newScope;

        $p = &$newScope;

        while (count($filteredScopes)) {
            $s = array_shift($filteredScopes);
            $s->parent = $p;
            $p->children[] = &$s;
            $p = $s;
        }

        return $newScope;
    }
750316
private function getNestedErrors(string $key, array $scope, array $input): array
    {
        $parts = explode('.', $key);
        $current = array_shift($parts);
        $next = implode('.', $parts);

        // The current part is * and there is still some parts, rune the
        // validation on each nested value.
        if ($current == '*' && count($parts) > 0) {

            $errors = [];

            foreach ($scope as $key => $nested) {

                $new_errors = $this->getNestedErrors($next, $nested, $input);

                $errors = array_merge($errors, $new_errors);

            }

            return $errors;

        }

        // There is still some parts, run the validation on the nested value.
        if (count($parts) > 0) {

            return $this->getNestedErrors($next, $scope[$current] ?? [], $input);

        }

        // There is no more parts, run the validation on the current scope.
        return $this->getErrors($current, $scope, $input);
    }
553826
public function getNextSortValue(array $scope = []): int
    {
        $query = $this->_table->query();
        $scope = Hash::merge($this->getConfig('scope'), $scope);
        if (!empty($scope)) {
            $query->where($scope);
        }
        $query->select([
            'maxSort' => $query->func()->max($this->getConfig('sortField')),
        ]);
        $res = $query->enableHydration(false)->first();
        if (empty($res)) {
            return 1;
        }

        return ($res['maxSort'] + 1);
    }
277402
protected function getScopeCounts()
    {
        if ( ! $this->areScopesEnabled()) {
            return [];
        }

        $info = $this->getModelInformation();

        if ( ! $info->list->scopes || ! count($info->list->scopes)) {
            // @codeCoverageIgnoreStart
            return [];
            // @codeCoverageIgnoreEnd
        }

        $counts = [];

        $repository = $this->getModelRepository();

        foreach (array_keys($info->list->scopes) as $key) {

            $this->applyScope($repository, $key);

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

            $this->applyListParentToQuery($query);

            $counts[ $key ] = $query->count();
        }

        return $counts;
    }
1316382
public function can($scope)
    {
        return in_array('*', $this->scopes) ||
               array_key_exists($scope, array_flip($this->scopes));
    }
653977
public function getScopePointer($scope)
    {
        if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) {
            return $this->parent;
        } elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) {
            $ptr = $this->parent;
            while (!empty($ptr->parent)) {
                $ptr = $ptr->parent;
            }

            return $ptr;
        }

        return null;
    }
741257
public static function getAllScopes()
    {
        return array(
            self::SCOPE_MANAGE_ACCOUNTS,
            self::SCOPE_MANAGE_SUBSCRIPTIONS,
            self::SCOPE_COLLECT_PAYMENTS,
            self::SCOPE_PREAPPROVE_PAYMENTS,
            self::SCOPE_VIEW_USER,
            self::SCOPE_SEND_MONEY
        );
    }
485378
public function scopeExists($scope)
    {
        // Check reserved scopes first.
        $scope = explode(' ', trim($scope));
        $reservedScope = $this->getReservedScopes();
        $nonReservedScopes = array_diff($scope, $reservedScope);
        if (count($nonReservedScopes) == 0) {
            return true;
        } else {
            // Check the storage for non-reserved scopes.
            $nonReservedScopes = implode(' ', $nonReservedScopes);

            return $this->storage->scopeExists($nonReservedScopes);
        }
    }
1279220
public function getScopes()
    {
        if (!isset($this->_scopes)) {
            $this->_scopes = clone $this->getService('com:components.domain.entityset.scope');
        }

        return $this->_scopes;
    }
963231
protected function _getScopes($scopes = [])
    {
        if ($scopes) {
            $returnScopes = [];
            foreach ($scopes as $scope) {
                $returnScopes[$scope] = $this->_scopes[$scope];
            }
            return $returnScopes;
        } else {
            return $this->_scopes;
        }
    }