Skip to content

Commit

Permalink
Enhancement: Use friendsofphp/php-cs-fixer instead of StyleCI (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored Dec 20, 2020
1 parent 23019f8 commit 8990a0f
Show file tree
Hide file tree
Showing 10 changed files with 1,889 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.styleci.yml export-ignore
/.php_cs.dist export-ignore
/Makefile export-ignore
/phpstan.neon.dist export-ignore
/phpstan-baseline.neon export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/psalm-baseline.xml export-ignore
/psalm.xml export-ignore
Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If you've written a new formatter, added a new locale, or fixed a bug, your cont

Before proposing a pull request, check the following:

* Your code should follow the [PSR-12 coding style guide](https://www.php-fig.org/psr/psr-12/). [StyleCI](https://styleci.io/) will handle compliance automatically on merge. Do not enable StyleCI on your fork.
* Your code should follow our coding standard. Run `make cs` to fix coding standard issues.
* Unit tests should pass after your patch. Run the tests in your local environment (with `make test`) or check the continuous integration status for your pull request.
* As much as possible, add unit tests for your code
* Never use `rand()` in your provider. Faker uses the Mersenne Twister Randomizer, so use `mt_rand()` or any of the base generators (`randomNumber`, `randomElement`, etc.) instead.
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
on:
pull_request: ~
push:
branches:
- "main"
- "[0-9].*"

name: Coding Standards

jobs:
php-cs-fixer:
name: php-cs-fixer

runs-on: ubuntu-latest

strategy:
matrix:
php-version:
- 7.1

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: intl
php-version: ${{ matrix.php-version }}

- name: Determine composer cache directory
id: composer-cache
run: echo "::set-output name=directory::$(composer config cache-dir)"

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Download dependencies
run: |
composer update --no-interaction --no-progress --optimize-autoloader
composer bin php-cs-fixer install --no-interaction --no-progress --optimize-autoloader
- name: Cache cache file for php-cs-fixer
uses: actions/cache@v2
with:
path: .php_cs.cache
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Run php-cs-fixer
run: |
vendor/bin/php-cs-fixer fix --diff --diff-format=udiff --dry-run --verbose
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/.build/
/vendor/
/vendor-bin/php-cs-fixer/vendor/
/vendor-bin/phpstan/vendor/
/vendor-bin/psalm/vendor/
/.php_cs.cache
/composer.lock
127 changes: 127 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->exclude([
'.build/',
'.github/',
'vendor-bin/',
])
->ignoreDotFiles(false)
->in(__DIR__)
->name('.php_cs.dist');

$config = new PhpCsFixer\Config('faker');

return $config
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short',
],
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => [
'break',
'continue',
'default',
'die',
'do',
'exit',
'for',
'foreach',
'include',
'include_once',
'require',
'require_once',
'return',
'switch',
'throw',
'try',
'while',
'yield',
],
],
'cast_spaces' => true,
'combine_nested_dirname' => true,
'compact_nullable_typehint' => true,
'concat_space' => [
'spacing' => 'one',
],
'declare_equal_normalize' => true,
'function_typehint_space' => true,
'implode_call' => true,
'lambda_not_used_import' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'modernize_types_casting' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_cast' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
'normalize_index_brace' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_dedicate_assert_internal_type' => true,
'php_unit_expectation' => true,
'php_unit_fqcn_annotation' => true,
'php_unit_mock' => true,
'php_unit_mock_short_will_return' => true,
'php_unit_namespaced' => true,
'php_unit_no_expectation_annotation' => true,
'php_unit_ordered_covers' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_test_case_static_method_calls' => [
'call_type' => 'self',
],
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_alias_tag' => [
'replacements' => [
'type' => 'var',
],
],
'phpdoc_no_package' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'pow_to_exponentiation' => true,
'psr_autoloading' => true,
'random_api_migration' => true,
'return_type_declaration' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'single_trait_insert_per_statement' => true,
'standardize_not_equals' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'visibility_required' => [
'elements' => [
'const',
'method',
'property',
],
],
'whitespace_after_comma_in_array' => true,
]);
69 changes: 0 additions & 69 deletions .styleci.yml

This file was deleted.

8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
.PHONY: build coverage help test
.PHONY: build cs coverage help test

help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

build: test static ## Runs test targets
build: cs test static ## Runs test targets

cs: vendor/autoload.php ## Fixes coding standard issues with php-cs-fixer
mkdir -p .build/
vendor/bin/php-cs-fixer fix --diff --diff-format=udiff --verbose

coverage: vendor/autoload.php ## Collects coverage with phpunit
vendor/bin/phpunit --coverage-text --coverage-clover=.build/logs/clover.xml
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Packagist Downloads](https://img.shields.io/packagist/dm/FakerPHP/Faker)](https://packagist.org/packages/fakerphp/faker)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/FakerPHP/Faker/Continuous%20Integration/main)](https://github.com/FakerPHP/Faker/actions)
[![StyleCI](https://github.styleci.io/repos/307658860/shield?branch=main&style=flat)](https://github.styleci.io/repos/307658860?branch=main)

Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.

Expand Down
12 changes: 12 additions & 0 deletions vendor-bin/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"require": {
"php": "^7.1 || ^8.0",
"friendsofphp/php-cs-fixer": "^2.17.2"
},
"config": {
"platform": {
"php": "7.1.33"
},
"preferred-install": "dist"
}
}
Loading

0 comments on commit 8990a0f

Please sign in to comment.