Coder Social home page Coder Social logo

yii2-coding-standards's Introduction

Mito Yii 2 Coding Standards

This repository contains Mito's coding standards for Yii 2 based applications.

Build Status Coverage Status

Getting the code

You can get code style definition using one of the following methods.

  • Clone hellowearemito/yii2-coding-standards repository:
$ git clone git://github.com/hellowearemito/yii2-coding-standards.git
$ composer require mito/yii2-coding-standards:"~2.0.0@beta"

PHP_Codesniffer

This repository contains five phpcs standards:

  • Application: for normal class files.
  • Views: for view files, requires using curly braces for control structures.
  • ViewsAlternate: for view files, requires using alternate syntax for control structures.
  • ViewsMixed: for view files, allows both curly braces and alternate syntax.
  • Others: for other files, such as configuration files and migration classes.

These standards are based on PSR2 and Yii 2's coding standard, with some additions and improvements.

The Views standards disable some rules that cause problems when mixing php with html, and therefore cannot fully check view files and cannot fix all problems in them, so be careful when using phpcbf with view files.

For a full description of the rules, see docs/rules.md.

Using the standards

After CodeSniffer is installed, you can launch it with a custom standard using the following syntax:

$ ./vendor/bin/phpcs --extensions=php --standard=vendor/mito/yii2-coding-standards/Application .

To automatically fix most issues, use phpcbf:

$ ./vendor/bin/phpcbf --extensions=php --standard=vendor/mito/yii2-coding-standards/Application .

Warning: always check phpcbf's output and keep backups. If it breaks your code, you get to keep both pieces.

You should also run a syntax check using php -l before running phpcbf, because some sniffs assume the code is syntactically valid, and may mangle it if it is not.

If you're using PhpStorm you can configure it to use CodeSniffer using Settings → PHP → Code Sniffer. The standard can be specified at Inspections → PHP → PHP Code Sniffer validation.

Note that this will check all your files with a single standard, but you should use different standards for different types of files. These standards were designed for use with gulp-phpcs and gulp-phpcbf, so instead of using exclusion patterns in the ruleset.xml, they rely on the gulp task selecting the appropriate standard for a file.

You can write your own ruleset.xml that extends from the Application standard and contains appropriate exclusion patterns (check the Others and Views ruleset.xml files for what rules to exclude).

Useful links

Contributing

See CONTRIBUTING.md for information.

yii2-coding-standards's People

Contributors

nkovacs avatar samdark avatar nkovacs2 avatar resurtm avatar cebe avatar alexgx avatar albertborsos avatar gsherwood avatar qiangxue avatar schmunk42 avatar

Watchers

 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.