kafkiansky/better-laravel
最新稳定版本:v0.2.0
Composer 安装命令:
composer require --dev kafkiansky/better-laravel
包简介
A set of rules for the Psalm static analysis tool that help to detect popular issues when working with the Laravel framework.
README 文档
README
Contents
Installation
composer require kafkiansky/better-laravel --dev
Motivation
Laravel is a framework focused on ease of development. However, while providing many simple tools to quickly implement production ready solutions, it also adds more options to allow bugs. This package provides a set of plugins for the Psalm static analyzer, which covers many known issues.
Hooks
DontExtendApplicationEventServiceProvider
How often have you made the mistake of inheriting the right EventServiceProvider?
For example, you have a service provider A in which you register subscribers or listeners, and then inherit it in service provider B in which you register only listeners or only subscribers.
So you risk duplicating subscribers or listeners because Laravel will register them twice in the dispatcher.
The DontExtendApplicationEventServiceProvider hook will detect such service providers and prevent them from using inheritance from project event service providers.
DontUseEnvOutsideConfiguration
You have probably heard that the env function will always return null when caching a configuration. This is because Laravel does not load environment variables if it sees a cached configuration file in bootstrap/cache/config.php.
This hook works quite simply: if it sees calls to the env function outside the configuration files, it shows an error.
⚠️ Important restriction: all configuration files must be stored in the config folder.
ConfigurationOptionMustExists
Laravel allows you to work conveniently with configuration through dot notation. This is both convenient because it allows you to have unlimited nesting of the configuration, and inconvenient because no one validates such a configuration, and you can get the name wrong. This hook parses all the configuration files of your project and checks that the options you are accessing really exist.
⚠️ Important restriction: all configurations must be stored in the config folder and the file names must match the namespace (root) of the configuration.
For example, you have the following config in a file called api.php:
return [ 'http' => [ 'uri' => 'https://httpbin.org', ], ];
When accessing the api.http.ur configuration, you will see an error from Psalm that such configuration option is missing.
Testing
$ composer test
License
The MIT License (MIT). See License File for more information.
统计信息
- 总下载量: 14.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-20