magento-ecg / coding-standard

Magento PHP_CodeSniffer Coding Standard
MIT License
308 stars 100 forks source link

"Plugin beforeSave function should have at least two" #43

Closed anzmage closed 7 years ago

anzmage commented 7 years ago

i think this warning message is incorrect... this message show on my backend model for product attribute

<?php
namespace Training4\Warranty\Model\Attribute\Backend;

class AttributeWarranty extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
{
    public function beforeSave($object)
    {
        $value = $object->getData($this->getAttribute()->getAttributeCode());
        if (is_numeric($value)) {
            $value .= " year(s)";
            $object->setData($this->getAttribute()->getAttributeCode(), $value);
        }
        return parent::beforeSave($object);
    }
}
nntoan commented 7 years ago

@ansyori The message is correct, the first parameter should be the plugin subject/object, the second one in your case (before) should be the parameter you want to modify. Because the purpose of before plugins is modify the parameters before doing something.

LilyBergonzat commented 2 years ago

The warning message is indeed incorrect, a backend model has a beforeSave() function that is not a plugin. It shouldn't warn in this case. I just stumbled upon the same problem.