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

@return array
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
            ),
        ];
    }
186966
protected function createAssociatedDirectivesOfType(Node $node, string $directiveClass): Collection
    {
        return (new Collection($node->directives))
            ->map(function (DirectiveNode $directive) use ($node) {
                return $this->create($directive->name->value, $node);
            })
            ->filter(function (Directive $directive) use ($directiveClass) {
                return $directive instanceof $directiveClass;
            });
    }
895323
public static function oneByScope($scope, $scope_id)
	{
		return self::all()
			->whereEquals('scope', $scope)
			->whereEquals('scope_id', $scope_id)
			->ordered()
			->row();
	}
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;
    }
1322435
private function collectDefinitionsAndReferences(Node $node)
    {
        $fqn = ($this->definitionResolver)::getDefinedFqn($node);
        // Only index definitions with an FQN (no variables)
        if ($fqn !== null) {
            $this->definitionNodes[$fqn] = $node;
            $this->definitions[$fqn] = $this->definitionResolver->createDefinitionFromNode($node, $fqn);
        } else {

            $parent = $node->parent;
            if (
                (
                    // $node->parent instanceof Node\Expression\ScopedPropertyAccessExpression ||
                    ($node instanceof Node\Expression\ScopedPropertyAccessExpression ||
                    $node instanceof Node\Expression\MemberAccessExpression)
                    && !(
                        $node->parent instanceof Node\Expression\CallExpression ||
                        $node->memberName instanceof PhpParser\Token
                    ))
                || ($parent instanceof Node\Statement\NamespaceDefinition && $parent->name !== null && $parent->name->getStart() === $node->getStart())
            ) {
                return;
            }

            $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node);
            if (!$fqn) {
                return;
            }

            if ($fqn === 'self' || $fqn === 'static') {
                // Resolve self and static keywords to the containing class
                // (This is not 100% correct for static but better than nothing)
                $classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
                if (!$classNode) {
                    return;
                }
                $fqn = (string)$classNode->getNamespacedName();
                if (!$fqn) {
                    return;
                }
            } else if ($fqn === 'parent') {
                // Resolve parent keyword to the base class FQN
                $classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
                if (!$classNode || !$classNode->classBaseClause || !$classNode->classBaseClause->baseClass) {
                    return;
                }
                $fqn = (string)$classNode->classBaseClause->baseClass->getResolvedName();
                if (!$fqn) {
                    return;
                }
            }

            $this->addReference($fqn, $node);

            if (
                $node instanceof Node\QualifiedName
                && ($node->isQualifiedName() || $node->parent instanceof Node\NamespaceUseClause)
                && !($parent instanceof Node\Statement\NamespaceDefinition && $parent->name->getStart() === $node->getStart()
                )
            ) {
                // Add references for each referenced namespace
                $ns = $fqn;
                while (($pos = strrpos($ns, '\\')) !== false) {
                    $ns = substr($ns, 0, $pos);
                    $this->addReference($ns, $node);
                }
            }

            // Namespaced constant access and function calls also need to register a reference
            // to the global version because PHP falls back to global at runtime
            // http://php.net/manual/en/language.namespaces.fallback.php
            if (ParserHelpers\isConstantFetch($node) ||
                ($parent instanceof Node\Expression\CallExpression
                    && !(
                        $node instanceof Node\Expression\ScopedPropertyAccessExpression ||
                        $node instanceof Node\Expression\MemberAccessExpression
                    ))) {
                $parts = explode('\\', $fqn);
                if (count($parts) > 1) {
                    $globalFqn = end($parts);
                    $this->addReference($globalFqn, $node);
                }
            }
        }
    }
416686
public static function getGlobalScope($scope)
    {
        return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope)
        {
            return $scope instanceof $value;
        });
    }
372622
protected function collectPatterns(ClassNode $class)
    {
        $patterns = [];
        foreach ($this->patterns as [$srcPattern, $targetPattern, $message]) {
            if (preg_match($srcPattern, $class->getNamespaceName())) {
                $patterns[] = [$srcPattern, $targetPattern, $message];
            }
        }

        return $patterns;
    }
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"
		];
	}
345435
public function fetch($scope = null)
    {
        $messages = $this->all($scope);
        $this->clear($scope);

        return $messages;
    }
328156
public function renderScopeElement($scope)
    {
        $params = ['scope' => $scope];

        switch ($scope->type) {
            case 'date':
                if ($scope->value && $scope->value instanceof Carbon) {
                    $params['dateStr'] = Backend::dateTime($scope->value, ['formatAlias' => 'dateMin']);
                    $params['date']    = $scope->value->format('Y-m-d H:i:s');
                }

                break;
            case 'daterange':
                if ($scope->value && is_array($scope->value) && count($scope->value) === 2 &&
                    $scope->value[0] && $scope->value[0] instanceof Carbon &&
                    $scope->value[1] && $scope->value[1] instanceof Carbon
                ) {
                    $after = $scope->value[0]->format('Y-m-d H:i:s');
                    $before = $scope->value[1]->format('Y-m-d H:i:s');

                    if(strcasecmp($after, '0000-00-00 00:00:00') > 0) {
                        $params['afterStr'] = Backend::dateTime($scope->value[0], ['formatAlias' => 'dateMin']);
                        $params['after']    = $after;
                    }
                    else {
                        $params['afterStr'] = '∞';
                        $params['after']    = null;
                    }

                    if(strcasecmp($before, '2999-12-31 23:59:59') < 0) {
                        $params['beforeStr'] = Backend::dateTime($scope->value[1], ['formatAlias' => 'dateMin']);
                        $params['before']    = $before;
                    }
                    else {
                        $params['beforeStr'] = '∞';
                        $params['before']    = null;
                    }
                }

                break;
            case 'number':
                if (is_numeric($scope->value)) {
                    $params['number'] = $scope->value;
                }

                break;

            case 'numberrange':
                if ($scope->value && is_array($scope->value) && count($scope->value) === 2 &&
                    $scope->value[0] &&
                    $scope->value[1]
                ) {
                    $min = $scope->value[0];
                    $max = $scope->value[1];

                    $params['minStr'] = $min ?: '';
                    $params['min'] = $min ?: null;

                    $params['maxStr'] = $max ?: '∞';
                    $params['max'] = $max ?: null;
                }

                break;

            case 'text':
                $params['value'] = $scope->value;
                $params['size'] = array_get($scope->config, 'size', 10);

                break;
        }

        return $this->makePartial('scope_'.$scope->type, $params);
    }
