定制 devbeta/psr12-strict-rules 二次开发

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

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

devbeta/psr12-strict-rules

Composer 安装命令:

composer require devbeta/psr12-strict-rules

包简介

PSR-12 strict coding standard

README 文档

README

This specification extends and expands PSR-12, the extended coding style guide and requires adherence to PSR-1, the basic coding standard.

Contributors have different coding styles and so do the maintainers. During code reviews there are regularly discussions about spaces and alignments, where and when was said that a function needs to be imported. And that's where this coding standard comes in: To have internal consistency in a component and between components.

Installation

Install the module via composer by running:

composer require --dev devbeta/psr12-strict-rules

Usage

Create file phpcs.xml on base path of your repository with this content:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Coding standard"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <description>PSR-12 strict coding standard</description>

    <arg name="colors"/>
    <arg name="cache" value=".phpcs.json"/>
    <arg name="extensions" value="php"/>
    <arg name="parallel" value="80"/>

    <arg value="p"/>

    <rule ref="PSR12-Strict-Rules"/>

    <file>config</file>
    <file>src</file>
    <file>tests</file>
</ruleset>

You can add or exclude some locations in that file. For a reference please see: Annotated Ruleset

Coding Style Guide

Basic Coding Standard

  • Code MUST follow all rules outlined in PSR-12.

Arrays

  • All values in multiline arrays must be indented with 4 spaces.
  • The short array syntax MUST be used to define arrays.

Classes

  • There MUST NOT be duplicate class names.
  • Checks the declaration of the class and its inheritance is correct.
  • The file name MUST match the case of the terminating class name.
  • For self-reference a class lower-case self:: MUST be used without spaces around the scope resolution operator.

Code Analysis

  • The final keyword on methods MUST be omitted in final classes.
  • Detects unnecessary overridden methods that simply call their parent.

Control Structures

  • Verifies that control statements conform to their coding standards.
  • Ensure multi-line if conditions are defined correctly.

Formatting

  • There MUST be one whitespace after a type casting operator.
  • There MUST be one whitespace after unary not.
  • If an assignment goes over two lines, ensure the equal sign is indented.

Functions

  • Ensure single and multi-line function declarations are defined correctly.

Metrics

  • Checks the cyclomatic complexity (McCabe) for functions.
  • Checks the nesting level for methods.

Naming Conventions

  • Checks that abstract classes are prefixed by Abstract.
  • Ensures method and functions are named correctly.
  • Checks that interfaces are suffixed by Interface.
  • Checks that traits are suffixed by Trait.

Operators

  • The && and || operators SHOULD be used instead of and and or.

PHP

  • The backtick operator MUST NOT be used.
  • Deprecated PHP functions MUST be avoided.
  • The PHP goto language construct SHOULD NOT be used.
  • Alias functions SHOULD NOT be used.
  • Throws an error or warning when any code prefixed with an asperand is encountered.
  • Checks that the strict_types has been declared.
  • The constant PHP_SAPI SHOULD be used instead of the php_sapi_name() function.
  • The global keyword MUST NOT be used.
  • PHP function calls MUST be in lowercase.
  • Non executable code MUST be removed.

Scope

  • The pseudo-variable $this MUST NOT be called inside a static method or function.

Strings

  • Checks that two strings are not concatenated together; suggests using one string instead.
  • Makes sure there are no spaces around the concatenation operator.

WhiteSpace

  • Check & fix whitespace on the inside of arbitrary parentheses.
  • Verifies spacing between the spread operator and the variable/function call it applies to.
  • Checks that object operators are indented correctly.
  • Checks that the closing braces of scopes are aligned correctly.
  • Checks the separation between functions and methods.
  • There MUST be a single space after language constructs.
  • There MUST NOT be any white space around the object operator UNLESS multilines are used.
  • Verifies that class members are spaced correctly.
  • Ensure there is no whitespace before/after an object operator.
  • Verifies that operators have valid spacing surrounding them.
  • There MUST NOT be a space before a semicolon. Redundant semicolons SHOULD be avoided.

devbeta/psr12-strict-rules 适用场景与选型建议

devbeta/psr12-strict-rules 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 297 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 devbeta/psr12-strict-rules 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-10-30