Skip to content

stefna/codestyle

Repository files navigation

Stefna Codestyle

Usage

vendor/bin/phpcs -n --standard=vendor/stefna/codestyle/library.xml src/

License

The MIT License (MIT). Please see License File for more information.

Sniffs

DeclareStrictSniff

Now enforces that <?php declare(strict_types=1); becomes the first line in the file.

MultiLineFunctionDeclarationSniff

Add support for empty methods on a single line. Example:

class Example
{
	public function empty(): void {};
}

Enforce multi row parameters to not be on the first row. Example:

class Example
{
	public function test(
		#[Attribute]
		int $param,
	)
}

DocCommentSniff

Allows some doc blocks to work as single line:

  • @var
  • @phpstan-var
  • @type
  • @lang
  • @noinspection
  • @use
  • @deprecated
  • @phpstan-ignore-next-line
/** @var string $var */

@return doesn't need any description/data:

/**
 * @return
 */

ControlStructureSpacingSniff

Adding an exception to allow multiline if-statments to be indented less, if started on the same line as the opening parenthesis.

Example:

	if (isset(
		$a['key'],
		$a['key']['subKey'],
	)) {
	}

CamelCapsMethodNameSniff

Allow a the custom case of everything being upper case.

class Example
{
	public function METHOD(): void {}
}

BracketPlacementSniff

Two rules are enfored by this.

First, a control statement has to be on it's own line. Example:

if (false) {
    doSomething();
}
else {
    doSomethingElse();
}

Second, foces the closing bracket to be on it's own line except if it's on a single line with an empty body. Example:

if (false) {}

BlanLinesSniff

Enforces that inside a function, the first line after the opening { can't be empty Example:

function test(): void
{
	$var = 'This has to be the first line';
}

It also enforces that the spacing between rows can be 0 or 1 blank line. Example:

function test(): void
{
	$var = 0;

	$var += 1;
	$var *= 2;
}

StaticSniff

Now warns about closures to be static if they don't have $this in body Example:

$closure = static function () {
	something();
};

$fn = static fn () => something();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •