Giter Site home page Giter Site logo

suin / phpcs-psr4-sniff Goto Github PK

View Code? Open in Web Editor NEW
24.0 5.0 14.0 315 KB

[READ-ONLY] PHP_CodeSniffer sniff that checks class name matches PSR-4 project structure.

PHP 100.00%
coding-standards coding-style namespace php-codesniffer phpcs psr-4 static-analysis third-party-sniff custom-sniff

phpcs-psr4-sniff's Introduction

suin/phpcs-psr4-sniff

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

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, suin/phpcs-psr4-sniff 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.

phpcs-psr4-sniff's People

Contributors

bc-luke avatar suin avatar sveneld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.