定制 artisanpack-ui/code-style-pint 二次开发

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

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

artisanpack-ui/code-style-pint

Composer 安装命令:

composer require artisanpack-ui/code-style-pint

包简介

Laravel Pint preset for ArtisanPack UI code standards

README 文档

README

Laravel Pint preset for ArtisanPack UI code standards. This package provides a pre-configured pint.json file that enforces coding standards matching the artisanpack-ui/code-style PHPCS package.

Installation

Install the package via Composer:

composer require artisanpack-ui/code-style-pint --dev

Usage

For Laravel Applications

Publish the pint.json configuration file to your project root:

php artisan artisanpack:publish-pint-config

Use --force to overwrite an existing pint.json:

php artisan artisanpack:publish-pint-config --force

Alternatively, use Laravel's standard publish command:

php artisan vendor:publish --tag=artisanpack-pint-config

For Laravel Packages

When developing a Laravel package, use PintConfigBuilder directly since php artisan isn't available:

Standard Pint Configuration:

<?php
// pint-setup.php
require __DIR__ . '/vendor/autoload.php';

use ArtisanPackUI\CodeStylePint\Config\PintConfigBuilder;

PintConfigBuilder::create()
    ->withArtisanPackUIPreset()
    ->save(__DIR__ . '/pint.json');

Run it once to generate your config:

php pint-setup.php

Or copy the stub directly:

cp vendor/artisanpack-ui/code-style-pint/stubs/pint.json.stub pint.json

WordPress-Style Spacing (PHP-CS-Fixer):

For WordPress-style spacing in packages, copy the PHP-CS-Fixer configuration stub:

cp vendor/artisanpack-ui/code-style-pint/stubs/.php-cs-fixer.dist.php.stub .php-cs-fixer.dist.php

Then install PHP-CS-Fixer:

composer require --dev friendsofphp/php-cs-fixer

WordPress-Style Spacing (Laravel Applications)

If you need WordPress-style spacing (spaces inside parentheses and brackets) in a Laravel application, use the --wordpress flag:

php artisan artisanpack:publish-pint-config --wordpress

This will create .php-cs-fixer.dist.php with custom fixers that enforce:

  • Spaces inside parentheses: if ( $var ) instead of if ($var)
  • Spaces inside brackets (variable indices only): $array[ $key ] instead of $array[$key]
  • Spaces around concatenation: $a . $b instead of $a.$b

Note: WordPress spacing requires PHP-CS-Fixer instead of Pint:

# Install PHP-CS-Fixer
composer require --dev friendsofphp/php-cs-fixer

# Run code formatting
./vendor/bin/php-cs-fixer fix

Running Pint

Once the Pint configuration is in place, run Pint to format your code:

./vendor/bin/pint

To test without making changes:

./vendor/bin/pint --test

Running PHP-CS-Fixer (WordPress Spacing)

If you're using WordPress-style spacing, run PHP-CS-Fixer instead:

./vendor/bin/php-cs-fixer fix

To test without making changes:

./vendor/bin/php-cs-fixer fix --dry-run --diff

Programmatic Configuration

For advanced use cases, you can build configurations programmatically:

use ArtisanPackUI\CodeStylePint\Config\PintConfigBuilder;

// Full preset (use base_path() in Laravel apps, __DIR__ in packages)
PintConfigBuilder::create()
    ->withArtisanPackUIPreset()
    ->save(__DIR__ . '/pint.json');

// Customize rule groups
PintConfigBuilder::create()
    ->withFormattingRules(true)
    ->withCodeStructureRules(true)
    ->withBestPracticeRules(false)  // Disable strict types, yoda style, etc.
    ->withArtisanPackUIPreset()
    ->addRule('concat_space', ['spacing' => 'one'])
    ->removeRule('yoda_style')
    ->exclude('tests/fixtures')
    ->save(__DIR__ . '/pint.json');

See docs/customization.md for detailed customization options.

Rules Included

This preset enforces the following code style rules:

  • Array Syntax: Short array syntax ([] instead of array())
  • Binary Operator Spaces: Single space around operators, aligned assignments
  • Brace Position: Same line for control structures, next line for functions
  • Class Structure: Ordered class elements (traits, constants, properties, methods)
  • Concatenation Spacing: Single space around concatenation operator (. )
  • Import Ordering: Alphabetically sorted imports (classes, functions, constants)
  • Single Quotes: Single quotes for strings without variables
  • Trailing Commas: In multiline arrays, arguments, and parameters
  • Visibility Required: All properties, methods, and constants must have visibility
  • Yoda Style: Literals on the left side of comparisons

For WordPress-style spacing (spaces inside parentheses and brackets), see the WordPress-Style Spacing section.

Complementary PHPCS Usage

Some rules cannot be enforced by Pint (security checks, naming conventions, line length). For complete code style enforcement, use both packages:

{
  "require-dev": {
    "artisanpack-ui/code-style": "^1.0",
    "artisanpack-ui/code-style-pint": "^1.0"
  }
}

Recommended Workflow

  1. Run Pint first to auto-fix formatting:

    ./vendor/bin/pint
  2. Run PHPCS to catch remaining issues:

    ./vendor/bin/phpcs --standard=ArtisanPackUIStandard .

Laravel Boost AI Guidelines

This package includes AI guidelines for Laravel Boost, which will automatically be available when users run php artisan boost:install.

Overriding Default Pint Guidelines

To have AI assistants use ArtisanPack UI standards instead of Laravel's default Pint guidelines, publish the Boost override:

php artisan vendor:publish --tag=artisanpack-boost-override

This creates .ai/guidelines/laravel/pint.blade.php, which overrides Boost's default Pint guidelines with ArtisanPack UI specific guidance.

Documentation

Contributing

As an open source project, this package is open to contributions from anyone. Please read through the contributing guidelines to learn more about how you can contribute to this project.

License

This package is open-sourced software licensed under the GPL-3.0-or-later license.

artisanpack-ui/code-style-pint 适用场景与选型建议

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

它主要适用于以下技术方向: 「laravel」 「php-cs-fixer」 「code-style」 「Pint」 「artisanpack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 artisanpack-ui/code-style-pint 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 32
  • 依赖项目数: 20
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-11-21