cspray / phinal
在您的类上强制执行final!
2.0.0
2023-01-26 13:36 UTC
Requires
- php: ^8.0
- ext-simplexml: *
- vimeo/psalm: 5.*
Requires (Dev)
- behat/behat: ^3.11
- codeception/codeception: ^4.1
- phpunit/phpunit: ^9.5.5
- psalm/plugin-phpunit: ^0.18
- squizlabs/php_codesniffer: ^3.3
- weirdan/codeception-psalm-module: ^0.13.1
- weirdan/prophecy-shim: ^2.0
README
你喜欢final吗?真的很喜欢?那么就在所有的类上强制执行它!当你需要回退到继承时,你可以通过显式地标记你的类并解释为什么它应该被继承来完成。
安装
运行Psalm 5
composer require --dev cspray/phinal
vendor/bin/psalm-plugin enable cspray/phinal
运行Psalm 4
composer require --dev cspray/phinal:1.0.0
vendor/bin/psalm-plugin enable cspray/phinal
代码示例
太好了!👍
<?php declare(strict_types=1); use Cspray\Phinal\AllowInheritance; final class ProperlyMarkedFinal {} #[AllowInheritance('Explain why you would need to inherit this.')] class YouCanInheritThis {}
不好!👎
<?php declare(strict_types=1); class NotMarkedFinal {}
你为什么需要继承这个?你可能不需要,应该标记为final!