Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DocCommentSpacingSniff.php

function DocCommentSpacingSniff::sortAnnotationsToGroups

*

Parameters

list<Annotation> $annotations: * @return list<list<Annotation>>

1 call to DocCommentSpacingSniff::sortAnnotationsToGroups()
DocCommentSpacingSniff::checkAnnotationsGroupsOrder in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php
*

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php, line 638

Class

DocCommentSpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\Commenting

Code

private function sortAnnotationsToGroups(array $annotations) : array {
    $expectedAnnotationsGroups = $this->getAnnotationsGroups();
    $sortedAnnotationsGroups = [];
    $annotationsNotInAnyGroup = [];
    foreach ($annotations as $annotation) {
        foreach ($expectedAnnotationsGroups as $annotationsGroupPosition => $annotationsGroup) {
            foreach ($annotationsGroup as $annotationName) {
                if ($this->isAnnotationMatched($annotation, $annotationName)) {
                    $sortedAnnotationsGroups[$annotationsGroupPosition][] = $annotation;
                    continue 3;
                }
            }
        }
        $annotationsNotInAnyGroup[] = $annotation;
    }
    ksort($sortedAnnotationsGroups);
    foreach (array_keys($sortedAnnotationsGroups) as $annotationsGroupPosition) {
        $expectedAnnotationsGroupOrder = array_flip($expectedAnnotationsGroups[$annotationsGroupPosition]);
        usort($sortedAnnotationsGroups[$annotationsGroupPosition], function (Annotation $firstAnnotation, Annotation $secondAnnotation) use ($expectedAnnotationsGroupOrder) : int {
            $getExpectedOrder = function (string $annotationName) use ($expectedAnnotationsGroupOrder) : int {
                if (array_key_exists($annotationName, $expectedAnnotationsGroupOrder)) {
                    return $expectedAnnotationsGroupOrder[$annotationName];
                }
                $order = 0;
                foreach ($expectedAnnotationsGroupOrder as $expectedAnnotationName => $expectedAnnotationOrder) {
                    if ($this->isAnnotationNameInAnnotationNamespace($expectedAnnotationName, $annotationName)) {
                        $order = $expectedAnnotationOrder;
                        break;
                    }
                }
                return $order;
            };
            $expectedOrder = $getExpectedOrder($firstAnnotation->getName()) <=> $getExpectedOrder($secondAnnotation->getName());
            return $expectedOrder !== 0 ? $expectedOrder : $firstAnnotation->getStartPointer() <=> $secondAnnotation->getStartPointer();
        });
    }
    if (count($annotationsNotInAnyGroup) > 0) {
        $sortedAnnotationsGroups[] = $annotationsNotInAnyGroup;
    }
    return $sortedAnnotationsGroups;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal