All Projects → kubawerlos → Php Cs Fixer Custom Fixers

kubawerlos / Php Cs Fixer Custom Fixers

Licence: mit
A set of custom fixers for PHP CS Fixer

Projects that are alternatives of or similar to Php Cs Fixer Custom Fixers

Pep8speaks
A GitHub app to automatically review Python code style over Pull Requests
Stars: ✭ 546 (+628%)
Mutual labels:  static-analysis, code-style
vscode-checkstyle
Haxe Checkstyle extension for Visual Studio Code
Stars: ✭ 24 (-68%)
Mutual labels:  static-analysis, code-style
Php Cs Fixer
A tool to automatically fix PHP Coding Standards issues
Stars: ✭ 10,709 (+14178.67%)
Mutual labels:  static-analysis, code-style
Scalastyle
scalastyle
Stars: ✭ 679 (+805.33%)
Mutual labels:  static-analysis, code-style
Flake8
The official GitHub mirror of https://gitlab.com/pycqa/flake8
Stars: ✭ 1,112 (+1382.67%)
Mutual labels:  static-analysis
Cognicrypt
CogniCrypt is an Eclipse plugin that supports Java developers in using Java Cryptographic APIs.
Stars: ✭ 50 (-33.33%)
Mutual labels:  static-analysis
Apisan
APISan: Sanitizing API Usages through Semantic Cross-Checking
Stars: ✭ 46 (-38.67%)
Mutual labels:  static-analysis
Php Language Server
PHP Implementation of the VS Code Language Server Protocol 🆚↔🖥
Stars: ✭ 1,019 (+1258.67%)
Mutual labels:  static-analysis
Mobile Security Framework Mobsf
Mobile Security Framework (MobSF) is an automated, all-in-one mobile application (Android/iOS/Windows) pen-testing, malware analysis and security assessment framework capable of performing static and dynamic analysis.
Stars: ✭ 10,212 (+13516%)
Mutual labels:  static-analysis
Kube Linter
KubeLinter is a static analysis tool that checks Kubernetes YAML files and Helm charts to ensure the applications represented in them adhere to best practices.
Stars: ✭ 1,177 (+1469.33%)
Mutual labels:  static-analysis
Comb
Interactive code auditing and grep tool in Emacs Lisp
Stars: ✭ 58 (-22.67%)
Mutual labels:  static-analysis
Pysonar2
PySonar2: an advanced semantic indexer for Python
Stars: ✭ 1,074 (+1332%)
Mutual labels:  static-analysis
Terraform Security Scan
Run a security scan on your terraform with the very nice https://github.com/liamg/tfsec
Stars: ✭ 64 (-14.67%)
Mutual labels:  static-analysis
Intellidroid
A targeted input generator for Android that improves the effectiveness of dynamic malware analysis.
Stars: ✭ 46 (-38.67%)
Mutual labels:  static-analysis
Anchore Engine
A service that analyzes docker images and applies user-defined acceptance policies to allow automated container image validation and certification
Stars: ✭ 1,192 (+1489.33%)
Mutual labels:  static-analysis
Stoat
STatic (LLVM) Object file Analysis Tool
Stars: ✭ 44 (-41.33%)
Mutual labels:  static-analysis
Cxxctp
DEPRECATED. USE INSTEAD github.com/blockspacer/flextool
Stars: ✭ 58 (-22.67%)
Mutual labels:  static-analysis
Sonar Swift
sonar-swift.SonarQube iOS Plugin, Support Objective-C And Swift, Support Infer (SonarQube iOS 代码扫描插件,支持 Objective-C 和 Swift ,支持 Infer 结果导入 ) base on https://github.com/Idean/sonar-swift
Stars: ✭ 70 (-6.67%)
Mutual labels:  static-analysis
Clj Kondo
A linter for Clojure code that sparks joy.
Stars: ✭ 1,083 (+1344%)
Mutual labels:  static-analysis
Phpstorm Ide Config
My PhpStorm configuration for writing modern PHP code
Stars: ✭ 55 (-26.67%)
Mutual labels:  code-style

PHP CS Fixer: custom fixers

Latest stable version PHP version License Repository size Last commit

CI Status Code coverage Tests Mutation testing badge Psalm type coverage

A set of custom fixers for PHP CS Fixer.

Installation

PHP CS Fixer: custom fixers can be installed by running:

composer require --dev kubawerlos/php-cs-fixer-custom-fixers

Usage

In your PHP CS Fixer configuration register fixers and use them:

 <?php
 return PhpCsFixer\Config::create()
+    ->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
     ->setRules([
         '@PSR2' => true,
         'array_syntax' => ['syntax' => 'short'],
+        PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer::name() => true,
+        PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer::name() => true,
     ]);

Fixers

CommentSurroundedBySpacesFixer

Comment must be surrounded by spaces.

 <?php
-/*foo*/
+/* foo */

CommentedOutFunctionFixer

