A set of Wieni best practices, coding standards and tools to enforce them.
- A central location to keep track of our written coding standards and best practices
- Make configuration for tools to enforce our codestyle available in all of our repositories, without having to duplicate and sync them manually
This package requires PHP 7.1 or higher and can be installed using Composer:
composer require --dev wieni/wmcodestyleThis package provides a command to sync any file from this repository to
your project. It is recommended to add it to the scripts section of
composer.json so it is automatically executed at the appropriate time.
{
"name": "foo/bar",
"require": {
"php": "^7.2",
},
"require-dev": {
"wieni/wmcodestyle": "^1.0"
+ },
+ "scripts": {
+ "post-update-cmd": [
+ "wmcodestyle sync .editorconfig --quiet"
+ ]
}
}This package provides a configuration factory and multiple rule sets for
friendsofphp/php-cs-fixer.
Pick one of the rule sets:
Wieni\wmcodestyle\PhpCsFixer\Config\RuleSet\Php71Wieni\wmcodestyle\PhpCsFixer\Config\RuleSet\Php73Wieni\wmcodestyle\PhpCsFixer\Config\RuleSet\Php74Wieni\wmcodestyle\PhpCsFixer\Config\RuleSet\Php80
Create a configuration file .php_cs.php in the root of your project:
<?php
use Wieni\wmcodestyle\PhpCsFixer\Config\Factory;
use Wieni\wmcodestyle\PhpCsFixer\Config\RuleSet\Php73;
$config = Factory::fromRuleSet(new Php73);
$config->getFinder()
->ignoreVCSIgnored(true)
->in(__DIR__)
->name('/\.(php|module|inc|install|test|profile|theme)$/')
->notPath('/(public|web)\/(index|update)\.php/');
$config->setCacheFile(__DIR__ . '/.php_cs.cache');
return $config;By default, risky rules are not used. To use them, pass --allow-risky=yes to php-cs-fixer or set the
WMCODESTYLE_RISKY=1 environment variable.
All configuration examples use the caching feature, and if you want to
use it as well, you should add the cache file to .gitignore:
# Ignore files generated by wieni/wmcodestyle
.php_cs.cache💡 Optionally override rules from a rule set by passing in an array of rules to be merged in:
<?php
use Wieni\wmcodestyle\PhpCsFixer\Config\Factory;
use Wieni\wmcodestyle\PhpCsFixer\Config\RuleSet\Php73;
-$config = Factory::fromRuleSet(new Php73);
+$config = Factory::fromRuleSet(new Php73, [
+ 'mb_str_functions' => false,
+ 'strict_comparison' => false,
+]);
$config->getFinder()
->ignoreVCSIgnored(true)
->in(__DIR__)
->name('/\.(php|module|inc|install|test|profile|theme)$/')
->notPath('/(public|web)\/(index|update)\.php/');
$config->setCacheFile(__DIR__ . '/.php_cs.cache');
return $config;If you like Makefiles, create a Makefile with a coding-standards target:
+.PHONY: coding-standards
+coding-standards: vendor
+ mkdir -p .build/php-cs-fixer
+ vendor/bin/php-cs-fixer fix --config=.php_cs --diff --verbose
vendor: composer.json composer.lock
composer validate
composer installRun
$ make coding-standards
to automatically fix coding standard violations.
If you like composer scripts, add a coding-standards script to composer.json:
{
"name": "foo/bar",
"require": {
"php": "^7.2",
},
"require-dev": {
"wieni/wmcodestyle": "^1.0"
+ },
+ "scripts": {
+ "coding-standards": [
+ "php-cs-fixer fix --config=.php_cs.php"
+ ]
}
}Run
$ composer coding-standards
All notable changes to this project will be documented in the CHANGELOG file.
If you discover any security-related issues, please email security@wieni.be instead of using the issue tracker.
Distributed under the MIT License. See the LICENSE file for more information.