ORM 3.7 SortDirection support in orderBy clause

未关闭
#792 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@whataboutpereira 已经在做这个了。

开始于 2026年10月8日。

  • #796 来自 @whataboutpereira —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
php
领域
devtools

调研方向

Reproduce the example using QueryBuilder::orderBy with \SortDirection::Ascending and the nonexistent field. Find the orderBy analysis entry point and its regression tests, then ensure invalid fields are reported for enum direction values while valid fields remain accepted.

由索引模型根据 Issue 内容生成。

描述

It seems order by fields are not checked at all when order is given as the new \SortDirection enum (polyfilled on PHP 8.5 in this case).

<?php

namespace App\Entity;

use App\Repository\TestRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: TestRepository::class)]
class Test
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    public int $id;

    #[ORM\Column]
    public string $name;
}
<?php

namespace App\Repository;

use App\Entity\Test;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<Test>
 */
class TestRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Test::class);
    }

    /**
     * @return list<Test>
     */
    public function test(): array
    {
        return $this->createQueryBuilder('t')
            ->orderBy('t.nonexistent2', \SortDirection::Ascending)
            ->getQuery()
            ->getResult()
        ;
    }
}
[OK] No errors  
主要语言
PHP
星标
683
派生
129
平均合并
13 小时 6 分钟
30 天内合并 PR
14

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

phpstan/phpstan-doctrine 的其他 Issue

查看 phpstan/phpstan-doctrine 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。