Skip to content

weerd/php-style

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

✨ PHP Styles ✨

This package provides a simple way to apply pre-configured base style rules for the PHP Code Standards Fixer tool, that can be easily shared across projects and packages using PHP 7+.

It can be configured using the default rules or you can specify a different supported base ruleset, along with any additional rules or overrides you would like to include.

Installation

$ composer require weerd/php-style 

Usage

Add a .php_cs.dist in the root directory of your project or pacakge.

Within that file create a new instance of PhpCsFixer\Finder and configure what files and directories the PHP CS Fixer tool should be looking to fix code style.

Next, call the Weerd\PhpStyle\configure() function and pass the instance of the finder as the first argument.

Below are some examples along with variations utilizing the $options array:

Example using default ruleset

The following example returns a configuration with the default rules for PHP styles.

<?php use PhpCsFixer\Finder; $finder = Finder::create() ->in([ __DIR__.'/src', __DIR__.'/tests', ]); return Weerd\PhpStyle\configure($finder);

Example using default ruleset and additional rules

The following example returns a configuration with the default rules, along with two additional rules included in the final set of rules for PHP styles.

<?php use PhpCsFixer\Finder; $finder = Finder::create() ->in([ __DIR__.'/src', __DIR__.'/tests', ]) ->notName('*.blade.php'); $options = [ 'rules' => [ 'single_quote' => true, 'trim_array_spaces' => true, ], ]; return Weerd\PhpStyle\configure($finder, $options);

Example using laravel ruleset

The following example returns a configuration with the laravel rules for PHP styles.

<?php use PhpCsFixer\Finder; $finder = Finder::create() ->in([ __DIR__.'/app', __DIR__.'/config', __DIR__.'/database', __DIR__.'/routes', __DIR__.'/tests', ]) ->notName('*.blade.php'); return Weerd\PhpStyle\configure($finder, ['base' => 'laravel']);

Credits

🙌 Thanks to @Spatie and their Laravel Package Training course for opening my eyes and introducing me to the PHP Code Standards Fixer tool and how to use it!

🙌 This package is heavily inspired by @timacdonald's great article on how to share PHP CS Fixer rules!

🙌 The complete set of Laravel specific rules are thanks to @laravel-shift and the compiled rules shared in a gist and used on Laravel Shift!

About

Shareable pre-configured base style rules for the PHP Code Standards Fixer tool.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages