Returns the type name for the given use statement.

@param File $file
@param UseStatement $useStatement

@return string
978463
public static function getTypeName(File $file, UseStatement $useStatement): string
    {
        return UseStatement::getTypeName(static::getType($file, $useStatement)) ?? '';
    }
2610
public function getStatement($usePlaceholders = true)
    {
        $statement = "";
        if ($this->isSelect()) {
            $statement = $this->getSelectStatement($usePlaceholders);
        } elseif ($this->isInsert()) {
            $statement = $this->getInsertStatement($usePlaceholders);
        } elseif ($this->isReplace()) {
            $statement = $this->getReplaceStatement($usePlaceholders);
        } elseif ($this->isUpdate()) {
            $statement = $this->getUpdateStatement($usePlaceholders);
        } elseif ($this->isDelete()) {
            $statement = $this->getDeleteStatement($usePlaceholders);
        }
        return $statement;
    }
894054
def used_in_func(statement: str, filename: str = '<string>',
                 mode: str = 'exec'):
    ''''''
    try:
        return get_used_in_func(ast.parse(statement, filename, mode))
    except Exception as e:
        raise RuntimeError(f'Failed to parse statement: {statement} {e}')
182837
protected static function _generateUses($uses)
    {
        if (!$uses) {
            return '';
        }
        $traits = [];
        foreach ((array) $uses as $use) {
            if (!trait_exists($use)) {
                throw new MissingImplementationException("Unexisting trait `{$use}`");
            }
            $traits[] = '\\' . ltrim($use, '\\');
        }
        return '    use ' . join(', ', $traits) . ';';
    }
947235
protected function insertUseStatement(File $phpcsFile, array $useStatement): void
    {
        $existingStatements = $this->existingStatements;
        if ($existingStatements) {
            $lastOne = array_pop($existingStatements);

            $lastUseStatementIndex = $lastOne['end'];
        } else {
            $namespaceStatement = $this->getNamespaceStatement($phpcsFile);

            $lastUseStatementIndex = $namespaceStatement['end'];
        }

        $phpcsFile->fixer->addNewline($lastUseStatementIndex);
        $phpcsFile->fixer->addContent($lastUseStatementIndex, $this->generateUseStatement($useStatement));
    }
280273
protected function findUseStatementForClassName(File $phpCsFile, $className) {
		$useStatements = $this->parseUseStatements($phpCsFile);
		if (!isset($useStatements[$className])) {
			$useStatement = $this->findInSameNameSpace($phpCsFile, $className);
			if ($useStatement) {
				return $useStatement;
			}

			return null;
		}

		return $useStatements[$className];
	}
1060732
public static function getMimeType($file)
    {
        $mimeType = new MimeTypeGuesser();
        $extension = self::getExtension($file);

        return $mimeType->getTypeByExtension($file);
    }
627703
public static function guessType($file)
    {
        $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));

        switch (true) {
            case $ext === 'json':
            case basename($file) === 'composer.lock':
                return self::JSON;
            case $ext === 'yml':
            case $ext === 'yaml':
                return self::YAML;
            case $ext === 'ini':
            case basename($file) === '.my.cnf':
                return self::INI;
        }

        return null;
    }
156617
protected function generateUseStatement(array $useStatement): string
    {
        $alias = '';
        if (!empty($useStatement['alias'])) {
            $alias = ' as ' . $useStatement['alias'];
        }

        $content = 'use ' . $useStatement['fullName'] . $alias . ';';

        return $content;
    }
802340
protected function processStatements($file, array $statements, $prefix = '')
    {
        $uses = [];
        $methods = [];
        $classes = [];

        foreach ($statements as $statement) {
            if ($statement instanceof Namespace_) {
                return $this->processStatements($file, $statement->stmts, (string)$statement->name);
            }

            if ($statement instanceof Use_) {
                foreach ($statement->uses as $use) {
                    // polyfill
                    $alias = $use->alias;
                    if (null === $alias && method_exists($use, 'getAlias')) {
                        $alias = $use->getAlias();
                    }

                    $uses[(string)$alias] = (string)$use->name;
                }
            }

            if ($statement instanceof Class_) {
                $class = $statement;
                $fullClassName = $prefix . '\\' . $class->name;

                $classes[$fullClassName] = [
                    'file' => $file,
                    'line' => $class->getAttribute('startLine'),
                    'name' => $fullClassName,
                    'docblock' => $this->getDocblock($class, $uses),
                ];

                foreach ($statement->stmts as $method) {
                    if (!$method instanceof ClassMethod) {
                        continue;
                    }

                    $fullMethodName = $fullClassName . '::' . $method->name;

                    $type = $method->returnType;

                    if ($type instanceof NullableType) {
                        $type = $type->type->toString();
                    } elseif ($type instanceof NodeAbstract) {
                        $type = $type->toString();
                    }

                    if (isset($uses[$type])) {
                        $type = $uses[$type];
                    }

                    if ($type !== null) {
                        $type = strpos($type, '\\') === 0 ? substr($type, 1) : $type;
                    }

                    if ($method->returnType instanceof NullableType) {
                        $type = ['null', $type];
                        sort($type);
                    }

                    $thisMethod = [
                        'file' => $file,
                        'class' => $fullClassName,
                        'name' => $fullMethodName,
                        'line' => $method->getAttribute('startLine'),
                        'return' => $type,
                        'params' => [],
                        'docblock' => $this->getDocblock($method, $uses),
                        'has_return' => isset($method->stmts) ? $this->statementsContainReturn($method->stmts) : false,
                    ];

                    /** @var Param $param */
                    foreach ($method->params as $param) {
                        $type = $param->type;

                        if ($type instanceof NullableType) {
                            $type = $type->type->toString();
                        } elseif ($type instanceof NodeAbstract) {
                            $type = $type->toString();
                        }

                        if (isset($uses[$type])) {
                            $type = $uses[$type];
                        }

                        if ($type !== null) {
                            $type = strpos($type, '\\') === 0 ? substr($type, 1) : $type;
                        }

                        if (property_exists($param, 'default') &&
                            $param->default instanceof Expr &&
                            property_exists($param->default, 'name') &&
                            property_exists($param->default->name, 'parts') &&
                            $type !== null &&
                            'null' === $param->default->name->parts[0]
                        ) {
                            $type .= '|null';
                        }

                        $name = null;
                        // parser v3
                        if (property_exists($param, 'name')) {
                            $name = $param->name;
                        }
                        // parser v4
                        if (null === $name && property_exists($param, 'var') && property_exists($param->var, 'name')) {
                            $name = $param->var->name;
                        }

                        $thisMethod['params']['$' . $name] = $type;
                    }

                    $methods[$fullMethodName] = $thisMethod;
                }
            }
        }

        return ['methods' => $methods, 'classes' => $classes];
    }
350009
public JavaFileObject useSource(JavaFileObject file) {
        JavaFileObject prev = (source == null ? null : source.getFile());
        source = getSource(file);
        return prev;
    }
1041206
private String getSourceSetNameFromFile(File file) {
    Path absolutePath = Paths.get(file.getAbsolutePath());
    Path basePath = Paths.get(task.getProject().file("src").getAbsolutePath());

    return basePath.relativize(absolutePath).toString().split(Matcher.quoteReplacement(File.separator))[0];
  }
859043
public function getUsedIn(ExtendedFileInterface $file)
    {
        $qb = $this->fileUsageRepository->createQueryBuilder('u');
        $qb
            ->select(['u.usageType', 'u.usageId', 'u.status'])
            ->join('u.file', 'f')
            ->where($qb->expr()->eq('f.id', $qb->expr()->literal($file->getId())))
            ->andWhere($qb->expr()->eq('f.version', $qb->expr()->literal($file->getVersion())));

        $usedIn = [];
        foreach ($qb->getQuery()->getScalarResult() as $row) {
            $usedIn[] = [
                'usage_type' => $row['usageType'],
                'usage_id' => $row['usageId'],
                'status' => $row['status'],
            ];
        }

        return $usedIn;
    }
538021
private function compareUseStatementsByNamespaceCount(
        UseStatement $prevStatement,
        UseStatement $nextStatement
    ): int {
        $aNameParts = explode(NamespaceHelper::NAMESPACE_SEPARATOR, $prevStatement->getFullyQualifiedTypeName());
        $bNameParts = explode(NamespaceHelper::NAMESPACE_SEPARATOR, $nextStatement->getFullyQualifiedTypeName());

        return count($aNameParts) <=> count($bNameParts);
    }
638498
public static String getType(File file) throws IORuntimeException {
		FileInputStream in = null;
		try {
			in = IoUtil.toStream(file);
			return getType(in);
		} finally {
			IoUtil.close(in);
		}
	}
1290089
public function getReadableValue($useName = null, $useValue = null)
  {
    $useName = $useName ?: ucwords(Strings::humanize($this->key));
    $useValue = $useValue ?: $this->value;
    if(is_array($useValue))
    {
      $useValue = implode(', ', ValueAs::arr($useValue));
    }

    $nonIsComparators = [
      AdvancedFilterComparator::STARTS_WITH,
      AdvancedFilterComparator::NOT_STARTS_WITH,
      AdvancedFilterComparator::ENDS_WITH,
      AdvancedFilterComparator::NOT_ENDS_WITH,
    ];

    if(!in_array($this->comparator, $nonIsComparators))
    {
      $useName .= ' is';
    }

    if(in_array(
      $this->comparator,
      [AdvancedFilterComparator::BETWEEN, AdvancedFilterComparator::NOT_BETWEEN]
    ))
    {
      list($min, $max) = explode(',', $useValue);
      return $useName . ' between ' . trim($min) . ' and ' . trim($max);
    }

    if(is_bool($useValue))
    {
      return $useName . ' ' . ($useValue ? 'true' : 'false');
    }

    return $useName . ' '
      . AdvancedFilterComparator::getDisplayValue($this->comparator) . ' '
      . $useValue;
  }
746422
private function compareUseStatements(UseStatement $prevStatement, UseStatement $nextStatement): int
    {
        $callbacks = [
            'compareUseStatementsByType',
            'compareUseStatementsByContent',
            // This will return something in any case!
            'compareUseStatementsByNamespaceCount'
        ];

        foreach ($callbacks as $callback) {
            $compared = $this->$callback($prevStatement, $nextStatement);

            if ($compared !== null) {
                return $compared;
            }
        }
    }