corpus/coding-standard

Corpus Coding Standard for PHP_CodeSniffer

Installs: 46 757

Dependents: 20

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 1

Type:phpcodesniffer-standard

v0.8.0 2023-11-02 19:15 UTC

README

Latest Stable Version Total Downloads License ci.yml

Corpus Coding Standard for PHP_CodeSniffer.

Requirements

  • dealerdirect/phpcodesniffer-composer-installer: *
  • squizlabs/php_codesniffer: *
  • slevomat/coding-standard: ^8.14
  • php: >=7.4

Installing

Install the latest version with:

composer require --dev 'corpus/coding-standard'

Sniffs

Class: \Corpus\Sniffs\ControlStructures\ClosingBraceNewlineSniff

Sniff: Corpus.ControlStructures.ClosingBraceNewline

Ensure that all closing curly brackets are followed by a blank line.

Example:

if( $foo ) {
    echo $bar;
}
echo $baz;

Becomes:

if( $foo ) {
    echo $bar;
}

echo $baz;

Class: \Corpus\Sniffs\ControlStructures\OpeningOneTrueBraceSniff

Sniff: Corpus.ControlStructures.OpeningOneTrueBrace

Ensure that the K&R "One True Brace" style is used.

Example:

class Foo
{
    public function bar()
    {
        echo "bbq";
    }
}

Becomes:

class Foo {
    public function bar() {
        echo "bbq";
    }
}

Class: \Corpus\Sniffs\General\BinaryOperationNewlineSniff

Sniff: Corpus.General.BinaryOperationNewline

Ensure that in multiline logical statements && and || lead lines rather than trail.

Example:

if(
    $foo &&
    $bar &&
    $baz
)}

Becomes:

if(
    $foo
    && $bar
    && $baz
)}

Class: \Corpus\Sniffs\General\ReturnTrailingNewlineSniff

Sniff: Corpus.General.ReturnTrailingNewline

Ensure that no blank lines separate return statements and following curly braces.

Example:

if( $foo == true ){
    return 1;

}

Becomes:

if( $foo == true ){
    return 1;
}

Class: \Corpus\Sniffs\Methods\ClosureSpacingSniff

Sniff: Corpus.Methods.ClosureSpacing

Force whitespace between function/fn keyword and opening paren on closures.

Example:

$foo = function ( string $foo ) { echo $foo; };
$bar = fn ( int $bar ) => $bar + 1;

Becomes:

$foo = function( string $foo ) { echo $foo; };
$bar = fn( int $bar ) => $bar + 1;

Class: \Corpus\Sniffs\Methods\MethodParameterFormattingSniff

Sniff: Corpus.Methods.MethodParameterFormatting

Set a maximum length for function arguments. Fix by breaking into multiple lines.

Example:

function Foo( ClosingBraceNewlineSniffTest $closingBraceNewlineSniffTest, OpeningOneTrueBraceSniffTest $openingOneTrueBraceSniffTest ) { }

Becomes:

function Foo(
    ClosingBraceNewlineSniffTest $closingBraceNewlineSniffTest,
    OpeningOneTrueBraceSniffTest $openingOneTrueBraceSniffTest
) { }
<?php
namespace Corpus\Sniffs\Methods;

class MethodParameterFormattingSniff {
	/**
	 * Maximum line character length after which to break function arguments into newlines
	 */
	public $maxLength = 130;
}

Inherited Sniffs