1292166
public function processNode(Node $node, Scope $scope): array
	{
		$functionReflection = $this->broker->getCustomFunction(new Node\Name($node->name->name), $scope);
		$returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();

		if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
			return [
				sprintf(
					'Function %s() has no return typehint specified.',
					$functionReflection->getName()
				),
			];
		}

		return [];
	}
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;
    }
1032829
private function resolveImportTable(Node $node): array
    {
        try {
            return $node->getImportTablesForCurrentScope();
        } catch (Exception $e) {
        }

        foreach ($node->getDescendantNodes() as $node) {
            try {
                $imports = $node->getImportTablesForCurrentScope();
                if (empty($imports[0])) {
                    continue;
                }
                return $imports;
            } catch (Exception $e) {
            }
        }

        return [ [], [], [] ];
    }
922365
protected function get_data($scope = 'all')
	{
		$clean_it = function ($data, $rules, $auto_filter)
		{
			foreach ($data as $key => &$value)
			{
				$filter = array_key_exists($key, $rules) ? $rules[$key] : null;
				$filter = is_null($filter) ? $auto_filter : $filter;

				$value = $filter ? \Security::clean($value, null, 'security.output_filter') : $value;
			}

			return $data;
		};

		$data = array();

		if ( ! empty($this->data)  and ($scope === 'all' or $scope === 'local'))
		{
			$data += $clean_it($this->data, $this->local_filter, $this->auto_filter);
		}

		if ( ! empty(static::$global_data)  and ($scope === 'all' or $scope === 'global'))
		{
			$data += $clean_it(static::$global_data, static::$global_filter, $this->auto_filter);
		}

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

        return array_merge($methodPostfix, $classOrInterfaceReference);
    }
1301483
private Map<String, Scope> parseScopes(NodeList scopeNodeList) {
        Map<String, Scope> scopes = new HashMap<String, Scope>();

        // Parse scopes
        for (int i = 0; i < scopeNodeList.getLength(); i++) {
            Element scopeElement = (Element) scopeNodeList.item(i);
            String name = scopeElement.getAttribute(TAG_SCOPE_ATTR_NAME);
            if (name.length() == 0) {
                throw new TextProcessorFactoryException("Illegal scope name. Scope name can't be empty.");
            }
            Scope scope =
                    new Scope(
                            name,
                            nodeAttribute(scopeElement, TAG_SCOPE_ATTR_IGNORE_TEXT, Scope.DEFAULT_IGNORE_TEXT)
                    );
            scope.setStrong(nodeAttribute(scopeElement, TAG_SCOPE_ATTR_STRONG, Scope.DEFAULT_STRONG));
            scopes.put(scope.getName(), scope);
        }

        // Set parents
        for (int i = 0; i < scopeNodeList.getLength(); i++) {
            Element scopeElement = (Element) scopeNodeList.item(i);

            String name = scopeElement.getAttribute(TAG_SCOPE_ATTR_NAME);
            Scope scope = scopes.get(name);
            if (scope == null) {
                throw new TextProcessorFactoryException(
                        MessageFormat.format("Can't find scope \"{0}\".", name)
                );
            }

            String parentName = nodeAttribute(scopeElement, TAG_SCOPE_ATTR_PARENT);
            if (parentName != null) {
                Scope parent = scopes.get(parentName);
                if (parent == null) {
                    throw new TextProcessorFactoryException(
                            MessageFormat.format("Can't find parent scope \"{0}\".", parentName)
                    );
                }
                scope.setParent(parent);
            }
            scope.setMax(nodeAttribute(scopeElement, TAG_SCOPE_ATTR_MAX, Scope.DEFAULT_MAX_VALUE));
            scope.setMin(nodeAttribute(scopeElement, TAG_SCOPE_ATTR_MIN, Scope.DEFAULT_MIN_VALUE));
        }

        return scopes;
    }
99430
public function getAllParents(Node $node = null, $lang = null)
    {
        if (is_null($node)) {
            return array();
        }

        $qb = $this->createQueryBuilder('node');

        // Directly hydrate the nodeTranslation and nodeVersion
        $qb->select('node', 't', 'v')
            ->innerJoin('node.nodeTranslations', 't')
            ->leftJoin(
                't.publicNodeVersion',
                'v',
                'WITH',
                't.publicNodeVersion = v.id'
            )
            ->where('node.deleted = 0');

        if ($lang) {
            $qb->andWhere('t.lang = :lang')
                ->setParameter('lang', $lang);
        }

        $qb->andWhere(
            $qb->expr()->andX(
                $qb->expr()->lte('node.lft', $node->getLeft()),
                $qb->expr()->gte('node.rgt', $node->getRight())
            )
        );

        $qb->addOrderBy('node.lft', 'ASC');

        return $qb->getQuery()->getResult();
    }