magento-coding-standard
magento-coding-standard copied to clipboard
Exception class Magento\Framework\Validator\ValidateException does not exist
Preconditions
Add attribute in Data Patch using $eavSetup->addAttribute()
method.
Place DataPatch in Vendor/Module/Setup/Patch/Data/AddTestAttribute.php file.
Example
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(Product::ENTITY, $attributeCode, $attribute);
Steps to reproduce
run vendor/bin/phpcs --standard=Magento2 app/code/Vendor/Module/Setup/Patch/Data/AddTestAttribute.php
Expected result
class 'Zend_Validate_Exception' is restricted in app/code/Vendor/Module/Setup/Patch/Data/AddTestAttribute.php.
Suggested replacement: Magento\Framework\Validator\Exception
Actual result
class 'Zend_Validate_Exception' is restricted in app/code/Vendor/Module/Setup/Patch/Data/AddTestAttribute.php.
Suggested replacement: Magento\Framework\Validator\ValidateException
Line
https://github.com/magento/magento-coding-standard/blob/097bda3e015f35dc7c2efc0b8c7a7d8dfc158a63/Magento2/Sniffs/Legacy/_files/restricted_classes.php#L129
Solution
The Magento\Framework\Validator\ValidateException
should be replaced with Magento\Framework\Validator\Exception
Hi @okolya. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.
Add a comment to assign the issue: @magento I am working on this
- Join Magento Community Engineering Slack and ask your questions in #github channel.
Both classes exist in the code-base.
https://github.com/magento/magento2/tree/5a022f69ada01effe32a207000a2391e1c918625/lib/internal/Magento/Framework/Validator https://github.com/magento/magento2/blob/5a022f69ada01effe32a207000a2391e1c918625/lib/internal/Magento/Framework/Validator/Exception.php https://github.com/magento/magento2/blob/5a022f69ada01effe32a207000a2391e1c918625/lib/internal/Magento/Framework/Validator/ValidateException.php
From what I can tell, ValidateException
was specifically introduced as a replacement for Zend_Validate_Exception
.
https://github.com/magento/magento2/commits/5a022f69ada01effe32a207000a2391e1c918625/lib/internal/Magento/Framework/Validator/ValidateException.php
Perhaps this change request should be paired with a change to the code-base to remove usage of ValidateException
in favour of ...\Validator\Exception
.