Code Monkey home page Code Monkey logo

ongr-strict-standard's Introduction

ONGR Strict Coding Standard

https://travis-ci.org/ongr-io/ongr-strict-standard.svg?branch=master

This standard provides strict code style checking for whitespace, commenting style and PHPDoc. It is PSR-2 compatible, enforces good programming and documentation practices.

Example

Ever wanted to standardize your team's code style? This is a PSR-2 compliant code:

<?php
namespace Project\MyClass ;

use Foo;

/**
 *  this class has method

 */
class MyClass
{

    public function foo($param)
    {
        $a = $param *  2;
        return $a+1;

    }
}

No more code like this!

After ONGR Strict Standard validation:

----------------------------------------------------------------------
FOUND 10 ERRORS AFFECTING 8 LINES
----------------------------------------------------------------------
1 | ERROR | [ ] There must be one blank line after the php open tag
|       |     and no whitespaces
2 | ERROR | [x] Space found before semicolon; expected "MyClass;"
|       |     but found "MyClass ;"
10 | ERROR | [ ] Class name doesn't match filename; expected "class
|       |     testas"
11 | ERROR | [ ] Expected no blank lines after an opening brace, 1
|       |     found
13 | ERROR | [ ] Missing function doc comment
15 | ERROR | [x] Expected 1 space after "*"; 2 found
16 | ERROR | [ ] Missing blank line before return statement
16 | ERROR | [x] Expected 1 space before "+"; 0 found
16 | ERROR | [x] Expected 1 space after "+"; 0 found
18 | ERROR | [x] Expected no blank lines before closing function
|       |     brace; 1 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 68ms; Memory: 5.75Mb

Features

  • Standardizes whitespace almost everywhere. E.g. between methods, spaces around operators, indentation of statements, etc.
  • Required class short description everywhere except for PHPUnit testing classes.
  • Required method short descriptions except for setters / getters and some magic methods.
  • Comments start with capital letter and ends with appropriate punctuation. This suggests proper documentation and reduces laziness.
  • Short array syntax is required.
  • Require type hinting in PHPDoc for all parameters. Require @return and @throws tags where necessary.
  • Code must not be aligned in assignments and array definitions.
  • Strings should be "double quoted" only with a reason ($variable interpolation inside, etc.)

Requirements

  • PHP >=5.4
  • CodeSniffer 2.x

Acknowledgement

Our work is based solely on Squiz Labs Squiz coding standard and opensky Symfony2 coding standard.

Installation

Composer:

{
   "require-dev": {
      "ongr/ongr-strict-standard": "2.*",
      "squizlabs/php_codesniffer": "2.*"
   }
}

Or optionally you can install globally to all projects at ~/.composer/composer.json.

Then: composer global update.

Warning: if you are planing on developing, then sources should be located in ONGR directory.

For example, when cloning add target directory:

git clone [email protected]:<username>/ongr-strict-standard.git ONGR

Running

vendor/bin/phpcs -p --standard=/home/<user>/.composer/vendor/ongr/ongr-strict-standard/ONGR --ignore=vendor/,Tests/app/,Resources/public/ ./

Note: Do not use ~ for HOME parameter, as PHPCS will not expand it.

Note: IDEs also support running Code Sniffer and adding error annotations directly on editor's source code (e.g. PHPStorm). Please see your IDE's documentation on how to add standard from custom directory.

PHPStorm Helper

Configure PHPCS: http://www.jetbrains.com/phpstorm/webhelp/using-php-code-sniffer-tool.html

Configure this standard:

1. Go to Settings > Inspections > PHP > PHP Code Sniffer Validation. 1. Mark checkbox ON for "PHP Code Sniffer Validation". 1. Select Custom standard. 1. Locate vendor/ongr/ongr-strict-standard/ONGR standard directory, press OK.

Code should be validated automatically on each PHP file edit.

License

This bundle is under the MIT license. Please, see the complete license in the bundle LICENSE file.

ongr-strict-standard's People

Contributors

tautrimas avatar grandltu avatar saimaz avatar dvondrak avatar trylika avatar lmikelionis avatar gimikus avatar ex13 avatar lauriis2 avatar

Watchers

James Cloos 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.