addiks/more-php-cs-fixers

Extension for PHP-CS-Fixer with more fixers

v0.2.0 2022-09-29 12:56 UTC

This package is auto-updated.

Last update: 2024-10-29 05:23:14 UTC


README

Travis Build Status Scrutinizer Build Status Scrutinizer Code Quality Code Coverage

More PHP-CS-Fixer's

This repository contains a few additional fixers for the PHP-CS-Fixer project:

  • Add a blank line before doc-comments
  • Add a blank line before else- and elseif-codeblocks
  • Add a blank line before catch- and finally-codeblocks

Setup

1. Install package via composer:

composer require addiks/more-php-cs-fixers

2. Register fixers in PHP-CS-Fixer configuration (file .php_cs).:

<?php

+use Addiks\MorePhpCsFixers\Whitespace\BlankLineBeforeCatchBlockFixer;
+use Addiks\MorePhpCsFixers\Whitespace\BlankLineBeforeElseBlockFixer;
+use Addiks\MorePhpCsFixers\Whitespace\BlankLineBeforeDocCommentFixer;

$config = PhpCsFixer\Config::create();
+$config->registerCustomFixers([
+    new BlankLineBeforeCatchBlockFixer(),
+    new BlankLineBeforeElseBlockFixer(),
+    new BlankLineBeforeDocCommentFixer(),
+]);
+$config->setRules([
+    'Addiks/blank_line_before_catch_block': true,
+    'Addiks/blank_line_before_else_block': true,
+    'Addiks/blank_line_before_doccomment': true,
+]);
return $config;

The fixers

Addiks/blank_line_before_catch_block

<?php

try {
    foo();
+
} catch (\Exception $b) {
    bar();
+
} finally {
    baz();
}

Addiks/blank_line_before_else_block

<?php
if ($a) {
    foo();
+
} elseif ($b) {
    bar();
+
} else {
    baz();
}

Addiks/blank_line_before_doccomment

<?php
/** @var string $foo */
$foo = "Lorem ipsum";
+
/** @var string $bar */
$bar = "dolor sit amet";

Addiks/correct_order_in_var_doccomment

<?php
-/** @var $foo string */
+/** @var string $foo */

Addiks/nullable_in_doccomment

<?php
-/** @var ?string $foo */
+/** @var string|null $foo */

Addiks/array_in_doccomment

<?php
-/** @var string[] $foo */
+/** @var array<string> $foo */