[Rule idea] Prevent injecting the ValidatorInterface in classes extending ConstraintValidator

Đang mở
#444 0 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
php, symfony
Lĩnh vực
devtools

Hướng nghiên cứu

No file or test is named. Start by locating the rule definitions and tests for classes implementing ConstraintValidatorInterface, then verify how constructor injection and #[Required] methods are represented; done means reporting ValidatorInterface injection in those classes without flagging other consumers.

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

Mô tả

Sometimes (for advanced cases), it is useful to execute validation of other constraints in the implementation of a ConstraintValidator.

The supported way of doing that in symfony/validator is to use $this->context->getValidator() (following the usage described in https://github.com/symfony/symfony/blob/v7.3.0/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php#L21-L58).
When providing support on the Symfony Slack, I encountered a case where a dev has injected the ValidatorInterface in the constraint instead and uses that. This broke everything because the main validator (entrypoint of the component) is injecting its current execution context in all the registered constraint validator, which will impact the in-progress validation when starting a new one (constraint validators will not attach all their violations to the new execution context even when not expected).

A static analysis rule could prevent such mistake by detecting places where we inject the Symfony\Component\Validator\Validator\ValidatorInterface (either through the constructor or through a method that has the #[Required] attribute of symfony/service-contracts) in a class implementing Symfony\Component\Validator\ConstraintValidatorInterface.

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

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.