@param Node\Stmt\ClassMethod $node
@param Scope                 $scope

@return array
354571
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 {
            if (!$node->default instanceof Node\Expr\ConstFetch) {
                return false;
            }

            return 'null' === $node->default->name->toLowerString();
        });

        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 null as default value.',
                    $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 null as default value.',
                $className,
                $methodName,
                $parameterName
            );
        }, $params);
    }
538336
private function collectMemberReferences(Node $node, ClassMemberQuery $query): array
    {
        $memberNodes = [];
        $memberName = null;

        if (false === $query->hasType() || $query->type() === ClassMemberQuery::TYPE_METHOD) {
            if ($node instanceof MethodDeclaration) {
                $memberName = $node->name->getText($node->getFileContents());

                if ($query->matchesMemberName($memberName)) {
                    $memberNodes[] = $node;
                }
            }

            if ($this->isMethodAccess($node)) {
                $memberName = $node->callableExpression->memberName->getText($node->getFileContents());

                if ($query->matchesMemberName($memberName)) {
                    $memberNodes[] = $node->callableExpression;
                }
            }
        }

        if (false === $query->hasType() || $query->type() === ClassMemberQuery::TYPE_PROPERTY) {
            /** @var PropertyDeclaration $node */
            if ($node instanceof PropertyDeclaration) {
                if ($node->propertyElements) {
                    foreach ($node->propertyElements->getChildNodes() as $propertyElement) {

                        if ($propertyElement instanceof AssignmentExpression) {
                            $propertyElement = $propertyElement->leftOperand;
                        }

                        if ($propertyElement instanceof Variable) {
                            $memberName = $propertyElement->name->getText($propertyElement->getFileContents());
                            if ($query->matchesMemberName($memberName)) {
                                $memberNodes[] = $propertyElement;
                            }
                        }
                    }
                }
            }

            // property access - only if it is not part of a call() expression
            if ($node instanceof MemberAccessExpression && false === $node->parent instanceof CallExpression) {
                $memberName = $node->memberName->getText($node->getFileContents());
                if (is_string($memberName) && $query->matchesMemberName($memberName)) {
                    $memberNodes[] = $node;
                }
            }

            if ($node instanceof ScopedPropertyAccessExpression && false === $node->parent instanceof CallExpression) {
                $memberName = $node->memberName->getText($node->getFileContents());

                // TODO: Some better way to determine if member names are properties
                if (substr($memberName, 0, 1) == '$' && $query->matchesMemberName($memberName)) {
                    $memberNodes[] = $node;
                }
            }
        }

        if (false === $query->hasType() || $query->type() === ClassMemberQuery::TYPE_CONSTANT) {
            if ($node instanceof ClassConstDeclaration) {
                if ($node->constElements) {
                    foreach ($node->constElements->getChildNodes() as $constElement) {
                        assert($constElement instanceof ConstElement);
                        $memberName = $constElement->name->getText($constElement->getFileContents());
                        if ($query->matchesMemberName($memberName)) {
                            $memberNodes[] = $constElement;
                        }
                    }
                }
            }

            if ($node instanceof ScopedPropertyAccessExpression && false === $node->parent instanceof CallExpression) {
                $memberName = $node->memberName->getText($node->getFileContents());
                if ($query->matchesMemberName($memberName)) {
                    $memberNodes[] = $node;
                }
            }
        }

        foreach ($node->getChildNodes() as $childNode) {
            $memberNodes = array_merge($memberNodes, $this->collectMemberReferences($childNode, $query));
        }

        return $memberNodes;
    }
169353
function loadScopes(scopes) {
  var scopeMapping = {};
  if (typeof scopes === 'object') {
    for (var s in scopes) {
      var routes = [];
      var entries = scopes[s];
      debug('Scope: %s routes: %j', s, entries);
      if (Array.isArray(entries)) {
        for (var j = 0, k = entries.length; j < k; j++) {
          var route = entries[j];
          if (typeof route === 'string') {
            routes.push({methods: ['all'], path: route,
              regexp: pathToRegexp(route, [], {end: false})});
          } else {
            var methods = helpers.normalizeList(methods);
            if (methods.length === 0) {
              methods.push('all');
            }
            methods = methods.map(toLowerCase);
            routes.push({methods: methods,
              path: route.path,
              regexp: pathToRegexp(route.path, [], {end: false})});
          }
        }
      } else {
        debug('Routes must be an array: %j', entries);
      }
      scopeMapping[s] = routes;
    }
  } else if (typeof scopes === 'string') {
    scopes = helpers.normalizeList(scopes);
    for (var i = 0, n = scopes.length; i < n; i++) {
      scopeMapping[scopes[i]] = [
        {methods: 'all', path: '/.+', regexp: /\/.+/}
      ];
    }
  }
  return scopeMapping;
}
951363
public function getAppControllersMethod($methodName, $scope = '')
    {
        $methods = [];
        
        if ($this->appControllerRefls) {
            foreach ($this->appControllerRefls as $appRefl) {
                if ($appRefl->hasMethod($methodName)) {
                    $method = $appRefl->getMethod($methodName);
                    
                    if ($this->isApplicationController($method->getDeclaringClass()->getName())) {
                        if ($scope) {
                            $isScope = 'is' . ucfirst($scope);
                            if (!$method->$isScope()) {
                                continue;
                            }
                        }
                        $methods[] = $method->getClosure($this);
                    }
                }
            }
        }
        
        return $methods;
    }