Configured functions must be commented out. Risky: when any of the configured functions has side effects or is overridden. Configuration options:

  • functions (array): list of functions to comment out; defaults to ['print_r', 'var_dump', 'var_export']
 <?php
-var_dump($x);
+//var_dump($x);

DataProviderNameFixer

Name of data provider that is used only once must match name of test. Risky: when relying on name of data provider function. Configuration options:

  • prefix (string): prefix that replaces "test"; defaults to 'provide'
  • suffix (string): suffix to be added at the end"; defaults to 'Cases'
 <?php
 class FooTest extends TestCase {
     /**
-     * @dataProvider dataProvider
+     * @dataProvider provideHappyPathCases
      */
     public function testHappyPath() {}
-    public function dataProvider() {}
+    public function provideHappyPathCases() {}
 }

DataProviderReturnTypeFixer

Return type of data provider must be iterable. Risky: when relying on signature of data provider.

 <?php
 class FooTest extends TestCase {
     /**
      * @dataProvider provideHappyPathCases
      */
     public function testHappyPath() {}
-    public function provideHappyPathCases(): array {}
+    public function provideHappyPathCases(): iterable {}
 }

DataProviderStaticFixer

Data provider must be static.

 <?php
 class FooTest extends TestCase {
     /**
      * @dataProvider provideHappyPathCases
      */
     public function testHappyPath() {}
-    public function provideHappyPathCases() {}
+    public static function provideHappyPathCases() {}
 }

InternalClassCasingFixer

Class defined internally by an extension, or the core should be called using the correct casing.

 <?php
-$foo = new STDClass();
+$foo = new stdClass();

MultilineCommentOpeningClosingAloneFixer

Multiline comment/PHPDoc must have opening and closing line without any extra content.

 <?php
-/** Hello
+/**
+ * Hello
  * World!
  */;

NoCommentedOutCodeFixer

There should be no commented out code.

 <?php
-//var_dump($_POST);
 print_r($_POST);

NoDoctrineMigrationsGeneratedCommentFixer

There must be no comment generated by Doctrine Migrations.

 <?php
 namespace Migrations;
 use Doctrine\DBAL\Schema\Schema;
-/**
- * Auto-generated Migration: Please modify to your needs!
- */
 final class Version20180609123456 extends AbstractMigration
 {
     public function up(Schema $schema)
     {
-        // this up() migration is auto-generated, please modify it to your needs
         $this->addSql("UPDATE t1 SET col1 = col1 + 1");
     }
     public function down(Schema $schema)
     {
-        // this down() migration is auto-generated, please modify it to your needs
         $this->addSql("UPDATE t1 SET col1 = col1 - 1");
     }
 }

NoDuplicatedArrayKeyFixer

Duplicated array keys must be removed.

 <?php
 $x = [
-    "foo" => 1,
     "bar" => 2,
     "foo" => 3,
 ];

NoDuplicatedImportsFixer

Duplicated use statements must be removed.

 <?php
 namespace FooBar;
 use Foo;
-use Foo;
 use Bar;

NoImportFromGlobalNamespaceFixer

There must be no import from global namespace.

 <?php
 namespace Foo;
-use DateTime;
 class Bar {
-    public function __construct(DateTime $dateTime) {}
+    public function __construct(\DateTime $dateTime) {}
 }

NoLeadingSlashInGlobalNamespaceFixer

When in global namespace there must be no leading slash for class.

 <?php
-$x = new \Foo();
+$x = new Foo();
 namespace Bar;
 $y = new \Baz();

NoNullableBooleanTypeFixer

There must be no nullable boolean type. Risky: when the null is used.

 <?php
-function foo(?bool $bar) : ?bool
+function foo(bool $bar) : bool
 {
      return $bar;
  }

NoPhpStormGeneratedCommentFixer

There must be no comment generated by PhpStorm.

 <?php
-/**
- * Created by PhpStorm.
- * User: root
- * Date: 01.01.70
- * Time: 12:00
- */
 namespace Foo;

NoReferenceInFunctionDefinitionFixer

There must be no reference in function definition. Risky: when rely on reference.

 <?php
-function foo(&$x) {}
+function foo($x) {}

NoSuperfluousConcatenationFixer

There should not be superfluous inline concatenation of strings. Configuration options:

  • allow_preventing_trailing_spaces (bool): whether to keep concatenation if it prevents having trailing spaces in string; defaults to false
 <?php
-echo 'foo' . 'bar';
+echo 'foobar';

NoUselessCommentFixer

There must be no comment like "Class Foo".

 <?php
 /**
- * Class Foo
  * Class to do something
  */
 class Foo {
     /**
-     * Get bar
      */
     function getBar() {}
 }

NoUselessDoctrineRepositoryCommentFixer

There must be no comment generated by the Doctrine ORM.

 <?php
-/**
- * FooRepository
- *
- * This class was generated by the Doctrine ORM. Add your own custom
- * repository methods below.
- */
 class FooRepository extends EntityRepository {}

NoUselessParenthesisFixer

There must be no useless parenthesis.

 <?php
-foo(($bar));
+foo($bar);

