Skip to content

Commit df8ae6c

Browse files
author
Feyyaz Esatoglu
authored
Merge pull request #3 from mollie/APM-541-usage-information
Usage and Installation information added to Readme.md
2 parents 390e722 + a6335f4 commit df8ae6c

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Mollie\PhpCodingStandards\PhpCsFixer\Rules;
34
use PhpCsFixer\Config;
45
use PhpCsFixer\Finder;
56

README.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,92 @@
11
# Mollie PHP Coding Standards
2-
32
Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpose of standardization.
3+
4+
## Usage
5+
This package makes use of PHP-CS-Fixer.
6+
7+
### Already familiar with PHP-CS-Fixer
8+
9+
This package provides default rules to be used with PHP-CS-Fixer.
10+
11+
You can find them in `Mollie\PhpCodingStandards\PhpCsFixer\Rules` which has methods specific to php version,
12+
which you can directly use in the `->setRules()` part of your config. For example, assuming PHP version 7.3:
13+
14+
```php
15+
use Mollie\PhpCodingStandards\PhpCsFixer\Rules;
16+
17+
$config->setRules(Rules::getForPhp73());
18+
```
19+
20+
### New to PHP-CS-Fixer
21+
22+
Place a file named `.php_cs.dist` that has following content in your project's root directory.
23+
24+
```php
25+
use Mollie\PhpCodingStandards\PhpCsFixer\Rules;
26+
use PhpCsFixer\Config;
27+
use PhpCsFixer\Finder;
28+
29+
$finder = Finder::create()
30+
->name('.php_cs.dist') // Fix this file as well
31+
->in(__DIR__);
32+
33+
return Config::create()
34+
->setFinder($finder)
35+
->setRiskyAllowed(true)
36+
// use specific rules for your php version e.g.: getForPhp71, getForPhp72, getForPhp73
37+
->setRules(Rules::getForPhp71());
38+
```
39+
40+
### Manual Triggering
41+
Run following command in your project directory, that will run fixer for every `.php` file.
42+
```bash
43+
vendor/bin/php-cs-fixer fix
44+
```
45+
46+
### Use via PhpStorm file watcher
47+
Please follow [official PhpStorm documentation](https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html#f21a70ca)
48+
49+
### Use via pre-commit git hook
50+
Place a file with the content of the following bash script into `.git/hooks` directory called pre-commit and make it executable
51+
you can find more details about git hooks on [official git manual](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks).
52+
53+
```bash
54+
#!/usr/bin/env bash
55+
56+
EXCLUDE_DIRECTORIES_REGEX='^(directory_one/(sub_directory_one|sub_directory_two)|directory_two)/.*'
57+
git diff --diff-filter=ACMRTUXB --name-only --staged | grep -E '\.php(_cs\.dist)?$' | grep -vE $EXCLUDE_DIRECTORIES_REGEX | while read FILE; do
58+
STATUS="$(git status --porcelain ${FILE} | cut -c 1-2)"
59+
vendor/bin/php-cs-fixer fix --using-cache=no --quiet --dry-run ${FILE}
60+
61+
# Not 0 means php-cs-fixer either errored or wanted to make changes
62+
if [ $? != 0 ]
63+
then
64+
# MM = staged & non-staged modification in same file
65+
if [ ${STATUS} = "MM" ]
66+
then
67+
echo -e "\033[31m┌────────────────────────────────────────────────────────────────────────────────┐"
68+
echo -e "│ Failure:\033[39m Codestyle violation(s) in file with both staged and unstaged changes. \033[31m│"
69+
echo -e "├────────────────────────────────────────────────────────────────────────────────┘"
70+
echo -e "└\033[33m File:\033[39m $FILE"
71+
exit 1
72+
fi
73+
74+
vendor/bin/php-cs-fixer fix --using-cache=no --quiet ${FILE}
75+
git add ${FILE}
76+
fi
77+
done
78+
```
79+
80+
## Installation
81+
```bash
82+
composer require --dev mollie/php-coding-standards
83+
```
84+
85+
## Working at Mollie
86+
Mollie is always looking for new talent to join our teams. We’re looking for inquisitive minds with good ideas and
87+
strong opinions, and, most importantly, who know how to ship great products. Want to join the future of payments?
88+
[Check out our vacancies](https://jobs.mollie.com).
89+
90+
## License
91+
[BSD (Berkeley Software Distribution) License](https://opensource.org/licenses/bsd-license.php).
92+
Copyright (c) 2013-2019, Mollie B.V.

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
},
1717
"minimum-stability": "stable",
1818
"require": {
19-
"php": "^7.1.3"
20-
},
21-
"require-dev": {
19+
"php": "^7.1.3",
2220
"friendsofphp/php-cs-fixer": "^2.15"
2321
},
2422
"bin": [

src/PhpCsFixer/Rules.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function getForPhp71(array $overriddenRules = []): array
1414
return array_merge(self::getBaseRules(), $overriddenRules);
1515
}
1616

17-
public static function getForPhp72(array $overriddenRules = []) : array
17+
public static function getForPhp72(array $overriddenRules = []): array
1818
{
1919
$specific72Rules = [
2020
// At the moment there are no specific 7.2 rules or configurations
@@ -23,7 +23,7 @@ public static function getForPhp72(array $overriddenRules = []) : array
2323
return array_merge(self::getForPhp71($specific72Rules), $overriddenRules);
2424
}
2525

26-
public static function getForPhp73(array $overriddenRules = []) : array
26+
public static function getForPhp73(array $overriddenRules = []): array
2727
{
2828
$specific73Rules = [
2929
'heredoc_indentation' => true,

0 commit comments

Comments
 (0)