895323
public static function oneByScope($scope, $scope_id)
	{
		return self::all()
			->whereEquals('scope', $scope)
			->whereEquals('scope_id', $scope_id)
			->ordered()
			->row();
	}
416686
public static function getGlobalScope($scope)
    {
        return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope)
        {
            return $scope instanceof $value;
        });
    }
939678
private function getModifiedVariableNames(Node $node)
    {
        switch (true) {
            case $node instanceof Node\Stmt\Foreach_:
                return $this->extractModifiedVariableNames(array($node->keyVar, $node->valueVar));

            case $node instanceof Node\Stmt\Unset_:
                $modifiedNames = $this->extractModifiedVariableNames($node->vars);
                $scope = $this->getCurrentScope();
                foreach ($modifiedNames as $name) {
                    $scope->unsetVariable($name);
                }

                return $modifiedNames;

            case $node instanceof Node\Stmt\Global_:
            case $node instanceof Node\Expr\List_:
                return $this->extractModifiedVariableNames($node->vars);

            case $node instanceof Node\Expr\Assign:
            case $node instanceof Node\Expr\AssignOp:
            case $node instanceof Node\Expr\PostDec:
            case $node instanceof Node\Expr\PostInc:
            case $node instanceof Node\Expr\PreDec:
            case $node instanceof Node\Expr\PreInc:
                return $this->extractModifiedVariableNames(array($node->var));

            case $node instanceof Node\Expr\FuncCall:
            case $node instanceof Node\Expr\StaticCall:
            case $node instanceof Node\Expr\MethodCall:
                $byReferenceArguments = $this->functionAnalyzer->getByReferenceCallArguments($node);

                return $this->extractModifiedVariableNames($byReferenceArguments);

            case $node instanceof Node\Expr\AssignRef:
                return $this->addVariableReference($node);

            default:
                throw new \InvalidArgumentException(sprintf('Unknown node type %s', get_class($node)));
        }
    }
736879
public function getQueryNames(AbstractNode $node, ReflectionClass $reflectionNodeClass): array
    {
        $queryNames = [];

        $queryNodes = $this->getQueryNodes($node);

        foreach ($queryNodes as $queryNode) {
            $queryName = $queryNode->getName();

            if (!$this->isQueryMethod($queryName) || $reflectionNodeClass->hasMethod($queryName)) {
                continue;
            }

            $queryNames[] = $queryName;
        }

        return array_unique($queryNames);
    }
242157
protected function getQueryNodes(AbstractNode $node): array
    {
        $methodPostfix = $node->findChildrenOfType('MethodPostfix');
        $classOrInterfaceReference = $node->findChildrenOfType('ClassOrInterfaceReference');

        return array_merge($methodPostfix, $classOrInterfaceReference);
    }
968165
public function processNode(Node $node, Scope $scope): array
    {
        if (!$node->extends instanceof Node\Name) {
            return [];
        }

        $extendedClassName = $node->extends->toString();

        if (\in_array($extendedClassName, $this->classesAllowedToBeExtended, true)) {
            return [];
        }

        if (!isset($node->namespacedName)) {
            return [
                \sprintf(
                    'Anonymous class is not allowed to extend "%s".',
                    $extendedClassName
                ),
            ];
        }

        return [
            \sprintf(
                'Class "%s" is not allowed to extend "%s".',
                $node->namespacedName,
                $extendedClassName
            ),
        ];
    }
