Git Product home page Git Product logo

psr12-stroustrup-and-space's Introduction

PSR 12 with Stroustrup + Spaces coding style

This ruleset for PHPCS and PHPCBF adheres to PSR 12 with three changes:

  1. Stroustrup brackets (a K&R variant).

    • The opening bracket is always on the same line
    • No else-cuddling or other compression of control structures, i.e. else and catch keywords are on their own line (followed by the opening bracket).
  2. Spaces in Parentheses

    • One space before and after statement inside parentheses in control structures
    • One space after ! in control structures
  3. Space around functions

    • One blank line before and after functions

Inspired by this question on Stackoverflow.

Example

<?php

namespace Bar;

class Foo {

  public function baz() {
    if ( ! false ) {
      echo('Hello World!');
    }
    else {
      die();
    }
  }

}

Installation

  1. Install Composer.

  2. Add the following section to your composer.json (perhaps preferrably in the global context). This makes this repository visible for composer (replace the github address with your own if you fork the project). You can locate your composer.json with composer config home or composer global config home.

{
    "repositories": [
        {
            "type": "vcs",
            "url": "[email protected]:nicolajknudsen/psr12-stroustrup-and-space"
        }
    ]
}
  1. Run the following to install the project and dependencies, including dev dependencies. Add a global if you are installing globally. Allow the plugin from "dealerdirect/phpcodesniffer-composer-installer" when prompted.
composer require nicolajknudsen/psr12-stroustrup-and-space:dev-master

That's it. Check that the coding standard is available by running phpcs -i.

VS Code

To make use of the linting and fixing ability af PHPCS and PHPCBF in VS Code, complete the following steps:

  1. Install the PHPSAB extension in VS Code.
  2. Point the config to /path/to/composer/vendor/bin. Follow the guide in the extension documentation, or just open settings.json in VS Code with ctrl+shift+P and add the following config:
{
  "phpsab.executablePathCS": "/path/to/composer/vendor/bin/phpcs",
  "phpsab.executablePathCBF": "/path/to/composer/vendor/bin/phpcbf",
  "phpsab.standard": "psr12-stroustrup-and-space",
  "phpsab.debug": true,
  "phpsab.fixerEnable": true,
  "phpsab.snifferEnable": true,
  "phpsab.snifferShowSources": true
}

psr12-stroustrup-and-space's People

Stargazers

Anatoly IVANOV 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.