apsg/coding-standards 问题修复 & 功能扩展

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

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

apsg/coding-standards

Composer 安装命令:

composer require apsg/coding-standards

包简介

Coding standardsfor PINT

README 文档

README

Usage

We can pass the path of the config file to Pint: https://laravel.com/docs/9.x/pint#configuring-pint

so after this package is installed:

composer require apsg/coding-standards

one can tell Pint to use this config:

./vendor/bin/pint --config vendor/apsg/coding-standards/pint.json

Alternatively - one can just copy the pint.json file and use it as a template in it's own projects.

Rules descriptions:

Namespace

"single_blank_line_before_namespace": false,
"no_blank_lines_before_namespace": true,
"blank_line_after_opening_tag": false,

Those three ( 1, 2, 3 ) remove extra line before namespace. We don't look at this part of the file anyway, so this extra line is surplus in my opinion.

Before

<?php

namespace App\Domains\Admin\Controllers;

After:

<?php
namespace App\Domains\Admin\Controllers;

Trait imports

"single_trait_insert_per_statement": true, 

Thanks to single-line trait imports we immediately see all of them - there is no import that hides in this right-hand side twilight zone.

Also this allows to simply comment out single import while coding/debugging.

Before:

class Material extends Model implements HasMedia
{
    use HasStates, HasFactory, HasSlug, InteractsWithMedia;
...

After:

class Material extends Model implements HasMedia
{
    use HasStates;
    use HasFactory;
    use HasSlug;
    use InteractsWithMedia;
...

Spaces

Rules:

"not_operator_with_successor_space": false,
"cast_spaces": {
    "space": "none"
},
"concat_space": {
    "spacing": "one"
},

Before:

if(! $boolVariable) ...

$someString = $a.'-'.$b.'suffix';

$floatVariable = (float) '2.13'; 

After:

if(!$boolVariable) ...

$someString = $a . '-' . $b . 'suffix';

$floatVariable = (float)'2.13'; 

Alignment

Following rule for me is a must - especially when building large arrays (like in transformers). It also reduces visual clutter

"binary_operator_spaces": {
    "operators": {
        "=>": "align"
    }
},

Before:

return [
    'id' => $attachment->id,
    'name' => $attachment->name,
    'mime' => $attachment->mime,
    'url' => $attachment->downloadUrl(),
    'element' => $attachment->element,
    'copies' => $attachment->copies,

After:

return [
    'id'      => $attachment->id,
    'name'    => $attachment->name,
    'mime'    => $attachment->mime,
    'url'     => $attachment->downloadUrl(),
    'element' => $attachment->element,
    'copies'  => $attachment->copies,

Related to previous rule is another one, that reduces visual clutter in php-docs:

"phpdoc_align": {
    "align": "vertical",
    "tags": [
        "method",
        "param",
        "property",
        "property-read",
        "property-write",
        "return",
        "throws",
        "type",
        "var"
    ]
},

Before:

/**
 * @property int $id
 * @property int $user_id
 * @property string $title
 * @property string $slug
 * @property string|null $description
 * @property-read Collection|Attachment[] $attachments
 * @property-read User $owner
 */
class Material extends Model implements HasMedia

After:

/**
 * @property      int                     $id
 * @property      int                     $user_id
 * @property      string                  $title
 * @property      string                  $slug
 * @property      string|null             $description
 * @property-read Collection|Attachment[] $attachments
 * @property-read User                    $owner
 */
class Material extends Model implements HasMedia

Blank lines

Rule

"no_extra_blank_lines": {
    "tokens": [
        "extra",
        "square_brace_block",
        "return"
    ]
}

This extends default behaviour (extra) and removes surplus blank lines:

  • inside of curly braces []
  • after return statement

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-02-06