backdevs/coding-standard

Backdevs PHP_CodeSniffer Coding Standard and other static analysis tools' configurations.

Installs: 49

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

1.0.0 2024-08-26 09:29 UTC

This package is auto-updated.

Last update: 2024-10-26 09:50:05 UTC


README

A PHP_CodeSniffer coding standard and other static analysis tools configuration files for Backdevs' PHP projects.

Included default configurations

Installation

Composer:

composer require --dev backdevs/coding-standard

Usage

PHP_CodeSniffer:

In your project's phpcs.xml file add the following line:

<rule ref="BackdevsCodingStandard"/>

If you don't have a phpcs.xml file, here's an example for a Laravel project:

<?xml version="1.0"?>
<ruleset
        name="Backdevs Coding Standard"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
    <description>Backdevs Coding Standard.</description>
    
    <arg name="extensions" value="php"/>
    <arg name="colors" />

    <arg value="sp"/>

    <file>app</file>
    <file>bootstrap</file>
    <file>config</file>
    <file>database</file>
    <file>routes</file>
    <file>tests</file>

    <exclude-pattern>cache/*</exclude-pattern>

    <rule ref="BackdevsCodingStandard"/>
</ruleset>

Now you should be able to run:

vendor/bin/phpcs

PHP Mess Detector:

If you don't have the phpmd/phpmd package installed, you can install it by running:

composer require --dev phpmd/phpmd

Then, in your project's phpmd.xml file add the following line:

<rule ref="vendor/backdevs/coding-standard/phpmd/phpmd.xml"/>

If you don't have a phpmd.xml file, here's a simple example:

<?xml version="1.0"?>
<ruleset
    name="Backdevs Coding Standard"
    xmlns="http://pmd.sf.net/ruleset/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
    xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
    <description>Backdevs Coding Standard.</description>

    <rule ref="vendor/backdevs/coding-standard/phpmd/phpmd.xml"/>
</ruleset>

Now you can run:

vendor/bin/phpmd app,bootstrap,config,database,routes,tests text phpmd.xml