private function applySorting(ClassMetadata $metadata, string $className, array $sorting, string $alias): void
    {
        foreach ($sorting as $sort) {
            $customSort = $this->sortingTypeFactory->getCustomSorting($className, $sort['field']);
            if ($customSort) {
                $customSort($this->uniqueNameFactory, $metadata, $this->queryBuilder, $alias, $sort['order']);
            } else {
                $sortingField = $alias . '.' . $sort['field'];
                if ($sort['nullAsHighest'] ?? false) {
                    $expression = 'CASE WHEN ' . $sortingField . ' IS NULL THEN 1 ELSE 0 END';
                    $sortingField = $this->uniqueNameFactory->createAliasName('sorting');
                    $this->queryBuilder->addSelect($expression . ' AS HIDDEN ' . $sortingField);
                }

                $this->queryBuilder->addOrderBy($sortingField, $sort['order']);
            }
        }
    }