worksome/coding-style 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

worksome/coding-style

Composer 安装命令:

composer require worksome/coding-style

包简介

Worksomes coding style

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

This repository contains the coding style followed by Worksome.

It includes configuration for ECS, PHPStan, and Rector.

Setup

Install this Composer package:

composer require --dev worksome/coding-style

Run the generate command for generating the config files:

composer generate-coding-style-stubs

Add the following section to your composer.json file:

"scripts": {
    "ecs": "vendor/bin/ecs",
    "ecs:fix": "vendor/bin/ecs --fix",
    "phpstan": "vendor/bin/phpstan analyse",
    "rector": "vendor/bin/rector process --dry-run --ansi",
    "rector:fix": "vendor/bin/rector process --ansi"
},

Usage

To use it, simply run one of the scripts added to composer.

$ composer ecs
$ composer ecs:fix
$ composer phpstan
$ composer rector
$ composer rector:fix

ECS Rules

The Worksome code style extends the PSR-12 base rule set.

Additional / Customised Rules

Note: Customised rules have a ⚙️ icon.

PhpCsFixer

PHP CodeSniffer

Slevomat Coding Standard

Symplify Coding Standard

Worksome

Custom PHPStan rules

The Worksome code style includes the following custom PHPStan rules.

Generic

Rules that are applied to all projects.

DeclareStrictTypes

Identifier: worksome.declareStrictTypes

This rule is used to ensure that all PHP files include with the declare(strict_types=1) statement.

DisallowPHPUnit

Identifier: worksome.disallowPhpunit

This rule prevents PHPUnit tests in favour of Pest PHP. It will allow abstract TestCase classes.

NamespaceBasedSuffix

Identifier: worksome.namespaceBasedSuffix

Sets up configuration for suffixing the following namespaces

  • App\Events: Event
  • App\Listener: Listener
  • App\Policies: Policy
  • App\Jobs: Job

This makes sures events, listeners, policies and jobs has the same suffix.

Laravel

Rules that are only applied in a Laravel context.

DisallowEnvironmentCheckRule

Identifier: worksome.laravel.disallowEnvironmentCheck

This rule will prevent checking the application environment, instead preferring that a driver based approach is used.

EnforceKebabCaseArtisanCommandsRule

Identifier: worksome.laravel.kebabCaseArtisanCommands

This rule will enforce the use of kebab-case for Artisan commands.

RequireWithoutTimestampsRule

Identifier: worksome.laravel.requireWithoutTimestamps

This rule enforces that all update, insert, save, saveQuietly, delete, restore, method calls within Laravel migration files are properly enclosed in a withoutTimestamps() context.

Custom PHP_CodeSniffer sniffs

The Worksome code style includes various custom PHP_CodeSniffer sniffs where auto-fixers via PHP CS Fixer are not possible.

Generic

Pascal-casing enum cases

This ensures that all enum cases use pascal-casing (e.g. Case::PascalCase).

Laravel

All custom sniffs specific to Laravel.

Config filename kebab case

Checks if all config files are written in kebab case.

Disallow compact usage

Makes sure that compact() isn't used in code.

Disallow env usage

Makes sure that you don't use env helper in your code, except for config files.

Disallow HasFactory usage

Ensures that the HasFactory trait is not used on models, this ensures that the factory class is called directly.

Event listener suffix

Enforces event listeners to end with a specific suffix, this suffix is defaulted to Listener.

parameters defaults
suffix Listener

Disallow blade outside the resources directory

Makes sure no .blade.php files exist outside of Laravel's resources directory.

parameters defaults
resourcesDirectory {YOUR_PROJECT}/resources

Exception suffix

This ensures that all Exception classes should have a suffix of Exception.

PhpDoc

All custom sniffs which are not specific to Laravel.

Property dollar sign

Makes sure that you always have a dollar sign in your properties defined in phpdoc.

/**
* @property string $name
 */
class User {}

Param tags with no type or comment

This removes all @param tags which has not specified a type or comment.

/**
 * @param string $name
 * @param $type some random type
 * @param $other // <-- will be removed
 */
public function someMethod($name, $type, $other): void
{}

This is mainly because PHPStan requires this before it sees the property as valid.

Disallow TODO comments

This ensures that all to-do comments are blocked from use. Jira should be used instead.

Space in generics

This ensures that generics types in PHPDoc comments contain a single space after the comma.

Custom Rector rules

The Worksome code style includes custom Rector rules for automatically refactoring code.

Generic

Disallowed Attributes

This ensures that specified PHP attributes are automatically removed when they are not allowed.

Credits

worksome/coding-style 适用场景与选型建议

worksome/coding-style 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 818.05k 次下载、GitHub Stars 达 49, 最近一次更新时间为 2020 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 worksome/coding-style 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 worksome/coding-style 我们能提供哪些服务?
定制开发 / 二次开发

基于 worksome/coding-style 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 818.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 49
  • 点击次数: 23
  • 依赖项目数: 34
  • 推荐数: 0

GitHub 信息

  • Stars: 49
  • Watchers: 15
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-24