Coding Standards - markhowellsmead/helpers GitHub Wiki

WordPress

Based on the official setup for WordPress Coding Standards for PHP. (Manual details of the Standards for PHP are here.)

Installation

Install the dependencies globally using composer.

composer global require --dev squizlabs/php_codesniffer
composer global require --dev dealerdirect/phpcodesniffer-composer-installer
composer global require --dev wp-coding-standards/wpcs
composer global require --dev phpcompatibility/phpcompatibility-wp

Add the vendor folder to your PATH by adding the following line to your .bash_profile (OSX).

export PATH="$HOME/.composer/vendor/bin:$PATH"

Atom

Add the Atom Beautify package. Set the package to use PHPCBF and set the Standard to PSR2, not PEAR.

Add the paths to PHP-CS-Fixer and PHPCBF in the Executables settings.

If you need to use e.g. WordPress-Core for an individual project, add the following ruleset.xml to the current folder or the project root. (i.e. the top-level folder which you have open in your Atom project window.) This doesn't work hierarchically!

<?xml version="1.0"?>
<ruleset name="Say Hello - WordPress Core">
    <description>WordPress Core Ruleset for Say Hello</description>

    <!-- Use WPCS as a base -->
    <rule ref="WordPress-Core">
        <!-- Allow Tabs -->
        <exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
        <exclude name="WordPress.WP.I18n.NonSingularStringLiteralDomain" />
    </rule>

    <!-- Disallow spaces as tabs -->
    <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>

    <!-- Define 4 spaces as a tab -->
    <rule ref="Generic.WhiteSpace.ScopeIndent">
        <properties>
            <property name="indent" value="4"/>
            <property name="tabIndent" value="true"/>
        </properties>
    </rule>
</ruleset>
⚠️ **GitHub.com Fallback** ⚠️