1237042
public function applyScopeToQuery($scope, $query)
    {
        if (is_string($scope)) {
            $scope = $this->getScope($scope);
        }

        if (!$scope->value) {
            return;
        }

        switch ($scope->type) {
            case 'date':
                if ($scope->value instanceof Carbon) {
                    $value = $scope->value;

                    /*
                     * Condition
                     */
                    if ($scopeConditions = $scope->conditions) {
                        $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                            ':filtered' => $value->format('Y-m-d'),
                            ':after'    => $value->format('Y-m-d H:i:s'),
                            ':before'   => $value->copy()->addDay()->addMinutes(-1)->format('Y-m-d H:i:s')
                        ])));
                    }
                    /*
                     * Scope
                     */
                    elseif ($scopeMethod = $scope->scope) {
                        $query->$scopeMethod($value);
                    }
                }

                break;

            case 'daterange':
                if (is_array($scope->value) && count($scope->value) > 1) {
                    list($after, $before) = array_values($scope->value);

                    if ($after && $after instanceof Carbon && $before && $before instanceof Carbon) {

                        /*
                         * Condition
                         */
                        if ($scopeConditions = $scope->conditions) {
                            $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                                ':afterDate'  => $after->format('Y-m-d'),
                                ':after'      => $after->format('Y-m-d H:i:s'),
                                ':beforeDate' => $before->format('Y-m-d'),
                                ':before'     => $before->format('Y-m-d H:i:s')
                            ])));
                        }
                        /*
                         * Scope
                         */
                        elseif ($scopeMethod = $scope->scope) {
                            $query->$scopeMethod($after, $before);
                        }
                    }
                }

                break;

            case 'number':
                if (is_numeric($scope->value)) {
                    /*
                     * Condition
                     */
                    if ($scopeConditions = $scope->conditions) {
                        $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                            ':filtered' => $scope->value,
                        ])));
                    }
                    /*
                     * Scope
                     */
                    elseif ($scopeMethod = $scope->scope) {
                        $query->$scopeMethod($scope->value);
                    }
                }

                break;

            case 'numberrange':
                if (is_array($scope->value) && count($scope->value) > 1) {
                    list($min, $max) = array_values($scope->value);

                    if ($min && $max) {

                        /*
                         * Condition
                         *
                         */
                        if ($scopeConditions = $scope->conditions) {
                            $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                                ':min'  => $min,
                                ':max'  => $max
                            ])));
                        }
                        /*
                         * Scope
                         */
                        elseif ($scopeMethod = $scope->scope) {
                            $query->$scopeMethod($min, $max);
                        }
                    }
                }

                break;

            case 'text':
                /*
                 * Condition
                 */
                if ($scopeConditions = $scope->conditions) {
                    $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                        ':value' => Db::getPdo()->quote($scope->value),
                    ])));
                }

                /*
                 * Scope
                 */
                elseif ($scopeMethod = $scope->scope) {
                    $query->$scopeMethod($scope->value);
                }

                break;

            default:
                $value = is_array($scope->value) ? array_keys($scope->value) : $scope->value;

                /*
                 * Condition
                 */
                if ($scopeConditions = $scope->conditions) {

                    /*
                     * Switch scope: multiple conditions, value either 1 or 2
                     */
                    if (is_array($scopeConditions)) {
                        $conditionNum = is_array($value) ? 0 : $value - 1;
                        list($scopeConditions) = array_slice($scopeConditions, $conditionNum);
                    }

                    if (is_array($value)) {
                        $filtered = implode(',', array_build($value, function ($key, $_value) {
                            return [$key, Db::getPdo()->quote($_value)];
                        }));
                    }
                    else {
                        $filtered = Db::getPdo()->quote($value);
                    }

                    $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [':filtered' => $filtered])));
                }
                /*
                 * Scope
                 */
                elseif ($scopeMethod = $scope->scope) {
                    $query->$scopeMethod($value);
                }

                break;
        }

        return $query;
    }
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;
    }
623508
protected function addToScopes(TreeScope $scope)
    {
        $this->scopes[] = $scope;
        $this->scopeByName[$scope->getName()] = $scope;
        $this->scopeByModelRootId[$scope->getModelRootId()] = $scope;
        $this->scopeByPathPrefix[$scope->getPathPrefix()] = $scope;
    }
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);
    }
1172
private function getContainingClassType(Node $node)
    {
        $classFqn = $this->getContainingClassFqn($node);
        return $classFqn ? new Types\Object_(new Fqsen('\\' . $classFqn)) : null;
    }
1115431
public function processNode(Node $node, Scope $scope): array
	{
		if (!$scope->isInClass()) {
			throw new \PHPStan\ShouldNotHappenException();
		}

		$methodReflection = $scope->getClassReflection()->getNativeMethod($node->name->name);

		$messages = [];

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

			/** @var string $message */
			$message = $message;

			$messages[] = $message;
		}

		return $messages;
	}
617566
public function processNode(Node $node, Scope $scope): array
    {
        $messages       = [];
        $nodeIdentifier = $node->name;
        if (null === $nodeIdentifier) {
            return $messages;
        }
        $name = $nodeIdentifier->name;
        if (0 === \strpos($name, 'AnonymousClass')) {
            return $messages;
        }

        $fqcn = $node->namespacedName->toString();
        if ($node instanceof Interface_) {
            if (! \preg_match('/Interface$/', $name)) {
                $messages[] = \sprintf('Interface %s should end with "Interface" suffix.', $fqcn);
            }
        } elseif ($node instanceof Trait_) {
            if (! \preg_match('/Trait$/', $name)) {
                $messages[] = \sprintf('Trait %s should end with "Trait" suffix.', $fqcn);
            }
        } else {
            $classRef = $this->broker->getClass($fqcn)->getNativeReflection();

            if ($classRef->isAbstract()) {
                if (false !== \strpos($name, '_')) {
                    $match = \preg_match('/_Abstract[^_]+$/', $name);
                } else {
                    $match = \preg_match('/^Abstract/', $name);
                }
                if (! $match) {
                    $messages[] = \sprintf('Abstract class %s should start with "Abstract" prefix.', $fqcn);
                }
            }
            if ($classRef->isSubclassOf(\Exception::class)) {
                if (! \preg_match('/Exception$/', $name)) {
                    $messages[] = \sprintf('Exception class %s should end with "Exception" suffix.', $fqcn);
                }
            }
        }

        return $messages;
    }