定制 builtnorth/coding-standards 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

builtnorth/coding-standards

Composer 安装命令:

composer require builtnorth/coding-standards

包简介

Built North coding standards for WordPress projects, extending WPCS with modern PHP practices

README 文档

README

WordPress coding standards for Built North projects, extending WPCS with modern PHP practices.

Overview

This package provides a consistent set of coding standards for all Built North WordPress projects. It extends the WordPress Coding Standards (WPCS) while allowing modern PHP features and PSR-4 autoloading.

Installation

Add to your project via Composer:

composer require --dev builtnorth/coding-standards

Usage

Basic Usage

Create a phpcs.xml file in your project root:

<?xml version="1.0"?>
<ruleset name="My Project">
    <description>Coding standards for my project</description>
    
    <!-- Use Built North standards -->
    <rule ref="BuiltNorth"/>
    
    <!-- Project-specific text domain -->
    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array">
                <element value="my-text-domain"/>
            </property>
        </properties>
    </rule>
</ruleset>

Running the Standards

# Check your code
vendor/bin/phpcs

# Fix auto-fixable issues
vendor/bin/phpcbf

# Check specific file or directory
vendor/bin/phpcs src/

# Check with specific standard
vendor/bin/phpcs --standard=BuiltNorth

What's Included

Base Standards

  • WordPress Coding Standards (WPCS) 3.0+
  • PHP Compatibility checks for PHP 8.1+
  • PSR-1/PSR-2 file structure rules

Modern PHP Features Allowed

  • ✅ Short array syntax []
  • ✅ Short ternary operator ?:
  • ✅ Namespaces and PSR-4 autoloading
  • ✅ Modern PHP 8.1+ features

Excluded WordPress Rules

  • File naming conventions (we use PSR-4)
  • Yoda conditions requirement
  • File comment requirements
  • Overly strict comment punctuation

File Exclusions

Automatically excludes from scanning:

  • /vendor/
  • /node_modules/
  • /build/ and /dist/
  • *.min.js and *.min.css
  • WordPress core files
  • Test bootstrap files

Customization

Adding Project-Specific Rules

Your project's phpcs.xml can add additional rules:

<rule ref="BuiltNorth"/>

<!-- Add project-specific rules -->
<rule ref="WordPress.WP.EnqueuedResourceParameters"/>

<!-- Or exclude specific rules -->
<rule ref="BuiltNorth">
    <exclude name="WordPress.NamingConventions.PrefixAllGlobals"/>
</rule>

Setting Prefixes for Global Functions

<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
    <properties>
        <property name="prefixes" type="array">
            <element value="my_prefix"/>
            <element value="MyNamespace"/>
        </property>
    </properties>
</rule>

Integration with CI/CD

GitHub Actions Example

- name: Install dependencies
  run: composer install

- name: Run PHPCS
  run: vendor/bin/phpcs --report=checkstyle | cs2pr

Pre-commit Hook

Add to .git/hooks/pre-commit:

#!/bin/bash
vendor/bin/phpcs --filter=GitStaged

Philosophy

Our coding standards aim to:

  1. Embrace Modern PHP: Use PHP 8.1+ features while maintaining WordPress compatibility
  2. Prioritize Readability: Code should be self-documenting with clear naming
  3. Support PSR-4: Use modern autoloading instead of WordPress file naming
  4. Balance Strictness: Enforce important standards without being pedantic
  5. Enable Consistency: Same standards across all Built North projects

Requirements

  • PHP >= 8.1
  • Composer
  • WordPress project (for context-aware rules)

Contributing

To contribute to these standards:

  1. Clone the repository
  2. Make your changes to BuiltNorth/ruleset.xml
  3. Test with real projects
  4. Submit a pull request with reasoning for changes

License

MIT

builtnorth/coding-standards 适用场景与选型建议

builtnorth/coding-standards 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.97k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-11