flaconi/coding-standard

Flaconi Coding Standard for PHP_CodeSniffer

Installs: 40 278

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 22

Forks: 1

Open Issues: 0

Type:phpcodesniffer-standard

5.0.0 2021-11-04 09:47 UTC

This package is auto-updated.

Last update: 2024-04-16 23:37:38 UTC


README

Latest version Downloads Travis build status Code coverage PHPStan

Flaconi Coding Standard for PHP_CodeSniffer provides sniffs that fall for now in one category:

  • Test - improving the code style of phpunit test cases

Table of contents

  1. Sniffs included in this standard
  2. Installation
  3. How to run the sniffs
  4. Fixing errors automatically
  5. Suppressing sniffs locally
  6. Contributing

Sniffs included in this standard

🔧 = Automatic errors fixing

Test - improving the code style of phpunit test cases

FlaconiCodingStandard.Test.UseMethodPrefixInTestcase 🔧

  • Checks for @test and force to use test Prefix

FlaconiCodingStandard.Test.UseStaticCallsForAssertInTestcase 🔧

Reports usage of non static assert method class

Installation

The recommended way to install Flaconi Coding Standard is through Composer.

composer require --dev flaconi/coding-standard

How to run the sniffs

You can choose one of two ways to run only selected sniffs from the standard on your codebase:

Choose which sniffs to run

Mention Flaconi Coding Standard in your project's ruleset.xml:

<?xml version="1.0"?>
<ruleset name="AcmeProject">
	<rule ref="vendor/flaconi/coding-standard/src/ruleset.xml"><!-- relative path to your ruleset.xml -->
		<!-- sniffs to exclude -->
	</rule>
</ruleset>

When running phpcs on the command line, use the --sniffs option to list all the sniffs you want to use separated by a comma:

vendor/bin/phpcs --standard=ruleset.xml \
--sniffs=FlaconiCodingStandard.Test.UseStaticCallsForAssertInTestcase,FlaconiCodingStandard.Test.UseMethodPrefixInTestcase \
--extensions=php --encoding=utf-8 --tab-width=4 -sp src tests

Or write your own ruleset.xml by referencing the selected sniffs. This is a sample ruleset.xml:

<?xml version="1.0"?>
<ruleset name="AcmeProject">
	<config name="installed_paths" value="../../flaconi/coding-standard"/><!-- relative path from PHPCS source location -->
	<rule ref="FlaconiCodingStandard.Test.UseMethodPrefixInTestcase"/>
	<!-- other sniffs to include -->
</ruleset>

Then run the phpcs executable the usual way:

vendor/bin/phpcs --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests

Fixing errors automatically

Sniffs in this standard marked by the 🔧 symbol support automatic fixing of coding standard violations. To fix your code automatically, run phpcbf instead of phpcs:

vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests

Always remember to back up your code before performing automatic fixes and check the results with your own eyes as the automatic fixer can sometimes produce unwanted results.

Contributing

To make this repository work on your machine, clone it and run these two commands in the root directory of the repository:

composer install
composer code-style
composer tests

After writing some code and editing or adding unit tests, run phing again to check that everything is OK:

composer code-style
composer tests

We are always looking forward for your bugreports, feature requests and pull requests. Thank you.