Closed
Description
Rule
getResource()
use is deprecated and Resource Model should be injected with DI to the Model class.
Reason
Most of the Mageto 2 tutorials and stackoverflow answers:
- https://www.mage2.tv/content/setup-scripts/adding-a-custom-eav-attribute/adding-an-input-filter-to-a-customer-or-address-attribute/
- https://magento.stackexchange.com/questions/163933/good-practice-how-to-save-many-objects
- https://magento.stackexchange.com/questions/46369/loading-just-an-attribute-from-a-model-and-saving-it
provide getResource()->save($object)
as recommended way to persist data changes on model - from model itself. As use of getResource()
is deprecated, and ResourceModel should be initialized using Dependency Injection, we should introduce inspection for PHP CS to avoid using getResource()
in models and setup scripts.