NoUselessSprintfFixer

Function sprintf without parameters should not be used. DEPRECATED: use no_useless_sprintf instead. Risky: when the function sprintf is overridden.

 <?php
-$foo = sprintf('Foo');
+$foo = 'Foo';

NoUselessStrlenFixer

Function strlen (or mb_strlen) should not be used when compared to 0. Risky: when the function strlen is overridden.

 <?php
-$isEmpty = strlen($string) === 0;
-$isNotEmpty = strlen($string) > 0;
+$isEmpty = $string === '';
+$isNotEmpty = $string !== '';

NumericLiteralSeparatorFixer

Numeric literals must have configured separators. Configuration options:

  • binary (bool, null): whether add, remove or ignore separators in binary numbers.; defaults to false
  • decimal (bool, null): whether add, remove or ignore separators in decimal numbers.; defaults to false
  • float (bool, null): whether add, remove or ignore separators in float numbers.; defaults to false
  • hexadecimal (bool, null): whether add, remove or ignore separators in hexadecimal numbers.; defaults to false
  • octal (bool, null): whether add, remove or ignore separators in octal numbers.; defaults to false
 <?php
-echo 0b01010100_01101000; // binary
-echo 135_798_642; // decimal
-echo 1_234.456_78e-4_321; // float
-echo 0xAE_B0_42_FC; // hexadecimal
-echo 0123_4567; // octal
+echo 0b0101010001101000; // binary
+echo 135798642; // decimal
+echo 1234.45678e-4321; // float
+echo 0xAEB042FC; // hexadecimal
+echo 01234567; // octal

OperatorLinebreakFixer

Operators - when multiline - must always be at the beginning or at the end of the line. DEPRECATED: use operator_linebreak instead. Configuration options:

  • only_booleans (bool): whether to limit operators to only boolean ones; defaults to false
  • position ('beginning', 'end'): whether to place operators at the beginning or at the end of the line; defaults to 'beginning'
 <?php
 function foo() {
-    return $bar ||
-        $baz;
+    return $bar
+        || $baz;
 }

PhpUnitNoUselessReturnFixer

PHPUnit's functions fail, markTestIncomplete and markTestSkipped should not be followed directly by return. Risky: when PHPUnit's native methods are overridden.

 <?php
 class FooTest extends TestCase {
     public function testFoo() {
         $this->markTestSkipped();
-        return;
     }
 }

PhpdocNoIncorrectVarAnnotationFixer

@var must be correct in the code.

 <?php
-/** @var Foo $foo */
 $bar = new Foo();

PhpdocNoSuperfluousParamFixer

There must be no superfluous parameters in PHPDoc.

 <?php
 /**
  * @param bool $b
- * @param int $i
  * @param string $s this is string
- * @param string $s duplicated
  */
 function foo($b, $s) {}

PhpdocOnlyAllowedAnnotationsFixer

Only listed annotations can be in PHPDoc. Configuration options:

  • elements (array): list of annotations to keep in PHPDoc; defaults to []
 <?php
 /**
  * @author John Doe
- * @package foo
- * @subpackage bar
  * @version 1.0
  */
 function foo_bar() {}

PhpdocParamOrderFixer

@param annotations must be in the same order as function's parameters.

 <?php
 /**
+ * @param int $a
  * @param int $b
- * @param int $a
  * @param int $c
  */
 function foo($a, $b, $c) {}

PhpdocParamTypeFixer

@param must have type.

 <?php
 /**
  * @param string $foo
- * @param        $bar
+ * @param mixed  $bar
  */
 function a($foo, $bar) {}

PhpdocSelfAccessorFixer

In PHPDoc inside class or interface element self should be preferred over the class name itself.

 <?php
 class Foo {
     /**
-     * @var Foo
+     * @var self
      */
      private $instance;
 }

PhpdocSingleLineVarFixer

@var annotation must be in single line when is the only content.

 <?php
 class Foo {
-    /**
-     * @var string
-     */
+    /** @var string */
     private $name;
 }

PhpdocTypesTrimFixer

PHPDoc types must be trimmed.

 <?php
 /**
- * @param null | string $x
+ * @param null|string $x
  */
 function foo($x) {}

SingleSpaceAfterStatementFixer

Single space must follow - not followed by semicolon - statement. Configuration options:

  • allow_linebreak (bool): whether to allow statement followed by linebreak; defaults to false
 <?php
-$foo = new    Foo();
-echo$foo->__toString();
+$foo = new Foo();
+echo $foo->__toString();

SingleSpaceBeforeStatementFixer

Single space must precede - not preceded by linebreak - statement.

 <?php
-$foo =new Foo();
+$foo = new Foo();

Contributing

Request feature or report bug by creating issue.

Alternatively, fork the repo, develop your changes, regenerate README.md:

php ./dev-tools/readme > ./README.md

make sure all checks pass:

./dev-tools/check_file_permissions.sh
./dev-tools/check_trailing_whitespaces.sh
composer verify
composer infection

and submit pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].