FormError is not subtype of native type T of FormError|FormErrorIterator.

Đang mở
#416 11 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php, symfony
Lĩnh vực
devtools

Hướng nghiên cứu

Start by reproducing the reported PHPStan 2 diagnostic with the Symfony Form getErrors() loop shown in the issue, then trace how that method's FormError|FormErrorIterator type is validated against the @var annotation. Done means the intended PhpStorm annotation is either accepted without the subtype error or the supported workaround is documented.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Hi!

I'm in the process of upgrading to phpstan 2.
One error that I couldn't find any solution yet is the following.

It was working on the latest 1.x versions

<?php

namespace App\Controller;

use App\Entity\Customer;
use App\Form\CustomerType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

class CustomerController extends AbstractController
{
    #[Route('/submit')]
    public function submit(Request $request): JsonResponse
    {
        $form = $this->createForm(CustomerType::class, new Customer());
        $form->handleRequest($request);

        if ($form->isSubmitted() && !$form->isValid()) {
             $errors = [];
            /** @var FormError $error */
            foreach ($form->getErrors(true) as $error) {
                 // process and handle  errors
            }
       }
      
        return $this->json([]);
    }
}

After phpstan 2 I get the following error:

PHPDoc tag @var with type Symfony\Component\Form\FormError is not subtype of native type T of Symfony\Component\Form\FormError|Symfony\Component\Form\FormErrorIterator.

I use the @var typehint for phpstorm, to have autocompletion. How can I fix this or is this a bug?

Thanks for your help

Ngôn ngữ chính
PHP
Star
806
Fork
107
Merge trung bình
2 giờ 4 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của phpstan/phpstan-symfony

Tất cả issue của phpstan/phpstan-symfony

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.