Giter VIP home page Giter VIP logo

codeigniter4-standard's Introduction

CodeIgniter4-Standard

CodeIgniter 4 coding standard for use with PHP_CodeSniffer 3.

Version 1.0.1

Master Develop
Build Status Build Status
Coverage Status Coverage Status

This is currently a work in progress.

Requested at: codeigniter4/CodeIgniter4#182

Requirements

PHP_CodeSniffer 3. (3.1.1 or greater).

PHP (7.1 or greater) with mbstring extension.

Install

Composer install

cd /Path/To/MyProject
composer require codeigniter4/codeigniter4-standard --dev

Set the phpcs standard path and phpcbf standard path in your editor/plugin config to:

/Path/To/MyProject/vendor/codeigniter4/codeigniter4-standard/CodeIgniter4/ruleset.xml

Download install

Download CodeIgniter4-Standard.

Set standard paths to your local filesystem:

'/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml'

Global install

Globally install PHP_CodeSniffer with one of the various methods.

Once complete you should be able to execute phpcs -i on the command line.

You should see something like:-

The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz and Zend.

Either clone this repository...

git clone -b master --depth 1 https://github.com/bcit-ci/CodeIgniter4-Standard.git.

or use composer...

composer global require codeigniter4/codeigniter4-standard

or download.

Take note of the paths where they were installed.

Create a symbolic link to the CodeIgniter4-Standard/CodeIgniter4 directory in php_codesniffer/src/Standards/ eg.

ln -s ~/Documents/Projects/CodeIgniter4-Standard/CodeIgniter4 ~/.composer/vendor/squizlabs/php_codesniffer/src/Standards/CodeIgniter4

or copy the CodeIgniter4-Standard/CodeIgniter4 directory to php_codesniffer/src/Standards/

Executing phpcs -i should now show CodeIgniter4 installed eg.

The installed coding standards are CodeIgniter4, MySource, PEAR, PSR1, PSR2, Squiz and Zend.

You should now be able to set 'CodeIgniter4' as the phpcs standard in the plugin/editor/IDE of your choice.

Command line use

Sniffing errors & warnings (reporting).

Single file...

phpcs /Path/To/MyFile.php --standard='/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml'

or if globally installed.

phpcs /Path/To/MyFile.php --standard=CodeIgniter4

Directory (recursive).

phpcs /Path/To/MyProject --standard='/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml'

or if globally installed.

phpcs /Path/To/MyProject --standard=CodeIgniter4

Fixing fixable errors.

Single file.

phpcbf /Path/To/MyFile.php --standard='/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml'

or if globally installed.

phpcbf /Path/To/MyFile.php --standard=CodeIgniter4

Directory (recursive).

phpcbf /Path/To/MyProject --standard='/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml'

or if globally installed.

phpcbf /Path/To/MyProject --standard=CodeIgniter4

Example editor configs

SublimeText project config

Project > Edit Project

Set it to your preference.

{
    "SublimeLinter":
    {
        "linters":
        {
            "phpcs":
            {
                "@disable": false,
                "cmd": "/Path/To/php_codesniffer/bin/phpcs",
                // Or if installed globally. "cmd": "phpcs",
                "standard": "/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml"
            }
        }
    },
    "folders":
    [
        {
            "path": "/Path/To/MyProject"
        }
    ],
    "settings":
    {
        "phpcs":
        {
            "extensions_to_execute":
            [
                "php"
            ],
            "phpcs_executable_path": "/Path/To/php_codesniffer/bin/phpcs",
            // Or if installed globally. "phpcbf_executable_path": "phpcs",
            "phpcs_additional_args":
            {
                "--standard": "/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml",
                // Optional don't show warnings
                // "-n": ""
            },
            "phpcbf_executable_path": "/Path/To/php_codesniffer/bin/phpcbf",
            // Or if installed globally. "phpcbf_executable_path": "phpcbf",
            "phpcbf_additional_args":
            {
                "--standard": "/Path/To/CodeIgniter4-Standard/CodeIgniter4/ruleset.xml",
                // Optional don't fix warnings (if they're fixable)
                // "-n": ""
            },
            // Execute the sniffer on file save. (Using contextual menu instead)
            "phpcs_execute_on_save": false,
            // Show the error list after save. (Using sublime linter instead)
            "phpcs_show_errors_on_save": false,
            // Show the errors in the quick panel so you can then goto line. (Gets annoying)
            "phpcs_show_quick_panel": false,
            // Turn the debug output on/off.
            "show_debug": false
        }
    }
}

Credits

Thanks to Greg Sherwood, Marc McIntyre, Andy Grunwald, Thomas Ernest and Erik Torsner, for providing open source code which helped me build this standard and a big thanks to Squiz Labs for creating PHP_CodeSniffer.

Thanks to EllisLab for originally creating CodeIgniter and the British Columbia Institute of Technology for continuing the project. Thanks to all the developers and contibutors working on CodeIgniter 4.

codeigniter4-standard's People

Contributors

louisl avatar

Watchers

 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.