使用 extract() 时的显式变量声明

Explicit variable declaration when using extract()

我有以下片段:

protected function sendEmail($email)
{
    extract($email);

    $this->transmail->locale($locale)
                    ->timezone($timezone)
                    ->template($template)
                    ->subject($subject)
                    ->send($header, $params);
}

此代码完美运行 (full source code here). However, I want to make sure to follow some good practices on the go. I'm currenlty getting [some CodeClimate warnings] (PHPMD)(https://codeclimate.com/github/timegridio/timegrid/app/Listeners/SendBookingNotification.php):

哪种方式比较优雅?

我应该用 list() 或类似的方式显式声明变量吗?

提前致谢

You can use doc comment annotations to exclude methods or classes from PHPMD or to suppress special rules for some software artifacts.

/**
 * This will suppress all the PMD warnings in
 * this class.
 *
 * @SuppressWarnings(PHPMD)
 */
class Bar {
    function  foo() {
        $baz = 23;
    }
}

Or you can suppress one rule with an annotation like this:

/**
 *
 */
class Bar {
    /**
     * This will suppress UnusedLocalVariable
     * warnings in this method
     *
     * @SuppressWarnings(PHPMD.UnusedLocalVariable)
     */
    public function foo() {
        $baz = 42;
    }
}

来源https://phpmd.org/documentation/suppress-warnings.html


不使用 PHPMD 的 PHPStorm 用户可以使用

/** @noinspection RULE */

在这里可以找到规则

https://gist.github.com/discordier/ed4b9cba14652e7212f5