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

Breadcrumb

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

function NameContext::getShortName

Get shortest representation of this fully-qualified name.

Parameters

string $name Fully-qualified name (without leading namespace separator):

Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_*:

Return value

Name Shortest representation

File

vendor/nikic/php-parser/lib/PhpParser/NameContext.php, line 212

Class

NameContext

Namespace

PhpParser

Code

public function getShortName(string $name, int $type) : Name {
    $possibleNames = $this->getPossibleNames($name, $type);
    // Find shortest name
    $shortestName = null;
    $shortestLength = \INF;
    foreach ($possibleNames as $possibleName) {
        $length = strlen($possibleName->toCodeString());
        if ($length < $shortestLength) {
            $shortestName = $possibleName;
            $shortestLength = $length;
        }
    }
    return $shortestName;
}

API Navigation

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