frankvanhest/phpstan-rules-no-magic

PHPStan 规则,灵感来源于 roave/dont https://github.com/Roave/Dont

v3.0.0 2024-01-26 13:28 UTC

This package is auto-updated.

Last update: 2024-09-26 15:02:20 UTC


README

基本上,这些规则可以防止您使用 PHP 魔术方法。如果您想防止这些方法的运行时使用,请使用 https://github.com/Roave/Dont

安装

composer require frankvanhest/phpstan-rules-no-magic

使用

只需在您的 phpstan.neon 文件中包含以下内容,以防止使用方法 __call__callStatic__clone__wakeup__unserializeunserialize__get__sleep__serializeserialize__set__toString

includes:
    - vendor/frankvanhest/phpstan-rules-no-magic/config/no-magic.neon

当然,您可以通过选择所需的规则来自定义哪些方法应该被阻止。

针对 __call

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicCallRule

针对 __callStatic

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicCallStaticRule

针对 __clone

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicCloneRule

针对 __wakeup__unserializeunserialize(使用 Serializable 接口)

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicDeserializeRule

针对 __get

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicGetRule

针对 __sleep__serializeserialize(使用 Serializable 接口)

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicSerializeRule

针对 __set

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicSetRule

针对 __toString

rules:
    - FrankVanHest\PhpStanRulesNoMagic\NoMagicToStringRule

贡献

请随意提交问题或拉取请求。当涉及到拉取请求时,我很想知道它如何改进这个包,以及它可能解决什么问题。

有一些要求

  • 使用 PSR-12 进行代码风格
  • 为每个有意义的更改编写测试

许可证

许可