Skip to content

Commit b765b81

Browse files
committed
Add README
1 parent 0bdf9c6 commit b765b81

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# CodeIgniter Coding Standard
2+
3+
[![Unit Tests](https://github.com/CodeIgniter/coding-standard/actions/workflows/test-phpunit.yml/badge.svg)](https://github.com/CodeIgniter/coding-standard/actions/workflows/test-phpunit.yml)
4+
[![Coding Standards](https://github.com/CodeIgniter/coding-standard/actions/workflows/test-coding-standards.yml/badge.svg)](https://github.com/CodeIgniter/coding-standard/actions/workflows/test-coding-standards.yml)
5+
[![PHPStan Static Analysis](https://github.com/CodeIgniter/coding-standard/actions/workflows/test-phpstan.yml/badge.svg)](https://github.com/CodeIgniter/coding-standard/actions/workflows/test-phpstan.yml)
6+
[![PHPStan level](https://img.shields.io/badge/PHPStan-max%20level-brightgreen)](phpstan.neon.dist)
7+
[![Coverage Status](https://coveralls.io/repos/github/CodeIgniter/coding-standard/badge.svg?branch=develop)](https://coveralls.io/github/CodeIgniter/coding-standard?branch=develop)
8+
[![Latest Stable Version](http://poser.pugx.org/codeigniter/coding-standard/v)](https://packagist.org/packages/codeigniter/coding-standard)
9+
[![License](https://img.shields.io/github/license/codeigniter/coding-standard)](LICENSE)
10+
[![Total Downloads](http://poser.pugx.org/codeigniter/coding-standard/downloads)](https://packagist.org/packages/codeigniter/coding-standard)
11+
12+
This library holds the official coding standards of CodeIgniter based
13+
on [PHP CS Fixer][1] and powered by [Nexus CS Config][2].
14+
15+
## Installation
16+
17+
You can add this library as a local, per-project dependency to your project
18+
using [Composer](https://getcomposer.org/):
19+
20+
composer require codeigniter/coding-standard
21+
22+
If you only need this library during development, for instance to run your project's test suite,
23+
then you should add it as a development-time dependency:
24+
25+
composer require --dev codeigniter/coding-standard
26+
27+
## Setup
28+
29+
To start, let us create a `.php-cs-fixer.dist.php` file at the root of your project.
30+
31+
```php
32+
<?php
33+
34+
use CodeIgniter\CodingStandard\CodeIgniter4;
35+
use Nexus\CsConfig\Factory;
36+
37+
return Factory::create(new CodeIgniter4())->forProjects();
38+
39+
```
40+
41+
This minimal setup will return a default instance of `PhpCsFixer\Config` containing all rules applicable
42+
for the CodeIgniter organization.
43+
44+
Then, in your terminal, run the following command:
45+
46+
```console
47+
$ vendor/bin/php-cs-fixer fix --verbose
48+
```
49+
50+
## Adding License Headers
51+
52+
The default setup will not configure a license header in files. License headers can be especially useful
53+
for library authors to assert copyright. To add license headers in your PHP files, you can simply provide
54+
your name and name of library. Optionally, you can also provide your email and starting license year.
55+
56+
```diff
57+
<?php
58+
59+
use CodeIgniter\CodingStandard\CodeIgniter4;
60+
use Nexus\CsConfig\Factory;
61+
62+
-return Factory::create(new CodeIgniter4())->forProjects();
63+
+return Factory::create(new CodeIgniter4())->forLibrary(
64+
+ 'CodeIgniter 4 framework',
65+
+ 'CodeIgniter Foundation',
66+
67+
+ 2021,
68+
+);
69+
70+
```
71+
72+
## Providing Overriding Rules and Options
73+
74+
The list of enabled rules can be found in the [`CodeIgniter\CodingStandard\CodeIgniter4`][3] class. If you
75+
feel the rule is not applicable to you or you want to modify it, you can do so by providing an array of
76+
overriding rules to the second parameter of `Factory::create()`.
77+
78+
Similarly, you can further modify the `PhpCsFixer\Config` instance returned by using the available options.
79+
All available options are fully supported by [Nexus CS Config][2] and abstracted by simply providing an
80+
array of key-value pairs in the third parameter of `Factory::create()`.
81+
82+
```diff
83+
<?php
84+
85+
use CodeIgniter\CodingStandard\CodeIgniter4;
86+
use Nexus\CsConfig\Factory;
87+
88+
-return Factory::create(new CodeIgniter4())->forProjects();
89+
+return Factory::create(new CodeIgniter4(), [], [
90+
+ 'usingCache' => false,
91+
+])->forProjects();
92+
93+
```
94+
95+
You can check out this library's own [`.php-cs-fixer.dist.php`][4] for inspiration on how it is done.
96+
For more detailed documentation on all available options, you can check [here][2].
97+
98+
## Contributing
99+
100+
All forms of contributions are welcome!
101+
102+
Since the rules here will be propagated and used within the CodeIgniter organization, all proposed rules
103+
and modifications to existing rules should have a proof-of-concept (POC) PR sent first to
104+
the [CodeIgniter4][5] repository with possible changes to the code styles applied there. Once accepted
105+
there, you can send in a PR here to apply those rules.
106+
107+
## License
108+
109+
This work is open-sourced under the MIT license.
110+
111+
[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
112+
[2]: https://github.com/NexusPHP/cs-config
113+
[3]: src/CodeIgniter4.php
114+
[4]: .php-cs-fixer.dist.php
115+
[5]: https://github.com/codeigniter4/CodeIgniter4

0 commit comments

Comments
 (0)