Skip to content

Commit 09fa31b

Browse files
authored
Merge pull request mongodb#2248 from divine/php-cs-fıxer
Add php-cs-fıxer
2 parents 5d1416d + 427cef7 commit 09fa31b

File tree

3 files changed

+280
-85
lines changed

3 files changed

+280
-85
lines changed

.github/workflows/build-ci.yml

+98-79
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,104 @@
11
name: CI
22

33
on:
4-
push:
5-
branches:
6-
tags:
7-
pull_request:
4+
push:
5+
branches:
6+
tags:
7+
pull_request:
88

99
jobs:
10-
build:
11-
runs-on: ${{ matrix.os }}
12-
name: PHP v${{ matrix.php }} with Mongo v${{ matrix.mongodb }}
13-
continue-on-error: ${{ matrix.experimental }}
14-
strategy:
15-
matrix:
16-
include:
17-
- { os: ubuntu-latest, php: 7.2, mongodb: 3.6, experimental: true}
18-
- { os: ubuntu-latest, php: 7.2, mongodb: '4.0', experimental: true}
19-
- { os: ubuntu-latest, php: 7.2, mongodb: 4.2, experimental: true}
20-
- { os: ubuntu-latest, php: 7.2, mongodb: 4.4, experimental: true}
21-
- { os: ubuntu-latest, php: 7.3, mongodb: 3.6, experimental: false}
22-
- { os: ubuntu-latest, php: 7.3, mongodb: '4.0', experimental: false}
23-
- { os: ubuntu-latest, php: 7.3, mongodb: 4.2, experimental: false}
24-
- { os: ubuntu-latest, php: 7.3, mongodb: 4.4, experimental: false}
25-
- { os: ubuntu-latest, php: 7.4, mongodb: 3.6, experimental: false}
26-
- { os: ubuntu-latest, php: 7.4, mongodb: '4.0', experimental: false}
27-
- { os: ubuntu-latest, php: 7.4, mongodb: 4.2, experimental: false}
28-
- { os: ubuntu-latest, php: 7.4, mongodb: 4.4, experimental: false}
29-
- { os: ubuntu-latest, php: 8.0, mongodb: 4.4, experimental: false}
30-
services:
31-
mongo:
32-
image: mongo:${{ matrix.mongodb }}
33-
ports:
34-
- 27017:27017
35-
mysql:
36-
image: mysql:5.7
37-
ports:
38-
- 3307:3306
39-
env:
40-
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
41-
MYSQL_DATABASE: 'unittest'
42-
MYSQL_ROOT_PASSWORD:
10+
php-cs-fixer:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php:
15+
- '7.4'
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php }}
23+
extensions: curl,mbstring
24+
tools: php-cs-fixer
25+
coverage: none
26+
- name: Run PHP-CS-Fixer Fix
27+
run: php-cs-fixer fix --dry-run --diff --ansi
4328

44-
steps:
45-
- uses: actions/checkout@v2
46-
- name: "Installing php"
47-
uses: shivammathur/setup-php@v2
48-
with:
49-
php-version: ${{ matrix.php }}
50-
extensions: curl,mbstring,xdebug
51-
coverage: xdebug
52-
tools: composer
53-
- name: Show PHP version
54-
run: php -v && composer -V
55-
- name: Show Docker version
56-
run: if [[ "$DEBUG" == "true" ]]; then docker version && env; fi
57-
env:
58-
DEBUG: ${{secrets.DEBUG}}
59-
- name: Download Composer cache dependencies from cache
60-
if: (!startsWith(matrix.php, '7.2'))
61-
id: composer-cache
62-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
63-
- name: Cache Composer dependencies
64-
if: (!startsWith(matrix.php, '7.2'))
65-
uses: actions/cache@v1
66-
with:
67-
path: ${{ steps.composer-cache.outputs.dir }}
68-
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
69-
restore-keys: ${{ matrix.os }}-composer-
70-
- name: Install dependencies
71-
if: (!startsWith(matrix.php, '7.2'))
72-
run: |
73-
composer install --no-interaction
74-
- name: Run tests
75-
if: (!startsWith(matrix.php, '7.2'))
76-
run: |
77-
./vendor/bin/phpunit --coverage-clover coverage.xml
78-
env:
79-
MONGO_HOST: 0.0.0.0
80-
MYSQL_HOST: 0.0.0.0
81-
MYSQL_PORT: 3307
82-
- uses: codecov/codecov-action@v1
83-
with:
84-
token: ${{ secrets.CODECOV_TOKEN }}
85-
fail_ci_if_error: false
29+
build:
30+
runs-on: ${{ matrix.os }}
31+
name: PHP v${{ matrix.php }} with Mongo v${{ matrix.mongodb }}
32+
continue-on-error: ${{ matrix.experimental }}
33+
strategy:
34+
matrix:
35+
include:
36+
- { os: ubuntu-latest, php: 7.2, mongodb: 3.6, experimental: true }
37+
- { os: ubuntu-latest, php: 7.2, mongodb: '4.0', experimental: true }
38+
- { os: ubuntu-latest, php: 7.2, mongodb: 4.2, experimental: true }
39+
- { os: ubuntu-latest, php: 7.2, mongodb: 4.4, experimental: true }
40+
- { os: ubuntu-latest, php: 7.3, mongodb: 3.6, experimental: false }
41+
- { os: ubuntu-latest, php: 7.3, mongodb: '4.0', experimental: false }
42+
- { os: ubuntu-latest, php: 7.3, mongodb: 4.2, experimental: false }
43+
- { os: ubuntu-latest, php: 7.3, mongodb: 4.4, experimental: false }
44+
- { os: ubuntu-latest, php: 7.4, mongodb: 3.6, experimental: false }
45+
- { os: ubuntu-latest, php: 7.4, mongodb: '4.0', experimental: false }
46+
- { os: ubuntu-latest, php: 7.4, mongodb: 4.2, experimental: false }
47+
- { os: ubuntu-latest, php: 7.4, mongodb: 4.4, experimental: false }
48+
- { os: ubuntu-latest, php: 8.0, mongodb: 4.4, experimental: false }
49+
services:
50+
mongo:
51+
image: mongo:${{ matrix.mongodb }}
52+
ports:
53+
- 27017:27017
54+
mysql:
55+
image: mysql:5.7
56+
ports:
57+
- 3307:3306
58+
env:
59+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
60+
MYSQL_DATABASE: 'unittest'
61+
MYSQL_ROOT_PASSWORD:
62+
63+
steps:
64+
- uses: actions/checkout@v2
65+
- name: "Installing php"
66+
uses: shivammathur/setup-php@v2
67+
with:
68+
php-version: ${{ matrix.php }}
69+
extensions: curl,mbstring,xdebug
70+
coverage: xdebug
71+
tools: composer
72+
- name: Show PHP version
73+
run: php -v && composer -V
74+
- name: Show Docker version
75+
run: if [[ "$DEBUG" == "true" ]]; then docker version && env; fi
76+
env:
77+
DEBUG: ${{secrets.DEBUG}}
78+
- name: Download Composer cache dependencies from cache
79+
if: (!startsWith(matrix.php, '7.2'))
80+
id: composer-cache
81+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
82+
- name: Cache Composer dependencies
83+
if: (!startsWith(matrix.php, '7.2'))
84+
uses: actions/cache@v1
85+
with:
86+
path: ${{ steps.composer-cache.outputs.dir }}
87+
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
88+
restore-keys: ${{ matrix.os }}-composer-
89+
- name: Install dependencies
90+
if: (!startsWith(matrix.php, '7.2'))
91+
run: |
92+
composer install --no-interaction
93+
- name: Run tests
94+
if: (!startsWith(matrix.php, '7.2'))
95+
run: |
96+
./vendor/bin/phpunit --coverage-clover coverage.xml
97+
env:
98+
MONGO_HOST: 0.0.0.0
99+
MYSQL_HOST: 0.0.0.0
100+
MYSQL_PORT: 3307
101+
- uses: codecov/codecov-action@v1
102+
with:
103+
token: ${{ secrets.CODECOV_TOKEN }}
104+
fail_ci_if_error: false

.gitignore

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
.DS_Store
2-
phpunit.phar
3-
/vendor
4-
composer.phar
5-
composer.lock
1+
*.project
62
*.sublime-project
73
*.sublime-workspace
8-
*.project
4+
.DS_Store
95
.idea/
106
.phpunit.result.cache
7+
/.php_cs
8+
/.php_cs.cache
9+
/vendor
10+
composer.lock
11+
composer.phar
12+
phpunit.phar
1113
phpunit.xml

.php_cs.dist

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
3+
# Source: https://github.com/matt-allan/laravel-code-style/blob/main/src/Config.php
4+
5+
$rules = [
6+
'@PSR2' => true,
7+
'align_multiline_comment' => [
8+
'comment_type' => 'phpdocs_like',
9+
],
10+
'ordered_imports' => [
11+
'sort_algorithm' => 'alpha',
12+
],
13+
'array_indentation' => true,
14+
'binary_operator_spaces' => [
15+
'operators' => [
16+
'=>' => null,
17+
'=' => 'single_space',
18+
],
19+
],
20+
'blank_line_after_namespace' => true,
21+
'blank_line_after_opening_tag' => true,
22+
'blank_line_before_statement' => [
23+
'statements' => [
24+
'return',
25+
],
26+
],
27+
'cast_spaces' => true,
28+
'class_definition' => true,
29+
'clean_namespace' => true,
30+
'compact_nullable_typehint' => true,
31+
'concat_space' => [
32+
'spacing' => 'none',
33+
],
34+
'declare_equal_normalize' => true,
35+
'no_alias_language_construct_call' => true,
36+
'elseif' => true,
37+
'encoding' => true,
38+
'full_opening_tag' => true,
39+
'function_declaration' => true,
40+
'function_typehint_space' => true,
41+
'single_line_comment_style' => [
42+
'comment_types' => [
43+
'hash',
44+
],
45+
],
46+
'heredoc_to_nowdoc' => true,
47+
'include' => true,
48+
'indentation_type' => true,
49+
'lowercase_cast' => true,
50+
'lowercase_constants' => true,
51+
'lowercase_keywords' => true,
52+
'lowercase_static_reference' => true,
53+
'magic_constant_casing' => true,
54+
'magic_method_casing' => true,
55+
'method_argument_space' => true,
56+
'class_attributes_separation' => [
57+
'elements' => [
58+
'method',
59+
],
60+
],
61+
'visibility_required' => [
62+
'elements' => [
63+
'method',
64+
'property',
65+
],
66+
],
67+
'native_function_casing' => true,
68+
'native_function_type_declaration_casing' => true,
69+
'no_alternative_syntax' => true,
70+
'no_binary_string' => true,
71+
'no_blank_lines_after_class_opening' => true,
72+
'no_blank_lines_after_phpdoc' => true,
73+
'no_extra_blank_lines' => [
74+
'tokens' => [
75+
'throw',
76+
'use',
77+
'use_trait',
78+
'extra',
79+
],
80+
],
81+
'no_closing_tag' => true,
82+
'no_empty_phpdoc' => true,
83+
'no_empty_statement' => true,
84+
'no_leading_import_slash' => true,
85+
'no_leading_namespace_whitespace' => true,
86+
'no_multiline_whitespace_around_double_arrow' => true,
87+
'multiline_whitespace_before_semicolons' => true,
88+
'no_short_bool_cast' => true,
89+
'no_singleline_whitespace_before_semicolons' => true,
90+
'no_spaces_after_function_name' => true,
91+
'no_spaces_around_offset' => [
92+
'positions' => [
93+
'inside',
94+
],
95+
],
96+
'no_spaces_inside_parenthesis' => true,
97+
'no_trailing_comma_in_list_call' => true,
98+
'no_trailing_comma_in_singleline_array' => true,
99+
'no_trailing_whitespace' => true,
100+
'no_trailing_whitespace_in_comment' => true,
101+
'no_unneeded_control_parentheses' => true,
102+
'no_unneeded_curly_braces' => true,
103+
'no_unset_cast' => true,
104+
'no_unused_imports' => true,
105+
'lambda_not_used_import' => true,
106+
'no_useless_return' => true,
107+
'no_whitespace_before_comma_in_array' => true,
108+
'no_whitespace_in_blank_line' => true,
109+
'normalize_index_brace' => true,
110+
'not_operator_with_successor_space' => true,
111+
'object_operator_without_whitespace' => true,
112+
'phpdoc_indent' => true,
113+
'phpdoc_inline_tag_normalizer' => true,
114+
'phpdoc_no_access' => true,
115+
'phpdoc_no_package' => true,
116+
'phpdoc_no_useless_inheritdoc' => true,
117+
'phpdoc_return_self_reference' => true,
118+
'phpdoc_scalar' => true,
119+
'phpdoc_single_line_var_spacing' => true,
120+
'phpdoc_summary' => true,
121+
'phpdoc_trim' => true,
122+
'phpdoc_no_alias_tag' => [
123+
'type' => 'var',
124+
],
125+
'phpdoc_types' => true,
126+
'phpdoc_var_without_name' => true,
127+
'increment_style' => [
128+
'style' => 'post',
129+
],
130+
'no_mixed_echo_print' => [
131+
'use' => 'echo',
132+
],
133+
'braces' => true,
134+
'return_type_declaration' => [
135+
'space_before' => 'none',
136+
],
137+
'array_syntax' => [
138+
'syntax' => 'short',
139+
],
140+
'list_syntax' => [
141+
'syntax' => 'short',
142+
],
143+
'short_scalar_cast' => true,
144+
'single_blank_line_at_eof' => true,
145+
'single_blank_line_before_namespace' => true,
146+
'single_class_element_per_statement' => true,
147+
'single_import_per_statement' => true,
148+
'single_line_after_imports' => true,
149+
'single_quote' => true,
150+
'space_after_semicolon' => true,
151+
'standardize_not_equals' => true,
152+
'switch_case_semicolon_to_colon' => true,
153+
'switch_case_space' => true,
154+
'switch_continue_to_break' => true,
155+
'ternary_operator_spaces' => true,
156+
'trailing_comma_in_multiline_array' => true,
157+
'trim_array_spaces' => true,
158+
'unary_operator_spaces' => true,
159+
'line_ending' => true,
160+
'whitespace_after_comma_in_array' => true,
161+
'no_alias_functions' => true,
162+
'no_unreachable_default_argument_value' => true,
163+
'psr4' => true,
164+
'self_accessor' => true,
165+
];
166+
167+
$finder = PhpCsFixer\Finder::create()
168+
->in(__DIR__);
169+
170+
$config = new PhpCsFixer\Config();
171+
return $config
172+
->setRiskyAllowed(true)
173+
->setRules($rules)
174+
->setFinder($finder);

0 commit comments

Comments
 (0)