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

Breadcrumb

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

function CommentsRegistry::compareNodesLength

Compares node length

@codeCoverageIgnore

Parameters

Node\Node $node1 First node:

Node\Node $node2 Second node:

Return value

int

File

vendor/mck89/peast/lib/Peast/Syntax/CommentsRegistry.php, line 278

Class

CommentsRegistry
Comments registry class. Internal class used to manage comments

Namespace

Peast\Syntax

Code

public function compareNodesLength($node1, $node2) {
    $loc1 = $node1->location;
    $length1 = $loc1->end
        ->getIndex() - $loc1->start
        ->getIndex();
    $loc2 = $node2->location;
    $length2 = $loc2->end
        ->getIndex() - $loc2->start
        ->getIndex();
    
    //If the nodes have the same length make sure to choose nodes
    
    //different from Program nodes
    if ($length1 === $length2) {
        if ($node1 instanceof Node\Program) {
            $length1 += 1000;
        }
        elseif ($node2 instanceof Node\Program) {
            $length2 += 1000;
        }
    }
    return $length1 < $length2 ? -1 : 1;
}

API Navigation

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