定制 fabianblum/phpcs-psr4-sniff 二次开发

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

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

fabianblum/phpcs-psr4-sniff

最新稳定版本:3.0.1

Composer 安装命令:

composer require fabianblum/phpcs-psr4-sniff

包简介

PHP_CodeSniffer sniff that checks class name matches PSR-4 project structure. (PHP 8.3 ready)

README 文档

README

A custom PHP Code Sniffer sniff to help to find classes that is not compliant with PSR-4 Autoloader.

Public fork of abandoned package

This package was originally hosted at https://github.com/suin/phpcs-psr4-sniff, but seems to be abandoned. For ease of migration, the original namespacing has been kept.

To switch to this package, use the commands

composer remove suin/phpcs-psr4-sniff composer require fabianblum/phpcs-psr4-sniff 

Demo

Please visit ./tests/demo, if you would like to try this sniff.

Features

Classes, interfaces and traits

This sniff covers not only classes but also interfaces and traits.

Namespaces and class names

This sniff checks whether both of namespaces and class names match PSR-4 project structure.

Configuration free

As this sniff respects composer.json autoloading configuration, you don't have to declare mapping between namespace prefixes and base directories.

Similar packages

Psr4Fixer of PHP-CS-Fixer

Psr4Fixer checkes if class names should match the file name and fixes the class names if its don't correspond to the file names. It doesn't check the namespaces.

In contrast, this package checks not only class names but also namespaces.

SlevomatCodingStandard.Files.TypeNameMatchesFileName

SlevomatCodingStandard.Files.TypeNameMatchesFileName is a custom PHP Code Sniffer sniff to check whether namespaces and class names follow PSR-0/PSR-4 project structure.

This sniff is similar to suin/phpcs-psr4-sniff, but it needs explicit configuration about the PSR-0/PSR-4 project structure. suin/phpcs-psr4-sniff takes implicit way as it follows the autoloding configuration of Composer.

Installation

composer require --dev suin/phpcs-psr4-sniff 

Usage

At first, create a PHPCS ruleset XML (phpcs.xml.dist or phpcs.xml) file in the root of your project.

<?xml version="1.0"?> <ruleset name="My Project"> <!-- Specify directory that composer.json is placed. Usually it would be  project root directory. --> <arg name="basepath" value="."/> <!-- Relative path to your ruleset.xml --> <rule ref="vendor/suin/phpcs-psr4-sniff/src/Suin"/> <!-- Optional: If you have to specify composer.json path, please add  following section. --> <rule ref="Suin.Classes.PSR4"> <properties> <!-- composerJsonPath must be relative path to "basepath" --> <property name="composerJsonPath" value="sub-dir/composer.json"/> </properties> </rule> </ruleset>

Then run it with the command:

vendor/bin/phpcs src 

Changelog

Please see CHANGELOG for more details.

Contributing

Send issue or pull-request to main repository.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固